利用sharesdk来进行facebook的登录
by 伍雪颖
利用sharesdk来进行facebook的登录(当然也可以直接用Facebook-sdk-ios,不过用sharesdk相对简单点)
在国内app要加入facebook就是麻烦啊,因为要配置vpn,配置vpn后网速又慢.
1.下载sharesdk:(只下载facebook的部分,不然包大小会很大)
http://sharesdk.mob.com/Download
2.添加sdk进去工程和添加依赖的库
SystemConfiguration.framework
QuartzCore.framework
CoreTelephony.framework
libicucore.dylib
libz.1.2.5.dylib
Security.framework
3.引用注册码(要自己注册自己的appkey)
[ShareSDK
registerApp:@"5577ff992136"];
[ShareSDK
connectFacebookWithAppKey:@"107704292745179"
appSecret:@"38053202e1a5fe26c80c753071f0b573"];
4.返回的网页调用
- (BOOL)application:(UIApplication
*)application
handleOpenURL:(NSURL *)url
{
return [ShareSDK
handleOpenURL:url
wxDelegate:self];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [ShareSDK
handleOpenURL:url
sourceApplication:sourceApplication
annotation:annotation
wxDelegate:self];
}
5.添加facebook key
6.调用
- (IBAction)facebookLogin:(id)sender
{
[ShareSDK
getUserInfoWithType:ShareTypeFacebook
authOptions:nil
result:^(BOOL result,
id<ISSPlatformUser> userInfo,
id<ICMErrorInfo> error) {
NSLog(@"%@",[userInfo
sourceData]);
if (result) {
}
}];
}