ios - swift 3 - 推送通知的本地化不起作用

标签 ios swift push-notification apple-push-notifications localizable.strings

我正在尝试使用有效负载本地化推送通知(swift 3、ios 10):

{ 
"aps":{
        "alert":{  
           "title_loc_key":"NOTIFICATION_NEW_FRIEND_REQUEST_TITLE",
           "title-loc-args":[],
           "loc_key":"NOTIFICATION_NEW_FRIEND_REQUEST_BODY",
           "loc-args":[]
        },
       "mutable_content":1,
       "category":"new_friend_request",
       "badge":0,
       "sound":"default"
    }
}

在 Localizable.strings 上我有:

"NOTIFICATION_NEW_FRIEND_REQUEST_TITLE" = "some text";
"NOTIFICATION_NEW_FRIEND_REQUEST_BODY" = "some text"

我的系统语言是英文 问题是通知来了(我的 Iphone 正在振动)但没有显示任何内容。有什么问题以及如何解决?

最佳答案

title_loc_keytitle-loc-keyloc_keyloc-key

doc使用 - 定义关键字分隔符并且您正在混合(使用 - 用于 ...arg_ 用于 ...键)

Storing Localized Content in Your App Bundle

If you use a consistent set of messages for your notifications, you can store localized versions of the message text in your app bundle and use the loc-key and loc-args keys in your payload to specify which message to display. The loc-key and loc-args keys define the message content of the notification. When present, the local system searches the app’s Localizable.strings files for a key string matching the value in loc-key. It then uses the corresponding value from the strings file as the basis for the message text, replacing any placeholder values with the strings specified by the loc-args key. (You can also specify a title string for the notification using the title-loc-key and title-loc-args keys.)

关于ios - swift 3 - 推送通知的本地化不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45053216/

相关文章:

ios - 由一对多关系创建的访问器方法是否与 NSFetchedResultsControllers 一样好?

ios - swift ,使用 alamofire 将图像上传到 php 服务器

ios - 在函数 swift 中输入 **nil**

android - 应用程序在后台时处理 Firebase 推送通知数据

Android 12 Kotlin - 强烈考虑使用 FLAG_IMMUTABLE,仅当某些功能依赖于 PendingIntent 可变时才使用 FLAG_MUTABLE

iphone - 更改单元格中 detailtextlabel 的位置?

ios - shouldChangeCharactersInRange 没有被调用

ios - 适用于 iOS 的 Firebase 云消息传递 : don't receive notifications from POST request (only from composer tool)

swift - 版本控制系统未提供作者信息

ios - 我可以在后台收听 CMPedometer 并根据不同情况发送本地推送通知吗?