9

Ich habe versucht, in Actionable Notifications für meine Parse-App iPrayed 4 U. hinzuzufügen. In der App kann jemand für Sie "beten", indem Sie auf eine Schaltfläche klicken. Dabei wird ein Cloud-Code ausgeführt, der eine Kategorie für die APNS-Nutzlast enthält. In meinem AppDelegate habe ich:Analysieren von umsetzbaren Benachrichtigungen, die nicht vom iPhone gesendet werden

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

} 

Also, ich laufe zum Testen. Wenn jemand für mich betet, bekomme ich die Benachrichtigung auf meinem iPhone, ziehe nach unten und dort ist der "Sag Danke" -Knopf. Ich klicke darauf, aber nichts passiert. Hier ist der Kicker. Normalerweise würde ich sagen: "Nun, ich habe etwas vermasselt, beginne zu debuggen". Ich habe aber auch eine Apple Watch. Wenn ich auf die Schaltfläche "Sagen", die der Benachrichtigung auf meiner Uhr beigefügt ist, klicke, wird der Push gesendet, während ich nichts unternehme, wenn ich auf dieselbe Schaltfläche auf meinem iPhone klicke.

Irgendwelche Gedanken, was hier vor sich geht?

UPDATE:

In Konsole, wenn es fehlschlägt, erhalte ich:

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

Schließlich bekomme ich einen Erfolg Ruf, aber zu diesem Zeitpunkt ist es noch nicht wirklich Push senden. Irgendeine Idee, warum es nur geschieht, wenn es vom iPhone angezapft wird und nicht schaut?

+0

Ehrlich, ich habe keine Ahnung ;-) Haben Sie sich die Anfragen angesehen? (https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/wiki/Network-Debug-Tool war sehr hilfreich für mich!) Viel Glück! – niggeulimann

Antwort

3

Da rufen Sie completionHandler() vor PFCloud fertig. Sie benötigen completionHandler() in completionBlock

Tun Sie dies.

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

} 
Verwandte Themen