Ios Apple Watch通知有效负载
我想向apple watch通知添加值(当前屏幕使用硬编码数据): 我想为这些字段添加的值是:“金额”、“在”和“何时”。如何从PushNotificationPayload.apns文件中添加和获取此值并在通知中显示 这是PushNotificationPayload.apns文件:Ios Apple Watch通知有效负载,ios,swift,push-notification,watchkit,Ios,Swift,Push Notification,Watchkit,我想向apple watch通知添加值(当前屏幕使用硬编码数据): 我想为这些字段添加的值是:“金额”、“在”和“何时”。如何从PushNotificationPayload.apns文件中添加和获取此值并在通知中显示 这是PushNotificationPayload.apns文件: { "aps": { "alert": { "body": "New Transaction\n\n", "title": "Optional title" },
{
"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."
}
这些是步骤,
- 创建一个新类,它是
的子类WKUserNotificationInterfaceController
- 从情节提要中,选择要通知的动态界面场景(如果尚未创建该场景,请在静态场景的属性检查器中启用“Has Dynamic Interface”),并在Identity检查器中按上述创建方式设置自定义类
- 现在修改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", }
- 当收到远程通知时,将在自定义通知接口类中调用此方法,并且您将收到字典“remoteNotification”中的自定义键,您需要使用该字典在此处设置标签的文本
-(void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler { NSLog(@"remoteNotification Dictionary %@",remoteNotification); completionHandler(WKUserNotificationInterfaceTypeCustom); }
- 最后是调试:
- 在顶部选择目标,然后选择编辑方案
- 单击底部的复制方案,并给出您的自定义名称,如“NOTIFICATION Mywatchkitapp”等
- 然后,选择WatchKit Interface to Dynamic Notification,将通知有效负载发送到PushNotificationPayload.apns文件,并为此目标运行
金额
、在
时和在
时。有什么提示吗?