2016-11-30 21 views
0

私は、iOS 10で奇妙なプッシュ通知の問題に気づいています。私はthis SO threadのコード変更を提案して、サンドボックスAPNSフォームを受け取るようにしました。iOS 10プッシュ通知 - Sandbox APNSの問題

これらの変更を行った後、APNSからデバイストークンが返され、通知を受け取ることができます。しかし、私が&をXcodeから再起動すると、プッシュは機能しません。デバイスからアプリを削除してXcodeから再度入れると、プッシュが開始されます。

誰でもこの動作を見て、可能な修正が本当に役立つだろうと知っています。お知らせ下さい。ここ

は私AppDelegateのステップ実装による工程である:

ステップ1:インポートUserNotifications

#import <UserNotifications/UserNotifications.h> 

ステップ2:通知プロトコルに準拠

@interface MyAppDelegate() <UIApplicationDelegate, UNUserNotificationCenterDelegate> 

ステップ3:application:didFinishLaunchingWithOptions: register for notification

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10")) { 
      UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; 
      center.delegate = self; 
      [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) { 
       if(!error){ 
        [[UIApplication sharedApplication] registerForRemoteNotifications]; 
       } 
      }]; 
     } 

ステップ4:最後にiOSの10で通知を処理するには

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler { 
    [self handlePushNotificationWithUserInfo:response.notification.request.content.userInfo]; 
} 
+0

あなたのデバイストークンが登録されています –

+0

この問題は発生しません。シミュレータをリセットしてみてください。 –

+0

私はプッシュトークンを受け取り、私のサーバーに引き渡し、それはサーバー側に登録されています。彼らはプッシュペイロードも送っています。 – Abhinav

答えて

1

プッシュ通知を処理します。

2つの方法があります。

willPresentNotification

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
    willPresentNotification:(UNNotification *)notification 
    withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler 
{ 
    NSLog(@"This method is called to Handle push from foreground"); 
    // custom code to handle push while app is in the foreground 
    NSLog(@"User info ==> %@", notification.request.content.userInfo); 
} 

そしてdidReceiveNotificationResponse

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
    didReceiveNotificationResponse:(UNNotificationResponse *)response 
    withCompletionHandler:(void (^)())completionHandler 
{ 
    NSLog(@"Handle push from background or closed"); 
    NSLog(@"%@", response.notification.request.content.userInfo); 
} 

それがお役に立てば幸いです..!

関連する問題