2

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?

alexeis
  • 2,152
  • 4
  • 23
  • 30
  • I don't think it would work. I think you should keep user's settings info on server and receive already formatted string in the notifications from server. – Shoaib Jun 24 '15 at 09:20
  • That would be some kind of workaround but I don't like it too much... Such formatting should take place on the devices itself: E.g. what if the same user uses different language/region settings on his iphone/iPad? – alexeis Jun 24 '15 at 10:45
  • If the user have different language/region settings on his devices, you still have info about it on the server side as you have a token for each device, not one per user. – pteofil Jun 25 '15 at 11:17
  • @pteofil So you share the opinion that there is no possibility of adjusting anything within the payload locally before the message is shown to the user? – alexeis Jun 25 '15 at 13:49
  • 2
    Yes. Your app is not called before the message is shown to the user. Only if the user tap on the notification it will be taken in the app and so the app is awaken and you are given the payload to do with it as you please. – pteofil Jun 25 '15 at 13:57
  • 2
    Could you send your push notification as a silent push? This wakes your app up in the background and you could process the data in the push notification and then create a local notification with the parsed data? I haven't tried this but I think it should work. – asjj Jun 26 '15 at 15:58
  • Here's some info about this: http://stackoverflow.com/questions/19068762/will-ios-launch-my-app-into-the-background-if-it-was-force-quit-by-the-user – pteofil Jun 30 '15 at 07:05

1 Answers1

-1

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.

Ivan Rigamonti
  • 696
  • 5
  • 7
  • "If an app doesn’t use the loc-key and loc-args properties of the aps dictionary for client-side fetching of localized alert messages, the provider needs to localize the text of alert messages it puts in the notification payload." ...the app does use loc-key and loc-args, so the provider doesn't have to know about the device's language preferences. To format a double value the region settings are actually what is decisive. I think the right way is how asjj explained it: Send a silent remote push notification followed by a local notification. – alexeis Jun 29 '15 at 14:14