Apple Watch 通知负载
Apple Watch Notification Payload
我想给 apple watch 通知添加值(当前屏幕使用硬编码数据):
我要添加的值用于这些字段:"Amount"、"At" 和 "When"。如何添加从 PushNotificationPayload.apns 文件中获取此值并将其显示在通知中?
这是 PushNotificationPayload.apns 文件:
{
"aps": {
"alert": {
"body": "New Transaction\n\n",
"title": "Optional title"
},
"category": "newTransactionCategory"
},
"WatchKit Simulator Actions": [
{
"title": "Details",
"identifier": "transactionDetailsButtonAction"
}
],
"customKey": "Use this file to define a testing payload for your notifications. The aps dictionary specifies the category, alert text and title. The WatchKit Simulator Actions array can provide info for one or more action buttons in addition to the standard Dismiss button. Any other top level keys are custom payload. If you have multiple such JSON files in your project, you'll be able to select them when choosing to debug the notification interface of your Watch App."
}
这些是步骤,
创建一个新的 class,它是 WKUserNotificationInterfaceController
的子class。
从情节提要中,select 用于通知的动态界面场景(如果您尚未创建它,请在静态场景的属性检查器中启用 'Has Dynamic Interface')和身份检查员设置自定义 class 如上创建。
现在修改你的PushNotificationPayload.apns文件内容如下,
{
"aps": {
"alert": {
"body": "New Transaction\n\n",
"title": "Optional title"
},
"category": "newTransactionCategory"
},
"WatchKit Simulator Actions": [
{
"title": "Details",
"identifier": "transactionDetailsButtonAction"
}
],
"Amount": "USD 20",
"At": "Mc Donalds",
"When": "Today",
}
当收到远程通知时,该方法将在您的自定义通知接口class中被调用,您将收到您需要的字典'remoteNotification'中的自定义键用于在此处设置标签文本。
-(void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler {
NSLog(@"remoteNotification Dictionary %@",remoteNotification);
completionHandler(WKUserNotificationInterfaceTypeCustom);
}
最后是调试:
Select 你的目标在上面 select 编辑方案
单击底部的复制方案并提供您的自定义名称,例如 'NOTIFICATION-Mywatchkitapp' 等...
然后,select WatchKit 接口到动态通知,通知负载到您的 PushNotificationPayload.apns 文件和 运行 这个目标。
我想给 apple watch 通知添加值(当前屏幕使用硬编码数据):
我要添加的值用于这些字段:"Amount"、"At" 和 "When"。如何添加从 PushNotificationPayload.apns 文件中获取此值并将其显示在通知中?
这是 PushNotificationPayload.apns 文件:
{
"aps": {
"alert": {
"body": "New Transaction\n\n",
"title": "Optional title"
},
"category": "newTransactionCategory"
},
"WatchKit Simulator Actions": [
{
"title": "Details",
"identifier": "transactionDetailsButtonAction"
}
],
"customKey": "Use this file to define a testing payload for your notifications. The aps dictionary specifies the category, alert text and title. The WatchKit Simulator Actions array can provide info for one or more action buttons in addition to the standard Dismiss button. Any other top level keys are custom payload. If you have multiple such JSON files in your project, you'll be able to select them when choosing to debug the notification interface of your Watch App."
}
这些是步骤,
创建一个新的 class,它是
WKUserNotificationInterfaceController
的子class。从情节提要中,select 用于通知的动态界面场景(如果您尚未创建它,请在静态场景的属性检查器中启用 'Has Dynamic Interface')和身份检查员设置自定义 class 如上创建。
现在修改你的PushNotificationPayload.apns文件内容如下,
{ "aps": { "alert": { "body": "New Transaction\n\n", "title": "Optional title" }, "category": "newTransactionCategory" }, "WatchKit Simulator Actions": [ { "title": "Details", "identifier": "transactionDetailsButtonAction" } ], "Amount": "USD 20", "At": "Mc Donalds", "When": "Today", }
当收到远程通知时,该方法将在您的自定义通知接口class中被调用,您将收到您需要的字典'remoteNotification'中的自定义键用于在此处设置标签文本。
-(void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler { NSLog(@"remoteNotification Dictionary %@",remoteNotification); completionHandler(WKUserNotificationInterfaceTypeCustom); }
最后是调试:
Select 你的目标在上面 select 编辑方案
单击底部的复制方案并提供您的自定义名称,例如 'NOTIFICATION-Mywatchkitapp' 等...
然后,select WatchKit 接口到动态通知,通知负载到您的 PushNotificationPayload.apns 文件和 运行 这个目标。