Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ios中更改FBSDKLoginButton中的默认登录按钮?_Ios_Objective C - Fatal编程技术网

如何在ios中更改FBSDKLoginButton中的默认登录按钮?

如何在ios中更改FBSDKLoginButton中的默认登录按钮?,ios,objective-c,Ios,Objective C,如何在Facebook中自定义登录按钮?我不想使用Facebook的默认登录按钮 您应该添加一个ui按钮,并添加如下单击方法: - (IBAction)fbLogin:(id)sender { [FBSession.activeSession closeAndClearTokenInformation]; [FBSession openActiveSessionWithReadPermissions:@[@"public_profile"]

如何在Facebook中自定义登录按钮?我不想使用Facebook的默认登录按钮

您应该添加一个
ui按钮
,并添加如下单击方法:

- (IBAction)fbLogin:(id)sender {
    [FBSession.activeSession closeAndClearTokenInformation];
    [FBSession openActiveSessionWithReadPermissions:@[@"public_profile"]
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *fbSession, FBSessionState state, NSError *error) {
                                      [self sessionStateChanged:fbSession state:state error:error];
                                  }];
}
对于SDK 4.0:

U应添加一个按钮,并在按钮操作中使用以下代码:

- (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 9。将此代码放在按钮操作方法中

[FBSession openActiveSessionWithReadPermissions:@[@"public_profile",@"email",@"user_friends"]
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {


         // The session is open. Get the user information and update the UI.
         [FBRequestConnection startWithGraphPath:@"me"
                                      parameters:@{@"fields": @"first_name,last_name, email"}
                                      HTTPMethod:@"GET"
                               completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                   if (!error) {
                                       // Set the use full name.

                                       NSLog(@"FBresponse: =>%@",result);
                                   }
                                   else{
                                       NSLog(@"%@", [error localizedDescription]);
                                   }
                               }];



     }];

谢谢你完全按照我的要求工作。。还有一件事。。如何在弹出窗口中显示FBlogin视图?你能推荐我吗?提前感谢@dheeraj singhdo您想在弹出窗口中显示登录按钮吗?或插入凭据时的视图。在上述代码中,[result.grantedPermission]未返回任何内容。。电子邮件只有在您登录后才为空,或者在成功登录后调用了其他条件。如果([result.grantedPermissions containsObject:@“email”]){//Do work NSLog(@“%@”,result);NSLog(@“Correct”);}在这种情况下,我不会收到facebook用户的电子邮件@dheeraj singhFBLoginView由于FBSDKLoginKit的存在而被弃用。Facebook强烈建议我们使用最新的SDK,以便批准Facebook SDK 4.x中不存在AppStoreFBSession应用程序
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile",@"email",@"user_friends"]
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {


         // The session is open. Get the user information and update the UI.
         [FBRequestConnection startWithGraphPath:@"me"
                                      parameters:@{@"fields": @"first_name,last_name, email"}
                                      HTTPMethod:@"GET"
                               completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                   if (!error) {
                                       // Set the use full name.

                                       NSLog(@"FBresponse: =>%@",result);
                                   }
                                   else{
                                       NSLog(@"%@", [error localizedDescription]);
                                   }
                               }];



     }];