2016-11-23 9 views
0

私のネイティブiOSアプリケーションでAppleプッシュ通知を実装しています。 プッシュ通知はFireBase経由で実装されています。 これは、iOS 9 &より前には完璧に動作しています。iOS 10のバックグラウンドモードでFirebaseプッシュ通知警告音が再生されない

私はiOS 10で1つの問題に直面しています。他の状態のiOS 10ではプッシュ通知が正常に機能していますが、の場合はアプリがバックグラウンドのときにプッシュ通知の音が再生されません。 アプリのその他の状態については、すべて問題ありません。 バックグラウンドモードでのみ発行されます。

以下は実装プッシュ通知のコードです。

////////// FireBase//////////// 
    // Register for remote notifications 
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) { 
     // iOS 7.1 or earlier. Disable the deprecation warnings. 
#pragma clang diagnostic push 
#pragma clang diagnostic ignored "-Wdeprecated-declarations" 
     UIRemoteNotificationType allNotificationTypes = 
     (UIRemoteNotificationTypeSound | 
     UIRemoteNotificationTypeAlert | 
     UIRemoteNotificationTypeBadge); 
     [application registerForRemoteNotificationTypes:allNotificationTypes]; 
#pragma clang diagnostic pop 
    } else { 
     // iOS 8 or later 
     // [START register_for_notifications] 
     if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { 
      UIUserNotificationType allNotificationTypes = 
      (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); 
      UIUserNotificationSettings *settings = 
      [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; 
      [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 
     } else { 
      // iOS 10 or later 

#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 
      UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; 
      center.delegate = self; 
      [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ 
       if(!error){ 
        [[UIApplication sharedApplication] registerForRemoteNotifications]; 
       } 
      }]; 

      [[FIRMessaging messaging] setRemoteMessageDelegate:self]; 
#endif 
     } 

     [[UIApplication sharedApplication] registerForRemoteNotifications]; 
     // [END register_for_notifications] 
    } 


    [FIRApp configure]; 
    // [END configure_firebase] 
    // Add observer for InstanceID token refresh callback. 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:) 
               name:kFIRInstanceIDTokenRefreshNotification object:nil]; 

以下はデリゲート(S)であるため、受信した通知を管理:

Insdie以下

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

は、登録コードです。以下は

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 

    NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]); 
    NSLog(@"%@", userInfo); 

    [self manageAppAfterReceiveNotific: userInfo]; 
    completionHandler(UIBackgroundFetchResultNewData); 
} 

#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{ 

    NSDictionary *userInfo = response.notification.request.content.userInfo; 
    [self manageAppAfterReceiveNotific: userInfo]; 
} 
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{ 

    completionHandler(UNNotificationPresentationOptionAlert); 
} 

- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage { 

    NSLog(@"%@", [remoteMessage appData]); 

    [self manageAppAfterReceiveNotific: [remoteMessage appData]]; 
} 
#endif 

私のペイロードである:、firebase文書によると

{ 
    aps =  { 
     alert =   { 
      body = "any text"; 
      title = "New Notification"; 
     }; 
     badge = 1; 
     "content-available" = 1; 
     sound = default; 
    }; 
    extra = "{\"childrenId\":\"48\",\"timestamp\":\"1479724388\"}"; 
    "gcm.message_id" = "Message ID"; 
    noteType = "CHECK_OUT"; 
} 
+1

を参照してください、あなたはのペイロードを表示することができますあなたの通知? –

+0

@balkaran singh、私は質問を更新し、PayLoadをその中に追加します。 – Ayra

+0

こんにちは、アップロードペイロード、 – Ayra

答えて

関連する問題