2015-10-08 11 views
9

से नहीं भेज रहा है मैंने अपने पार्स ऐप के लिए क्रियाशील नोटिफिकेशन में जोड़ने का प्रयास किया है, ऐप में 4 यू। ऐप में, कोई बटन क्लिक करके आपके लिए "प्रार्थना" कर सकता है। ऐसा करने से क्लाउड कोड चलाता है जिसमें एपीएनएस पेलोड के लिए एक श्रेणी शामिल होती है। मेरे ऐपडिलेगेट में मेरे पास है:पार्स एक्शन योग्य नोटिफिकेशन आईफोन

if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) 
     {UIUserNotificationType types = UIUserNotificationTypeBadge | 
      UIUserNotificationTypeSound | UIUserNotificationTypeAlert; 

      UIMutableUserNotificationAction *acceptAction = 
      [[UIMutableUserNotificationAction alloc] init]; 

      acceptAction.identifier = @"THANKS_IDENTIFIER"; 

      acceptAction.title = @"Say Thanks"; 

      // Given seconds, not minutes, to run in the background 
      acceptAction.activationMode = UIUserNotificationActivationModeBackground; 
      acceptAction.destructive = NO; 
      acceptAction.authenticationRequired = NO; 

      UIMutableUserNotificationCategory *inviteCategory = 
      [[UIMutableUserNotificationCategory alloc] init]; 

      inviteCategory.identifier = @"TAGGED_CATEGORY"; 

      [inviteCategory setActions:@[acceptAction] 
          forContext:UIUserNotificationActionContextDefault]; 
      NSSet *categories = [NSSet setWithObjects:inviteCategory, nil]; 

           UIUserNotificationSettings *settings = 
           [UIUserNotificationSettings settingsForTypes:types categories:categories]; 

           [[UIApplication sharedApplication] 
            registerUserNotificationSettings:settings]; 

      [application registerForRemoteNotifications]; 
     } 

- (void)application:(UIApplication *)application 
handleActionWithIdentifier:(NSString *)identifier 
forRemoteNotification:(NSDictionary *)notification 
    completionHandler:(void (^)())completionHandler { 
    if ([identifier isEqualToString:@"THANKS_IDENTIFIER"]) { 
     [self handleAcceptActionWithNotification:notification]; 
     NSLog(@"Handled"); 



    } 
    // Must be called when finished 
    completionHandler(); 
} 
-(void) handleAcceptActionWithNotification:(NSDictionary *)notification { 
    NSLog(@"SendingThanks"); 
    PFUser *me = [PFUser currentUser]; 
    NSString *theirname = me[@"additional"]; 
    NSString *myAlertString=notification[@"loc-args"]; 
    NSLog(@"%@", notification); 
    [PFCloud callFunctionInBackground:@"thankYou" 
         withParameters:@{@"recipientId": myAlertString, @"theirName": theirname} 
           block:^(NSString *success, NSError *error) { 
            if (!error) { 
             // Push sent successfully 
            } 
           }]; 

} 

तो, मैं परीक्षण करने के लिए चलाता हूं। जब कोई मेरे लिए प्रार्थना करता है, तो मुझे अपने आईफोन पर अधिसूचना मिलती है, नीचे खींचें और "धन्यवाद कहें" बटन है। मैं इसे क्लिक करता हूं, लेकिन कुछ भी नहीं होता है। किकर यहाँ है। आम तौर पर मैं कहूंगा, "ठीक है, मैंने कुछ गड़बड़ कर दी, डीबगिंग शुरू करें"। हालांकि, मेरे पास ऐप्पल वॉच भी है। जब मैं अपने वॉच पर अधिसूचना से जुड़े धन्यवाद बटन पर क्लिक करता हूं, तो यह पुश भेजता है, बनाम कुछ भी नहीं करता जब मैं अपने आईफोन पर एक ही बटन पर क्लिक करता हूं।

कोई विचार क्या है कि यहां क्या हो रहा है?

अद्यतन:

कंसोल में, जब यह विफल रहता है, मैं:

[Error]: The request timed out. (Code: 100, Version: 1.8.2) 
2015-10-08 13:42:49.424 iPrayed[2231:712503] [Error]: Network connection failed. Making attempt 1 after sleeping for 1.463493 seconds. 

आखिरकार मैं एक सफलता कॉल मिलता है, लेकिन उस समय तक यह अभी भी वास्तव में पुश नहीं भेजता है। कोई विचार यह क्यों हो रहा है जब यह आईफोन से टैप किया गया और न देखे?

+0

ईमानदारी से, मेरे पास कोई विचार नहीं है ;-) क्या आपने अनुरोधों पर एक नज़र डाली है? (https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/wiki/Network-Debug-Tool मेरे लिए बहुत उपयोगी रहा है!) शुभकामनाएं! – niggeulimann

उत्तर

3

क्योंकि completionHandler()PFCloud से पहले आप कॉल करते हैं। आपको completionHandler()completionBlock

पर कॉल करने की आवश्यकता है।

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)notification completionHandler:(void (^)())completionHandler { 

    if ([identifier isEqualToString:@"THANKS_IDENTIFIER"]) { 
     PFUser *me = [PFUser currentUser]; 
     NSString *theirname = me[@"additional"]; 
     NSString *myAlertString=notification[@"loc-args"]; 
     [PFCloud callFunctionInBackground:@"thankYou" withParameters:@{@"recipientId": myAlertString, @"theirName": theirname} block:^(NSString *success, NSError *error) { 
      completionHandler(); 
     }]; 
    } else { 
     completionHandler(); 
    } 

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