Protocol - 6

Protocol 委托协议还有一种很常用的实现作用,实现它之后提供回调操作! 非常实用,例如在接I4SDK的时候:

@protocol AsPlatformSDKDelegate <NSObject>
@required

- (void)asLoginCallBack:(NSString *)paramToken;

/* 省略了一系列其他回调操作 */

@end

实现这个协议之后:

@interface SYJYLianYun()<AsPlatformSDKDelegate>

@end

在登录后回调验证Token UID等操作:

//登录回调验证Token
- (void)asLoginCallBack:(NSString *)paramToken
{
    NSString *uin = [NSString stringWithFormat:@"%lld", [[AsPlatformSDK sharedInstance] currentUserId]];
    
    [[SYHTTPRequestManager shareRequestManager] requestVerificationWithLianYunToken:paramToken uin:uin success:^(NSInteger sqUid, NSString *sqToken, NSString *userName) {
        NSString *gid = [[SYSystemInfo  shareSystemInfo] gameID];
        NSString *pid = [[SYSystemInfo  shareSystemInfo] partner];
        NSDictionary *dic = [[NSDictionary  alloc] initWithObjectsAndKeys:sqToken,@"token",pid,@"pid",gid,@"gid",nil];
        
        if ([SYUserInfo shareInstance].uLogin == 1)
        {
            //talkingData 登录
            if ([SYSystemInfo shareSystemInfo].isTalkingData)
            {
                [TalkingDataAppCpa onLogin:[NSString stringWithFormat:@"%d", sqUid]];
            }
        }
        else if ([SYUserInfo shareInstance].uLogin == 0)
        {
            //talkingData 注册
            if ([SYSystemInfo shareSystemInfo].isTalkingData)
            {
                [TalkingDataAppCpa onRegister:[NSString stringWithFormat:@"%d", sqUid]];
                [TalkingDataAppCpa onLogin:[NSString stringWithFormat:@"%d", sqUid]];
            }
        }
        
        [[NSNotificationCenter  defaultCenter] postNotificationName:LOGINIFONOTIFICATION
                                                             object:dic];
    } failure:^(NSInteger code, NSString *message) {
        [[NSNotificationCenter  defaultCenter] postNotificationName:LOGINIFONOTIFICATION
                                                             object:nil];
    }];
}

问题来了?我只是实现了协议,没有看到啥主动调用的操作,为什么会自动帮我执行方法?



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值