gpt4 book ai didi

ios - Apple Watch 通知负载

转载 作者:搜寻专家 更新时间:2023-10-30 23:11:17 25 4
gpt4 key购买 nike

我想给 apple watch 通知添加值(当前屏幕使用硬编码数据):

enter image description here

我要添加的值用于以下字段:“金额”、“时间”和“时间”。如何添加从 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."
}

最佳答案

这些是步骤,

  • 创建一个新类,它是 WKUserNotificationInterfaceController 的子类。

  • 从 Storyboard 中,选择您的动态界面场景以进行通知(如果您尚未创建它,请在静态场景的属性检查器中启用“具有动态界面”)并在身份检查器中设置自定义类,如上所示。

  • 现在修改你的 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",
    }
  • 收到远程通知时,将在您的自定义通知接口(interface)类中调用此方法,您将收到字典“remoteNotification”中的自定义键,您需要使用它来设置此处的标签文本.

    -(void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler {
    NSLog(@"remoteNotification Dictionary %@",remoteNotification);

    completionHandler(WKUserNotificationInterfaceTypeCustom);
    }
  • 最后是调试:

    1. 在顶部选择您的目标并选择“编辑方案”

    2. 单击底部的重复方案并提供您的自定义名称,例如“NOTIFICATION-Mywatchkitapp”等...

    3. 然后,选择 WatchKit Interface to Dynamic Notification,Notification Payload 到您的 PushNotificationPayload.apns 文件并为此目标运行。

关于ios - Apple Watch 通知负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29360410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com