更改警报的语言推送通知的旗帜

问题描述:

我现在面临的问题来改变警报的语言横幅时推来。其实我工作的这两种语言工作的应用程序。一个是英语,其次是挪威。我从我的Web服务器端的接收推,什么在它具有字符串时推来,你的应用程序之外的警报键显示在旗帜。但作为一个要求我们想,如果我的设置从英语到挪威语更改语言则当推来它的旗帜的警报字符串也将改变挪威。这将有可能在我的结束或我有每当我改变语言将其从服务器上更改。

I am facing problem to change the language of alert in banner when push comes. Actually i am working on an app which works in two language. One is English and second is Norwegian. The push I am receiving from my web server end and what the string it has in alert key is displayed in banner when push comes and you are outside of the app. But as a requirement we want that if I change the language from setting from English to Norwegian then when push comes it's banner's alert string would also change to Norwegian. Will it be possible at my end or i have to change it from server whenever i change language.

任何建议将是有益的。

感谢

有两种方式显示在iOS的推送通知本地化的文本:

There are two ways to display localized text in a push notification in iOS:

在您的服务器本地化的信息

在这种情况下,必须对设备的语言发送到服务器。您需要添加到您的iOS应用的code将类似于以下内容:

In this case, you must send the device language to your server. The code you need to add to your iOS app would be similar to the following:

NSString *preferredLanguage = [[NSLocale preferredLanguages] objectAtIndex:0];
const char *langStr = [preferredLanguage UTF8String];
[self sendCurrentLanguage:langStr]; // Method that communicates with your server

然后,您可以通过使用JSON通知有效载荷中的警报键发送适当的语言通知消息。

Then you can send the notification message in the appropriate language by using the alert key in the notification JSON payload.

发送本地化字符串与通知有效载荷

您可以发送有效载荷中的本地化的字符串。在警报键接受孩子 LOC键,你可以用它来发送一个本地化的字符串键:

You can send the localized string in the payload. The alert key accepts a child loc-key key that you can use to send a localized string:

"alert" : { 
    "loc-key" : "My Localized String",
    ...
}

,然后在对应的语言标识符内的 Localizable.strings 文件,添加以下内容:

"My Localized String" = "The localized string in the language you want.";

如果你需要传递的参数生成最终本地化的字符串,可以把它作为一个 LOC-ARGS JSON通知有效载荷阵,太:

If you need to pass arguments to build the final localized string, you can pass it as a loc-args JSON array in the notification payload, too:

"alert" : { 
        "loc-key" : "My Localized String",
        "loc-args" : [ "First argument", "Second argument" ],
        ...
    }

和,在你的 Localizable.strings

 "My Localized String" = "The localized string with first argument %@, and second argument %@."

或者,如果您需要更改的位置:

Or, if you need to change the positions:

 "My Localized String" = "The localized string with second argument %2$@, and first argument %1$@.";