如何更改ios中FBSDKLoginButton中的默认登录按钮? [英] How to change Default login button in FBSDKLoginButton in ios?
本文介绍了如何更改ios中FBSDKLoginButton中的默认登录按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何自定义Facebook中的登录按钮?我不想使用Facebook默认登录按钮。
How to Customize the Login button in Facebook? I don't want to use Facebook default login button.
推荐答案
对于SDK 4.0:
你应该添加一个按钮,在按钮操作中使用以下代码:
U should add a button and in button action use the below code :
- (IBAction)loginButtonClicked:(id)sender {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
NSLog(@"error %@",error);
} else if (result.isCancelled) {
// Handle cancellations
NSLog(@"Cancelled");
} else {
if ([result.grantedPermissions containsObject:@"email"]) {
// Do work
NSLog(@"%@",result);
NSLog(@"Correct");
}
}
}];
}
已更新:要接收用户信息
- (IBAction)loginButtonClicked:(id)sender {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
NSLog(@"error %@",error);
} else if (result.isCancelled) {
// Handle cancellations
NSLog(@"Cancelled");
} else {
if ([result.grantedPermissions containsObject:@"email"]) {
// Do work
[self fetchUserInfo];
}
}
}];
}
-(void)fetchUserInfo {
if ([FBSDKAccessToken currentAccessToken]) {
NSLog(@"Token is available");
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"Fetched User Information:%@", result);
}
else {
NSLog(@"Error %@",error);
}
}];
} else {
NSLog(@"User is not Logged in");
}
}
这篇关于如何更改ios中FBSDKLoginButton中的默认登录按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文