使用 Amazon SNS 向 iOS 发送推送通知并使用本地化格式化字符串处理它们

Send push notifications to iOS with Amazon SNS and handle them with Localized Formatted Strings

我正在尝试从 Amazon SNS 发送 iOS 推送通知并且我能够做到,但我想使用本地化格式的字符串发送通知并以正确的语言推送消息.

我正在使用 XCode 7.0.1 并使用 iPhone 5S 进行开发,但我认为这不是重点。

这是我要发送的消息:

{  
   "default":"This is the default Message",
   "APNS_SANDBOX":"{ "aps" : {  "alert" : {
        "loc-key" : "GAME_PLAY_REQUEST_FORMAT",
        "loc-args" : [ "Jenna", "Frank"]
    },"data": { "type": "dashboard", "opponentName":"Juan ","gameCategory":"Multimedia","gameType":"combo","ugid":"123456789" }, "badge" : 9,"sound" :"default"}}"
}

可以发送,但在设备中没有改变,消息是"GAME_PLAY_REQUEST_FORMAT",所以我想显示的是我Localizable.strings文件中这个键的值:

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

我知道你可以在苹果的文档中做到这一点 (https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW21)

希望大家帮忙。

谢谢

我会post把答案放在这里让大家看到。

@TàTruhoada 是的,您需要在有效负载中使用 loc-keys。你可以在下面的link中看到它是如何工作的:Creating the Remote Notification Payload

使用 loc-key 传递在应用程序的 Localizable.strings 文件中定义的密钥。 iPhone 查找键并将其替换为为当前本地化找到的字符串。 您可以在来自 Erica Sadun 的 link 中查看更多信息:构建通知负载