Format double in remote push notification message before it is presented

372 views Asked by At

In some of my remote push notification double values are sent in addition to strings. These values I need to format on the receiving device depending on the user's region settings and set the currency properly. I got an idea of/a workaround how to do so while the app is in the foreground:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {

    ...

    var locArgsFormatted: [NSObject] = []

    for arg in locArgs {

        if let double = arg as? Double {
            locArgsFormatted.append(Utils.Formatter.currencyOutput.stringFromNumber(double)!)

        } else {
            locArgsFormatted.append(arg)

        }
    }

    let formattedString = NSString(format: localizedString, arguments: Utils.Methods.getVaListFromArguments(locArgsFormatted)) as! String
}

But I have no idea how to so (and similar adjustments) while the app is in the background. The messages shown in an alert or a banner are automatically created by getting the localized strings in the Localizable.strings file (no option to format any double values first) but how can I intervene like in the example shown before the notification message is shown to the user?

1

There are 1 answers

1
Ivan Rigamonti On

Based on Apple's Local and Remote Notification Programming Guide the client app on the receiving device should pass the provider the current language preference in order to let the provider know how to localize the message. Thus, the localization would occur by software running on the server connected to the APN.

With such an architecture there is no need in the sending app to keep any localization info of any user. Furthermore the aforementioned programming guide shows how to guarantee that any changes in localization settings in the receiver's device are propagated to the provider.