IOS APN 中的多语言(推送通知)

Multi language in IOS APN (push notification)

我正在开发一个预订应用程序。我想在预订状态更新时向用户发送通知。

所以我在服务器端写了一些 json 像这样:

{
  "aps":
  {
    "alert": "update status",
    "category" : "booking approve", //can be "booking cancel" , "booking reject"
  }
}

而在IOS这边

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
  let aps = userInfo["aps"] as! [String: AnyObject]

  // need to customize and create notification message here

}

问题是,如何在收到推送通知的状态标签(例如预订批准)后自定义消息(根据用户语言)?

感谢您的帮助。

您应该查看 Remote Notification Payload guide,其中列出了可用于通知的所有密钥。您要找的是 loc-key :

loc-key : A key to an alert-message string in a Localizable.strings file for the current localization (which is set by the user’s language preference). The key string can be formatted with %@ and %n$@ specifiers to take the variables specified in the loc-args array. See Localized Formatted Strings for more information.

发送此密钥而不是发送任意选择语言的字符串,警报将根据您的应用程序可用的本地化显示翻译文本。

此外,自iOS 8.2 起,title-loc-key 可用于Apple Watch 收到通知时显示的标题。