提供第三方开放平台的集成服务,一句代码实现一种功能~喜欢的朋友可以前来点个小星星 开源库下载地址
目前市面上提供的第三方SDK,相当繁琐臃肿,还需要去他们的集成平台上注册各种key之类的,相当麻烦. CC轻量级开放平台服务 提供一行代码请求数据服务,底层集成了各平台SDK,用户无需关心具体平台的实现,省事省心.
1 直接将整个目录拖到你的项目中.(注意用group形式,目录会显示成黄色).本库用到AFNetworking,需要自己集成.
2 在AppDelegate.m文件顶部引入头文件CCOpenService.h,CCOpenConfig.h,并且写入下面的配置信息(注意,类似WeiXinAppID这样的,填写自己的微信appID)
//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//微信配置
[CCOpenConfig setWeiXinAppID:WeiXinAppID];
[CCOpenConfig setWeiXinAppSecret:WeiXinAppSecret];
//QQ配置
[CCOpenConfig setQQAppID:QQAppID];
[CCOpenConfig setQQAppKey:QQAppKey];
//微博配置
[CCOpenConfig setWeiBoAppKey:WeiBoAppKey];
[CCOpenConfig setWeiBoAppSecret:WeiBoAppSecret];
[CCOpenConfig setWeiBoRedirectURI:WeiBoRedirectURI];
return YES;
}
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
//配置微信,QQ,新浪
CCOpenService *wxService = [CCOpenService getOpenServiceWithName:CCOpenServiceNameWeiXin];
CCOpenService *qqService = [CCOpenService getOpenServiceWithName:CCOpenServiceNameQQ];
CCOpenService *wbService = [CCOpenService getOpenServiceWithName:CCOpenServiceNameWeiBo];
return [wxService handleOpenURL:url] || [qqService handleOpenURL:url] || [wbService handleOpenURL:url];
}
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
//配置微信,QQ,新浪
CCOpenService *wxService = [CCOpenService getOpenServiceWithName:CCOpenServiceNameWeiXin];
CCOpenService *qqService = [CCOpenService getOpenServiceWithName:CCOpenServiceNameQQ];
CCOpenService *wbService = [CCOpenService getOpenServiceWithName:CCOpenServiceNameWeiBo];
return [wxService handleOpenURL:url] || [qqService handleOpenURL:url] || [wbService handleOpenURL:url];
}
3 参考各个平台关于URL scheme的配置指南.例如微信:
4 iOS9 设备需要添加白名单,参考 iOS9白名单
服务类型目前支持CCOpenServiceNameWeiXin,CCOpenServiceNameQQ,CCOpenServiceNameWeiBo
//微信登录
CCOpenService *wxService = [CCOpenService getOpenServiceWithName:CCOpenServiceNameWeiXin];
[wxService requestOpenAccount:^(CCOpenRespondEntity *respond) {
if (respond == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"^_^亲,您木有安装微信哟~ " delegate:nil cancelButtonTitle:@"知道啦" otherButtonTitles:nil];
[alert show];
return;
}
NSLog(@"Respond data is %@",respond.data);
}];
WeiXin,QQ,WeiBo目录下的SDK需要手动导入,另外第三方平台的SDK可能需要手动导入一些类库,具体的先参考具体平台的官方说明,有空更新上.由于本人工作忙,所以很多功能还没时间写上.目前已经写好了整体框架,有兴趣的同学可当作自己学习锻炼机会,参考我的源码设计模式,将新增的功能PullRrequest给我,谢谢.