协议内部有多个方法,全部使用@optional修饰,执行其中一个方法,直接报错,结果显示reason: '-[BSGMatchViewController doSendMessageFromJPush:]: unrecognized selector sent to instance 0x1063a1800'
。
但是协议方法:doSendMessageFromJPush
在其他页面执行,并没有在BSGMatchViewController
使用,为什么会报错并显示以上报错信息呢?求解
协议是在AppDelegate
页面设置的,用于监听极光推送并通过协议发送对应方法。
AppDelegate.h:
//极光推送收到消息后通过协议传递信息
@protocol BSGJPushRegistrationIDDelegate <NSObject>
@optional
//前两个发送给首页`viewController`,第三个根据极光推送发送给其他页面
//发送极光推送registrationID
- (void)doSendRegistrationID:(NSString *)registrationID;
//发送极光推送消息
- (void)doSendMessageFromJPush:(NSMutableDictionary *)content;
-(void)doSendMatchInfoFromJPush:(NSMutableDictionary *)content;
@end
AppDelegate.m:-(void)doSendMatchInfoFromJPush:(NSMutableDictionary *)content
协议方法通过doJPushMatchWithUserInfo
方法在- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler
处调用:
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
// Required
NSDictionary * userInfo = notification.request.content.userInfo;
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
//此处使用极光推送,参数由后台确认并使用。
[self doJPushMatchWithUserInfo:userInfo];
}
而-(void)doJPushMatchWithUserInfo:(NSDictionary *)userInfo
内部调用协议方法:
-(void)doJPushMatchWithUserInfo:(NSDictionary *)userInfo{
BSGLog(@"极光推送消息(全部打印):%@",userInfo);
NSMutableDictionary * infoDictionary = [userInfo mutableCopy];
//此处使用极光推送,参数由后台确认并使用。
if (userInfo[@"webview_param"] && userInfo[@"webview_param"][@"type"]) {
[self.delegate doSendMatchInfoFromJPush:infoDictionary];
}
}
有时候执行到[self.delegate doSendMatchInfoFromJPush:infoDictionary];
这一步会报错,设了断点以后,点击两次continue后才会报错,报错信息如上。
具体是在AppDelegate哪个回调设置的呢?调用的时机又是哪里呢?请提供具体代码展示