我在我的应用程序中使用了firebase推送通知。我已经创建了SSL证书并正确地将p.12文件上传到我的firebase项目中并且代码中没有错误,但是当我从firebase发送通知消息时,它显示已完成消息,但在我的控制台中我得到了这个:< / p>
<Warning> [Firebase/Messaging][I-FCM002019] FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented
我的firebase推送通知代码如下:
#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");
}
}];
}
答案 0 :(得分:0)
错误清楚地表明您需要实施FIRMessaging
delegate
方法messaging:didReceiveMessage:
来接收邮件。