2014-07-18 18 views
7

पर इंटरएक्टिव पुश नोटिफिकेशन सेट करने में सक्षम नहीं है मैं पहले से ही इंटरैक्टिव लोकल नोटिफिकेशन सेट करने में सक्षम था, लेकिन रिमोट नोटिफिकेशन काम नहीं कर रहे हैं। मैं Parse.com उपयोग कर रहा हूँ JSONआईओएस 8

मेरे AppDelegate.Swift इस तरह दिखता है भेजने के लिए:

// 
// AppDelegate.swift 
// SwifferApp 
// 
// Created by Training on 29/06/14. 
// Copyright (c) 2014 Training. All rights reserved. 
// 

import UIKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { 
     UINavigationBar.appearance().barTintColor = UIColor.orangeColor() 
     UINavigationBar.appearance().tintColor = UIColor.whiteColor() 


     Parse.setApplicationId("eUEC7O4Jad0Kt3orqRouU0OJhkGuE20n4uSfrLYE", clientKey: "WypmaQ8XyqH26AeWIANttqwUjRJR4CIM55ioXvez") 

     let notificationTypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound 
     let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil) 

     UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings) 

     return true 
    } 

    func application(application: UIApplication!, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings!) { 
     UIApplication.sharedApplication().registerForRemoteNotifications() 
    } 

    func application(application: UIApplication!, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData!) { 
     let currentInstallation:PFInstallation = PFInstallation.currentInstallation() 
     currentInstallation.setDeviceTokenFromData(deviceToken) 
     currentInstallation.saveInBackground() 
    } 

    func application(application: UIApplication!, didFailToRegisterForRemoteNotificationsWithError error: NSError!) { 
     println(error.localizedDescription) 
    } 

    func application(application: UIApplication!, didReceiveRemoteNotification userInfo:NSDictionary!) { 

     var notification:NSDictionary = userInfo.objectForKey("aps") as NSDictionary 

     if notification.objectForKey("content-available"){ 
      if notification.objectForKey("content-available").isEqualToNumber(1){ 
       NSNotificationCenter.defaultCenter().postNotificationName("reloadTimeline", object: nil) 
      } 
     }else{ 
      PFPush.handlePush(userInfo) 
     } 
    } 

    func applicationWillResignActive(application: UIApplication) { 
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
    } 

    func applicationDidEnterBackground(application: UIApplication) { 
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
    } 

    func applicationWillEnterForeground(application: UIApplication) { 
     // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 
    } 

    func applicationDidBecomeActive(application: UIApplication) { 
     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    } 

    func applicationWillTerminate(application: UIApplication) { 
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
    } 
} 
पार्स पर

, मैं इस तरह पुश पेलोड सेट कर रहा हूं:

{ 
"alert": "Tune in for the World Series, tonight at 8pm EDT", 
"badge": "Increment", 
"sound": "chime", 
"category": "FIRST_CATEGORY" 
} 

और मुझे धक्का मिलता है, लेकिन मेरे द्वारा सेट किए गए कस्टम बटन के साथ नहीं।

+0

मैं क्या आप के लिए काम नहीं कर रहा पर स्पष्ट नहीं कर रहा हूँ। क्या किया गया है RereiveRemoteNotification बुलाया या नहीं? – Nick

+1

हां।पुश काम कर रहा है और दिखाई दे रहा है, लेकिन इंटरैक्टिव बटन काम नहीं कर रहे हैं। मुझे लगता है कि श्रेणी –

+0

@Nick से संबंधित कुछ है: क्या आपको कोई समाधान मिला है जब अधिसूचना प्राप्त होने पर हम इंटरैक्टिव बटन कैसे दिखा सकते हैं? – RayofHope

उत्तर

1

आप जबकि APNS के लिए पंजीकरण श्रेणियों पारित करने के लिए की जरूरत है। मेरी नमूना पर

देखो:

var replyAction : UIMutableUserNotificationAction = UIMutableUserNotificationAction() 
    replyAction.identifier = "REPLY_ACTION" 
    replyAction.title = "Yes, I need!" 

    replyAction.activationMode = UIUserNotificationActivationMode.Background 
    replyAction.authenticationRequired = false 

    var replyCategory : UIMutableUserNotificationCategory = UIMutableUserNotificationCategory() 
    replyCategory.identifier = "REPLY_CATEGORY" 

    let replyActions:NSArray = [replyAction] 

    replyCategory.setActions(replyActions, forContext: UIUserNotificationActionContext.Default) 
    replyCategory.setActions(replyActions, forContext: UIUserNotificationActionContext.Minimal) 

    let categories = NSSet(object: replyCategory) 



    let settings : UIUserNotificationType = UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge 
    UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: settings, categories: categories)) 
    UIApplication.sharedApplication().registerForRemoteNotifications() 
