NSLocalizedString - 线程 1:EXEC_BAD_ACCESS 和 String.localizedStringWithFormat
NSLocalizedString - Thread 1: EXEC_BAD_ACCESS with String.localizedStringWithFormat
我试图用一些局部变量发出通知。在模拟器中,一切正常,没有错误——即使是通知也能正常显示,但如果我在 iPhone 上测试它,应用程序就会崩溃。
func getContent(fromName: String, andDue: String, andAmount: Double) -> UNMutableNotificationContent {
let currency = self.appDelegate.settings.getShortCurrency() // standard währung aus dem System holen
let content = UNMutableNotificationContent()
content.subtitle = NSLocalizedString("REMINDERTITLE", comment: "Reminder: some payments are overdue...")
// Error in this line:
content.body = String.localizedStringWithFormat(NSLocalizedString("REMINDERTEXT", comment: "Hey, %@'s payment from %@ %@ is overdue since %@! Do you want to send him a reminder message?"), fromName, andAmount, currency, andDue)
content.badge = 1
content.sound = UNNotificationSound(named: "droppingCoin.wav")
return content
}
错误是:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x4084900000000000)
在这一行中:
content.body = String.localizedStringWithFormat(NSLocalizedString("REMINDERTEXT", comment: "Hey, %@'s payment from %@ %@ is overdue since %@! Do you want to send him a reminder message?"), fromName, andAmount, currency, andDue)
注释文本是 .strings 文件中定义的实际本地化文本值。
提前致谢!
您对 andAmount 使用了错误的格式说明符。 andAmount 是一个 double 而不是一个对象,所以使用 %f 而不是 %@。
我试图用一些局部变量发出通知。在模拟器中,一切正常,没有错误——即使是通知也能正常显示,但如果我在 iPhone 上测试它,应用程序就会崩溃。
func getContent(fromName: String, andDue: String, andAmount: Double) -> UNMutableNotificationContent {
let currency = self.appDelegate.settings.getShortCurrency() // standard währung aus dem System holen
let content = UNMutableNotificationContent()
content.subtitle = NSLocalizedString("REMINDERTITLE", comment: "Reminder: some payments are overdue...")
// Error in this line:
content.body = String.localizedStringWithFormat(NSLocalizedString("REMINDERTEXT", comment: "Hey, %@'s payment from %@ %@ is overdue since %@! Do you want to send him a reminder message?"), fromName, andAmount, currency, andDue)
content.badge = 1
content.sound = UNNotificationSound(named: "droppingCoin.wav")
return content
}
错误是:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x4084900000000000)
在这一行中:
content.body = String.localizedStringWithFormat(NSLocalizedString("REMINDERTEXT", comment: "Hey, %@'s payment from %@ %@ is overdue since %@! Do you want to send him a reminder message?"), fromName, andAmount, currency, andDue)
注释文本是 .strings 文件中定义的实际本地化文本值。
提前致谢!
您对 andAmount 使用了错误的格式说明符。 andAmount 是一个 double 而不是一个对象,所以使用 %f 而不是 %@。