Make Button touchUpInside FBLoginView

不羁的心 提交于 2020-01-16 01:12:20

问题


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


回答1:


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");
    }
}


来源:https://stackoverflow.com/questions/31528948/make-button-touchupinside-fbloginview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!