0

我已經在firebase..but添加的APN證書時,我從FCM發送通知我的設備不顯示任何通知,也實例id和MESSAGEID給出了輸出空無法通過FCM真實設備

這裏得到通知是我的應用程序delegate.m代碼

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
 
    // Override point for customization after application launch. 
 
    sleep(3); 
 
    SplitsVC*log=[[SplitsVC alloc] initWithNibName:@"SplitsVC" bundle:nil]; 
 
    
 
    self.navVC=[[MyNavigationController alloc] initWithRootViewController:log]; 
 
    
 
    [self.navVC.navigationBar setHidden:YES]; 
 
    [self.window setRootViewController:self.navVC]; 
 
    [self.window makeKeyAndVisible]; 
 
    // Add observer to listen for the token refresh notification. 
 
    // Register for remote notifications 
 
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) { 
 
     // iOS 7.1 or earlier 
 
     UIRemoteNotificationType allNotificationTypes = 
 
     (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge); 
 
     [application registerForRemoteNotificationTypes:allNotificationTypes]; 
 
    } else { 
 
     // iOS 8 or later 
 
     // [START register_for_notifications] 
 
     UIUserNotificationType allNotificationTypes = 
 
     (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); 
 
     UIUserNotificationSettings *settings = 
 
     [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; 
 
     [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 
 
     [[UIApplication sharedApplication] registerForRemoteNotifications]; 
 
     // [END register_for_notifications] 
 
    } 
 
    
 
    // [START configure_firebase] 
 
    [FIRApp configure]; 
 
    // [END configure_firebase] 
 
    
 
    // Add observer for InstanceID token refresh callback. 
 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:) 
 
               name:kFIRInstanceIDTokenRefreshNotification object:nil]; 
 
    return YES; 
 
} 
 

 
// [START receive_message] 
 
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
 
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 
 
    // If you are receiving a notification message while your app is in the background, 
 
    // this callback will not be fired till the user taps on the notification launching the application. 
 
    // TODO: Handle data of notification 
 
    
 
    // Print message ID. 
 
    NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]); 
 
    
 
    // Pring full message. 
 
    NSLog(@"%@", userInfo); 
 
} 
 
// [END receive_message] 
 

 
// [START refresh_token] 
 
- (void)tokenRefreshNotification:(NSNotification *)notification { 
 
    // Note that this callback will be fired everytime a new token is generated, including the first 
 
    // time. So if you need to retrieve the token as soon as it is available this is where that 
 
    // should be done. 
 
    NSString *refreshedToken = [[FIRInstanceID instanceID] token]; 
 
    NSLog(@"InstanceID token: %@", refreshedToken); 
 
    
 
    // Connect to FCM since connection may have failed when attempted before having a token. 
 
    [self connectToFcm]; 
 
    
 
    // TODO: If necessary send token to appliation server. 
 
} 
 
// [END refresh_token] 
 

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

 
- (void)applicationDidBecomeActive:(UIApplication *)application { 
 
    [self connectToFcm]; 
 
} 
 

 
// [START disconnect_from_fcm] 
 
- (void)applicationDidEnterBackground:(UIApplication *)application { 
 
    [[FIRMessaging messaging] disconnect]; 
 
    NSLog(@"Disconnected from FCM"); 
 
} 
 
// [END disconnect_from_fcm]

,這是輸出 - enter image description here

+0

請告訴我解決方案.... – arun

回答

1

請確保firebase上的證書和您在xcode中使用的證書相同。並且請嘗試查看Firebase的文檔。

+0

先生我的項目簽署代碼身份沒有得到現有的證書,所以我怎麼能解決這個問題?..請先生指導我我已經浪費了兩天 – arun

+0

請嘗試下載您的證書和從https://developer.apple.com/提供配置文件,並在Firebase雲消息傳遞部分中上傳相同的(.p12)證書。 –