[英]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
}
錯誤是:
線程1:EXC_BAD_ACCESS(代碼= 1,地址= 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而不是%@。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.