简体   繁体   English

IOS中的推送通知错误

[英]Push Notification Error in IOS

I have used a firebase push notification in my application . 我在应用程序中使用了firebase推送通知。 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: 我已经创建了SSL证书并将p.12文件正确上传到我的Firebase项目中,并且代码中没有错误,但是当我从firebase发送通知消息时,它显示消息已完成,但是在我的控制台中,我得到了:

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

My code for firebase push notification is this: 我的firebase推送通知代码是这样的:

#import "AppDelegate.h"

@import Firebase; @import Firebase; @import FirebaseMessaging; @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:来接收消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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