0

I have push notifications sent to the device with keys that have a value returned from Localizable.strings. The number of arguments is variable, sometimes it just needs one, sometimes it requires a few.

Normally to localise a string I would use this:

String.localizedStringWithFormat(NSLocalizedString(notification.localisedKey, comment: "a comment"), notification.localisedArguments)

However this only works if notification.localisedArguments is a single value. If it's an array, it crashes.

The workaround in iOS 10 is to use the following code:

NSString.localizedUserNotificationString(forKey: notification.localisedKey, arguments: notification.localisedArguments)

How can I make do an equivalent for iOS 9 and lower?

Tometoyou
  • 7,792
  • 12
  • 62
  • 108

1 Answers1

0

Try this (untested):

let localizedString = NSLocalizedString(notification.localisedKey, comment: "a comment")
let result = withVaList(notification.localisedArguments) {
    String.localizedStringWithFormat(localizedString, $0)
}
Alexander
  • 59,041
  • 12
  • 98
  • 151