2015-03-31 12 views
5

मैं सेब घड़ी अधिसूचना को मान जोड़ने के लिए चाहते हैं (वर्तमान स्क्रीन हार्ड कोडित डेटा का उपयोग करता है):एप्पल घड़ी अधिसूचना पेलोड

enter image description here

मूल्यों मैं जोड़ना चाहते हैं इन क्षेत्रों के लिए कर रहे हैं: "राशि" , "एट" और "कब"। मैं इस मान को 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." 
} 

उत्तर

4

ये कदम हैं,

  • एक नया वर्ग जो WKUserNotificationInterfaceController का एक उपवर्ग है बनाएँ:

    यह PushNotificationPayload.apns फ़ाइल है।

  • स्टोरीबोर्ड से, अधिसूचना के लिए अपनी गतिशील इंटरफेस दृश्य का चयन करें (यदि आपने इसे नहीं बनाया है, तो अपनी स्टेटिक सीन के विशेषता निरीक्षक में 'हैड डायनामिक इंटरफेस' सक्षम करें और उपरोक्त बनाए गए पहचान निरीक्षक सेट कस्टम क्लास में सक्षम करें।

  • अब आप अपने 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", 
    } 
    
  • दूरस्थ सूचना प्राप्त होने पर, इस विधि अपने कस्टम अधिसूचना इंटरफ़ेस वर्ग में बुलाया जाएगा और आप में कस्टम कुंजी प्राप्त होगा शब्दकोश 'रिमोट नॉटिफिकेशन' जिसे आपको अपने लेबल के टेक्स्ट को सेट करने के लिए उपयोग करने की आवश्यकता है। तल पर शीर्ष पर अपने लक्ष्य का चयन करें और चयन योजना संपादित

  • डुप्लिकेट योजना पर क्लिक करें और इस तरह 'अपने कस्टम नाम दे

    1. अधिसूचना:

      -(void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler { 
          NSLog(@"remoteNotification Dictionary %@",remoteNotification); 
      
          completionHandler(WKUserNotificationInterfaceTypeCustom); 
      } 
      
    2. अंतिम डिबगिंग है Mywatchkitapp 'आदि ...

    3. फिर, गतिशील अधिसूचना के लिए वॉचकिट इंटरफेस का चयन करें, अपने पुशनो में अधिसूचना पेलोड tificationPayload.apns फ़ाइल और इस लक्ष्य के लिए चलाएं।

+0

हाय @ DH14-एस एल, मैं अपने समाधान की कोशिश करना चाहते हैं। हालांकि वर्तमान में मुझे कस्टम लांग-लुक अधिसूचना जारी करने में समस्या आ रही है। मैंने यहां त्रुटि पोस्ट की है: http://stackoverflow.com/questions/29341051/how-to-avoid-this-error-took-too-long-to-show-custom-notification-falling-bac/29345228# 2 9 345228 – user1872384

+0

सुनिश्चित करें कि स्टोरीबोर्ड और पेलोड में 'श्रेणी' कुंजी सही है। फिर जांचें कि आपने 'विल एक्टिवेट' पर कोई लंबा चलने वाला कोड नहीं लिखा है या नहीं। – Dhawal

+0

दुर्भाग्यवश, यह अभी भी त्रुटि को हल नहीं करता है। :(यहां तक ​​कि एक नई परियोजना बनाने और कस्टम अधिसूचना सक्षम के साथ एक नया वॉचकिट लक्ष्य भी स्थापित करने से वह त्रुटि भी मिल जाएगी ... यह बहुत निराशाजनक है .... – user1872384

संबंधित मुद्दे