由于公司極度惡心的要使用網(wǎng)易的授權(quán)登錄,找了好久,最終選擇了ShareSDK医舆,發(fā)現(xiàn)還是很好用的翁涤。
直接代碼
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//注冊shareSDk
[ShareSDK registerApp:@"xxxxx"];
//sina
[ShareSDK connectSinaWeiboWithAppKey:@"38xxxx979"
appSecret:@"7df5xxxxbf7c"
redirectUri:@"http://www.baidu.com"];
//網(wǎng)易
[ShareSDK connect163WeiboWithAppKey:@"T5EI7BXe13vfyDuy"
appSecret:@"gZxwyNOvjFYpxwwlnuizHRRtBRZ2lV1j"
redirectUri:@"http://www.shareSDK.cn"];
//人人
[ShareSDK connectRenRenWithAppId:@"226427"
appKey:@"fc5b8aed373c4c27a05b712acba0f8c3"
appSecret:@"f29df781abdd4f49beca5a2194676ca4"
renrenClientClass:[RennClient class]];
//QQ空間
[ShareSDK connectQZoneWithAppKey:@"100371282"
appSecret:@"aed9b0303e3ed1e27bae87c33761161d"
qqApiInterfaceCls:[QQApiInterface class]
tencentOAuthCls:[TencentOAuth class]];
//這是模擬服務(wù)器的具體在www.parse.com上找到
[Parse setApplicationId:@"Arqhxxxxx26seU9Nb"
clientKey:@"ixKhwYxxxxp9FHdf"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[FirViewController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
2.在viewController中
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 50, 100, 100);
[button setTitle:@"Sina授權(quán)" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)buttonAction:(UIButton *)button
{
if ([ShareSDK hasAuthorizedWithType:ShareTypeSinaWeibo]) {
MainViewController *mainVC = [[MainViewController alloc] init];
[self presentViewController:mainVC animated:YES completion:NULL];
}else{
[ShareSDK getUserInfoWithType:ShareTypeSinaWeibo
authOptions:nil
result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
if (result)
{
PFQuery *query = [PFQuery queryWithClassName:@"UserInfo"];
[query whereKey:@"uid" equalTo:[userInfo uid]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if ([objects count] == 0)
{
PFObject *newUser = [PFObject objectWithClassName:@"UserInfo"];
[newUser setObject:[userInfo uid] forKey:@"uid"];
[newUser setObject:[userInfo nickname] forKey:@"name"];
[newUser setObject:[userInfo profileImage] forKey:@"profileImage"];
[newUser saveInBackground];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello"
message:@"歡迎注冊"
delegate:nil
cancelButtonTitle:@"知道了"
otherButtonTitles:nil];
[alertView show];
}else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello"
message:@"歡迎回來"
delegate:nil
cancelButtonTitle:@"知道了"
otherButtonTitles:nil];
[alertView show];
}
}];
// MainViewController *mainVC = [[MainViewController alloc] init];
// [self presentViewController:mainVC animated:YES completion:NULL];
}
}];
}
}
詳情可在ShareSDK的官網(wǎng)上視頻中有講解头谜。