简体   繁体   English

NSLocalizedString-线程1:具有String.localizedStringWithFormat的EXEC_BAD_ACCESS

[英]NSLocalizedString - Thread 1: EXEC_BAD_ACCESS with String.localizedStringWithFormat

I tried to make a notification with some localized variables. 我试图用一些局部变量发出通知。 In the simulator, everything works without an error - even the notification shows up as it should, but if I test it on an iPhone, the app crashes. 在模拟器中,一切正常,没有错误-通知也按预期显示,但如果我在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
    }

The error is: 错误是:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x4084900000000000) 线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x4084900000000000)

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)

The comment text is the actual localized text value defined in the .strings file. 注释文本是在.strings文件中定义的实际本地化文本值。

Thanks in advance! 提前致谢!

You're using the wrong format specifier for andAmount. 您为andAmount使用了错误的格式说明符。 andAmount is a double and not an object, so use %f instead of %@. andAmount是一个double而不是一个对象,因此请使用%f而不是%@。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM