2015-10-08 10 views
9

Ho provato ad aggiungere in notifiche eseguibili per la mia app Parse, iPrayed 4 U. Nell'app, qualcuno può "Pregare" per te facendo clic su un pulsante. In questo modo viene eseguito un codice cloud che include una categoria per il payload APNS. Nel mio AppDelegate ho:Notifiche Parse Actionable Non invio da iPhone

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 
            } 
           }]; 

} 

Quindi, corro ai test. Quando qualcuno prega per me, ricevo la notifica sul mio iPhone, trascina verso il basso e c'è il pulsante "Rispondi grazie". Lo clicco, ma non succede nulla. Ecco il kicker. Normalmente direi: "Bene, ho incasinato qualcosa, ho iniziato il debugging". Tuttavia, ho anche un Apple Watch. Quando faccio clic sul pulsante Dì ringraziamenti allegato alla notifica sul mio orologio, invia il push, contro il non fare nulla quando faccio clic sullo stesso pulsante sul mio iPhone.

Qualche idea su cosa sta succedendo qui?

UPDATE:

Nella console, quando non riesce, ottengo:

[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. 

Alla fine ricevo una chiamata successo, ma da quel momento ancora in realtà non inviare il Push. Qualche idea sul perché sta accadendo solo quando viene toccato da iPhone e non guarda?

+0

Onestamente, non ho idea ;-) Avete dato un'occhiata alle richieste? (https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/wiki/Network-Debug-Tool è stato molto utile per me!) Buona fortuna! – niggeulimann

risposta

3

Perché si chiama completionHandler() prima del PFCloud terminato. Hai bisogno di chiamare completionHandler() in completionBlock

Fare questo.

- (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(); 
    } 

} 
Problemi correlati