3

मुझे यकीन नहीं है कि मेरी समस्या आपके लिए समान है (सुनिश्चित करें कि आपकी समस्या पार्स के कारण नहीं है)। अगर किसी और को एक ही समस्या का सामना करना पड़े तो बस मेरा समाधान यहां पोस्ट करें।

मेरी समस्या अधिसूचना श्रेणी में है।

सुनिश्चित करें कि जब सूचना सेटिंग दर्ज की आप श्रेणी निर्धारित किया है सुनिश्चित करें (मैं ऑब्जेक्टिव-सी, कोई ज्यादा अंतर उपयोग कर रहा हूँ):

UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init]; 
      notificationCategory.identifier = @"CallNotificationCategory"; 
      [notificationCategory setActions:@[declineAction, answerAction] forContext:UIUserNotificationActionContextDefault]; 

      NSSet *categories = [[NSSet alloc] initWithObjects:notificationCategory, nil]; 

और, जब आप दूरस्थ सूचना भेजने, सुनिश्चित करें कि आपके " श्रेणी "पेलोड में और मान वैसा ही है जैसा आपने क्लाइंट में परिभाषित किया है।

{ 
    "alert": "Tune in for the World Series, tonight at 8pm EDT", 
    "badge": "Increment", 
    "sound": "chime", 
    "category": "CallNotificationCategory" 
} 
+0

मेरे द्वारा +1 ... धन्यवाद @xialin – RayofHope

0

यह काम मुझे इंटरैक्टिव पुश नोटिफिकेशन प्रदर्शित करने और पार्स के साथ स्विफ्ट में काम पाने के लिए: मेरे मामले में यह कुछ ऐसा है। ध्यान दें कि आपको प्रत्येक इंटरैक्टिव बटन के लिए UIMutableNotificationAction बनाना है जिसे आप बनाना चाहते हैं। बटन नीचे बटन के लिए विकल्पों को कॉन्फ़िगर करने के बारे में अधिक जानकारी में चला जाता है।

अपने अनुप्रयोग प्रतिनिधि फ़ाइल में:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 

    let notificationTypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound 

    var notificationActionAccept :UIMutableUserNotificationAction = UIMutableUserNotificationAction() 
    notificationActionAccept.identifier = "ACCEPT_IDENTIFIER" 
    notificationActionAccept.title = "Accept" 
    notificationActionAccept.destructive = true 
    notificationActionAccept.authenticationRequired = false 
    notificationActionAccept.activationMode = UIUserNotificationActivationMode.Background 

    var notificationCategory:UIMutableUserNotificationCategory = UIMutableUserNotificationCategory() 
    notificationCategory.identifier = "CallNotificationCategory" 
    notificationCategory .setActions([notificationActionAccept], forContext: UIUserNotificationActionContext.Default) 

    let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: NSSet(array:[notificationCategory])) 
    UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings) 

    return true 
} 

और पार्स बादल में जब तुम धक्का भेजने के लिए, आप UIMutableUserNotificationCategory को category से मेल खाएंगे @Xialin की तरह ऊपर उल्लेख किया है।

ऐसा लगता है कि आप UINotificationSettings पंजीकृत करने के बाद श्रेणियों को सेट नहीं कर रहे थे या कम से कम उन्हें सेट नहीं कर रहे थे - आपको उन्हें पहले सेट करने की आवश्यकता है या यह काम नहीं करेगा।

मुझे नीचे दी गई लिंक पर यह जानकारी मिली है। यदि आवश्यक हो तो यह अधिक जानकारी में जाता है। आशा है कि इस मदद करता है:

http://thecodeninja.tumblr.com/post/90742435155/notifications-in-ios-8-part-2-using-swift-what-is

1

यह Firebase रिमोट सूचनाएं का उपयोग करते समय अगर किसी को भी इस समस्या भर आता है के मामले में है।

बस भेजने के लिए बैकएंड डेवलपर से पूछते हैं:

"notification" : { 
    "title" : YOUR_TITLE, 
    "body" : YOUR_BODY, 
    "click_action" : YOUR_CATEGORY_NAME 
}