当我在AppDelegate+Firebase.m
模块中包含以下委托方法时,我看到上面的消息。
- (void)messaging:(nonnull FIRMessaging *)messaging didRefreshRegistrationToken:(nonnull NSString *)fcmToken {
...
}
如果我没有包含委托方法,则应用会在收到令牌刷新时崩溃: -
[FIRA_AppDelegate-1509991141874 messaging:didRefreshRegistrationToken:]: unrecognized selector sent to instance 0x60000003c740'
我之前在application:didFinishLaunchingWithOptions
[FIRMessaging messaging].delegate = self;
我的问题是,为什么我会看到警告?
我认为"它的小学班级"是AppDelegate
,它源自CDVAppDelegate
,仅定义application:didFinishLaunchingWithOptions
,如下所示:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
self.viewController = [[MainViewController alloc] init];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
那么为什么告诉我它将由初级班实施?
修改的
RAW警告输出
.../redsky-firebase/AppDelegate+Firebase.m:156:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation] - (void)messaging:(nonnull FIRMessaging *)messaging didRefreshRegistrationToken:(nonnull NSString *)fcmToken { ^ In module 'FirebaseMessaging' imported from .../redsky-firebase/Firebase/Firebase.h:37: .../redsky-firebase/FirebaseMessaging.framework/Headers/FIRMessaging.h:252:1: note: method 'messaging:didRefreshRegistrationToken:' declared here - (void)messaging:(nonnull FIRMessaging *)messaging
来自AppDelegate+Firebase.m:156
的代码
// [START refresh_token] /* If I don't include this, I get an exception saying unrecognised selector - out of date fcm libs? */ - (void)messaging:(nonnull FIRMessaging *)messaging didRefreshRegistrationToken:(nonnull NSString *)fcmToken { NSLog(@"FIREBASE: (AppDelegate+Firebase) messaging:didRefreshRegistrationToken: %@", fcmToken); [Firebase.firebase sendToken:fcmToken]; }
来自FIRMessaging.h:252
的代码
@protocol FIRMessagingDelegate /// This method will be called whenever FCM receives a new, default FCM token for your /// Firebase project's Sender ID. /// You can send this token to your application server to send notifications to this device. - (void)messaging:(nonnull FIRMessaging *)messaging didRefreshRegistrationToken:(nonnull NSString *)fcmToken FIR_SWIFT_NAME(messaging(_:didRefreshRegistrationToken:));