2016-06-24 6 views
5

https://developers.google.com/cloud-messaging/ios/clientのようにGCMクラウドメッセージングのアップグレード版であるFCMクラウドメッセージングを導入した後、前述のようにポッドを使用してFCMを統合するように移動しましたhttps://firebase.google.com/docs/cloud-messaging/notificationsチュートリアルは、リモート通知が両方の状態でうまく受信されたことです。バックグラウンド状態アクティブ状態しかし、私が直面した主な問題は通知バーに表示されます。私のコードは私が使用していますリモート通知はFCMを使用してiosに表示されません

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



    float ver = [[[UIDevice currentDevice] systemVersion] floatValue]; 

    if(ver >= 8 && ver<9) 
    { 
     if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) 
     { 
      [[UIApplication sharedApplication] registerForRemoteNotifications]; 
      UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]; 
      [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 

     } 
    }else if (ver >=9){ 

     [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 

     [[UIApplication sharedApplication] registerForRemoteNotifications]; 


    } 
    else{ 
     //iOS6 and iOS7 specific code 
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert]; 
    } 
    // ma tensa google maps 
    [FIRApp configure]; 
    [self connectToFcm]; 

} 


- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { 

    NSLog(@"My token is: %@", deviceToken); 
} 

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { 
    NSLog(@"Failed to get token, error: %@", error); 
} 
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 


     UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
     localNotification.userInfo = userInfo; 
     localNotification.applicationIconBadgeNumber = 0; 
     localNotification.soundName = UILocalNotificationDefaultSoundName; 
     localNotification.fireDate = [NSDate date]; 
     [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

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


//  
// if (application.applicationState == active) { 
//  <#statements#> 
// } 
    // Pring full message. 
    NSLog(@"%@", userInfo); 
} 

- (void)applicationDidEnterBackground:(UIApplication *)application { 

    // [[FIRMessaging messaging] disconnect]; 


} 


- (void)connectToFcm { 
    [[FIRMessaging messaging] connectWithCompletion:^(NSError * _Nullable error) { 
     if (error != nil) { 
      NSLog(@"Unable to connect to FCM. %@", error); 
     } else { 
      NSLog(@"Connected to FCM."); 

       [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"registeredToFCM"]; 
       [[NSUserDefaults standardUserDefaults] synchronize]; 




    // i used the method since not all the time app register for fcm so when 
//the complete launching and did not register // 
//for fcm the app request to register fro fcm again// 

     } 
    }]; 
} 

ここで私が検索するリンクここNotifications are not getting in iOS 9.2を移動する前に、私の問題を解決するためのED、FCM background notifications not working in iOS、およびPush notifications are not working in iOS 9私は

私の問題を解決することができませんでしたが、電話が鳴っと通知を受信した際に振動していることを伝えるのを忘れていました。

希望するいずれかのヘルプハッピーコーディング !!

+0

追記:マップを忘れずに、追加 '#warningミリアンペアのtensa Googleがプッシュして送信されたペイロードの種類 – Hussein

+0

maps'?プッシュペイロードの例を提供できますか(JSONは多分?)? – Hussein

+0

fcmコンソールから –

答えて

0

通知を表示する場合は、「優先度」を設定する必要があります。「高」。これと同じように:

"to":"TOKEN ID", 
"notification" : { 
    "body" : "test" 
}, 
"priority": "high" 
} 
関連する問題