I have a FBLoginView with property loginButton, and I want to make a button that is not in the same view fire this FBLoginView built in button feature. Does anyone have any suggestions? thanks
Download latest facebook SDK install and import coreKit & LoginKit frameworks in target.
Create one sample button and give action.
Ex:
[fbLogin addTarget:self action:@selector(facebookLogin:) forControlEvents:UIControlEventTouchUpInside];
#import<FBSDKCoreKit/FBSDKCoreKit.h>
#import<FBSDKLoginKit/FBSDKLoginKit.h>
-(void)facebookLogin:(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");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.