简体   繁体   中英

Push Notification Error in IOS

I have used a firebase push notification in my application . I have created SSL certificate and uploaded p.12 file to my firebase project properly and there is no error in a code , but when i send a notification message from firebase , it shows message sent completed , but in my console i got this:

<Warning> [Firebase/Messaging][I-FCM002019] FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented

My code for firebase push notification is this:

#import "AppDelegate.h"

@import Firebase; @import FirebaseMessaging;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(tokenRefreshCallBack:) name:kFIRInstanceIDTokenRefreshNotification object:nil];

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(tokenRefreshCallBack:) name:kFIRInstanceIDTokenRefreshNotification object:nil];

UIUserNotificationType altype=(UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound);
UIUserNotificationSettings *settings=[UIUserNotificationSettings settingsForTypes:altype categories:nil];

[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];

[FIRApp configure];


return YES;

}

- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

[FIRMessaging messaging];
NSLog(@"Disconnected from FCM");

}

- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
 [self connectFirebase];

}

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
NSLog(@"Message ID %@:",userInfo[@"gcm.message_id"]);
NSLog(@"MMM %@",userInfo);

}

-(void)tokenRefreshCallBack:(NSNotification *)notification{
NSString *token=[[FIRInstanceID instanceID]token];
NSLog(@"Token is %@",token);
[self connectFirebase];

}

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

}

错误清楚地表明,您需要实现FIRMessaging delegate方法FIRMessaging messaging:didReceiveMessage: FIRMessaging messaging:didReceiveMessage:来接收消息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM