在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/C  iOS/ 【iOS】協(xié)議方法采用@optional,使用報錯

【iOS】協(xié)議方法采用@optional,使用報錯

協(xié)議內(nèi)部有多個方法,全部使用@optional修飾,執(zhí)行其中一個方法,直接報錯,結果顯示reason: '-[BSGMatchViewController doSendMessageFromJPush:]: unrecognized selector sent to instance 0x1063a1800'
但是協(xié)議方法:doSendMessageFromJPush在其他頁面執(zhí)行,并沒有在BSGMatchViewController使用,為什么會報錯并顯示以上報錯信息呢?求解

協(xié)議是在AppDelegate頁面設置的,用于監(jiān)聽極光推送并通過協(xié)議發(fā)送對應方法。

AppDelegate.h:

//極光推送收到消息后通過協(xié)議傳遞信息
@protocol BSGJPushRegistrationIDDelegate <NSObject>

@optional
//前兩個發(fā)送給首頁`viewController`,第三個根據(jù)極光推送發(fā)送給其他頁面
//發(fā)送極光推送registrationID
- (void)doSendRegistrationID:(NSString *)registrationID;
//發(fā)送極光推送消息
- (void)doSendMessageFromJPush:(NSMutableDictionary *)content;

-(void)doSendMatchInfoFromJPush:(NSMutableDictionary *)content;

@end

AppDelegate.m:
-(void)doSendMatchInfoFromJPush:(NSMutableDictionary *)content協(xié)議方法通過doJPushMatchWithUserInfo方法在- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler處調(diào)用:


- (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); // 需要執(zhí)行這個方法,選擇是否提醒用戶,有Badge、Sound、Alert三種類型可以選擇設置
    
    //此處使用極光推送,參數(shù)由后臺確認并使用。
    [self doJPushMatchWithUserInfo:userInfo];
    
    
    
}

-(void)doJPushMatchWithUserInfo:(NSDictionary *)userInfo內(nèi)部調(diào)用協(xié)議方法:


-(void)doJPushMatchWithUserInfo:(NSDictionary *)userInfo{
    
    BSGLog(@"極光推送消息(全部打?。?@",userInfo);
    
    NSMutableDictionary * infoDictionary = [userInfo mutableCopy];
    
    //此處使用極光推送,參數(shù)由后臺確認并使用。
    if (userInfo[@"webview_param"]  && userInfo[@"webview_param"][@"type"]) {
        
        [self.delegate doSendMatchInfoFromJPush:infoDictionary];
        
    }
    
}

有時候執(zhí)行到[self.delegate doSendMatchInfoFromJPush:infoDictionary];這一步會報錯,設了斷點以后,點擊兩次continue后才會報錯,報錯信息如上。

回答
編輯回答
久舊酒

具體是在AppDelegate哪個回調(diào)設置的呢?調(diào)用的時機又是哪里呢?請?zhí)峁┚唧w代碼展示

2017年2月9日 07:36
編輯回答
離魂曲

謝謝邀請。
1.設置delegate設置錯了對象
2.AppDelegate里面沒有實現(xiàn)這個方法
3.方法沒有添加@objc

2018年2月10日 21:09