私のパーズアプリ「iPrayed 4 U」にアクション可能な通知を追加しようとしました。アプリでは、誰かがボタンをクリックしてあなたのために「祈り」をすることができます。そうすることで、APNSペイロードのカテゴリを含むクラウドコードが実行されます。私のAppDelegateで私は持っています:アクション可能な通知を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
}
}];
}
私はテストを実行します。誰かが私のために祈ると、私は自分のiPhoneで通知を受け取り、下にドラッグすると、「感謝の言葉」ボタンがあります。私はそれをクリックしますが、何も起こりません。ここはキッカーです。通常、私は「まあ、何かを混乱させて、デバッグを始める」と言うでしょう。しかし、私はApple Watchも持っています。ウォッチの通知にSay Thanksボタンをクリックすると、iPhoneの同じボタンをクリックしてもプッシュは送信されません。
ここで何が起こっていると思いますか?
UPDATE:コンソールで
それが失敗したときに、私が取得:
[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.
は最終的に私は成功コールを得るが、その時点でそれはまだ実際にプッシュ送信されません。アイフォーンからタップして見ていないときにのみ起こっている理由は?
正直なところ、私にはアイデアがありません;-) あなたはリクエストを見ましたか? (https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/wiki/Network-Debug-Toolは私にとって非常に役に立ちました!) 幸運を! – niggeulimann