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];
}];
}
问题来了?我只是实现了协议,没有看到啥主动调用的操作,为什么会自动帮我执行方法?