iOS - APNS how to use loc_key in payload

╄→尐↘猪︶ㄣ 提交于 2019-12-07 08:27:31

loc-key is a string that needs to match a key in your Localizable.strings file inside the app bundle. For example if the loc-key is "my-push.hello-world" and you have the following line in your Localizable.strings file:

"my-push.hello-world" = "Hello, World!";

the push message displayed to the user would read "Hello, World".

log-args are strings that will be replaced in the message, like your have it in [NSString stringWithFormat:@"blabla %@"];

Apples example is this:

Push Notification Payload:

"alert" : { 
    "loc-key" : "GAME_PLAY_REQUEST_FORMAT",
    "loc-args" : [ "Jenna", "Frank"]
}

Localizable.strings content:

"GAME_PLAY_REQUEST_FORMAT" = "%@ and %@ have invited you to play Monopoly";

if loc key is there, loc_key refers to a key in your localizable file...

e.g. if loc_key=XYZ, then there must be an entry "XYZ"="translated XYZ"; in the apps' localizable file.

loc_args is an array of strings that is to be inserted into the translated string as if you had used stringWithFormat:

e.g loc_args=["DOMI", "ME"] inserted into a translated XYZ like %@ is %@ results in "DOMI is ME"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!