簡體   English   中英

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."
}

這些是步驟,

  • 創建一個新類,它是WKUserNotificationInterfaceController的子類。

  • 從故事板中,選擇動態界面場景以進行通知(如果尚未創建,請在靜態場景的屬性檢查器中啟用“具有動態界面”),並在Identity Inspector中設置上面創建的自定義類。

  • 現在修改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); } 
  • 最后是調試:

    1. 選擇頂部的目標,然后選擇編輯方案

    2. 點擊底部的重復方案,並提供“NOTIFICATION-Mywatchkitapp”等自定義名稱...

    3. 然后,選擇WatchKit Interface to Dynamic Notification,Notification Payload到PushNotificationPayload.apns文件並運行此目標。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM