Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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
FBSDKLoginManager未在本机ios应用程序中打开登录对话框_Ios_Facebook - Fatal编程技术网

FBSDKLoginManager未在本机ios应用程序中打开登录对话框

FBSDKLoginManager未在本机ios应用程序中打开登录对话框,ios,facebook,Ios,Facebook,我是iPhone开发新手,我想使用最新的facebook sdk 4从我的原生iOS简单应用程序登录facebook。我只是想在我的应用程序中,从自定义的UIButtonclick打开一个facebook登录对话框,我在下面的代码中使用我的按钮点击方法 - (IBAction)didTapLoginFaceBook:(id)sender { FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login l

我是iPhone开发新手,我想使用最新的facebook sdk 4从我的原生iOS简单应用程序登录facebook。我只是想在我的应用程序中,从自定义的
UIButton
click打开一个facebook登录对话框,我在下面的代码中使用我的按钮点击方法

- (IBAction)didTapLoginFaceBook:(id)sender {

    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) {
            // Process error

        NSLog(@"Unexpected login error: %@", error);
        NSString *alertMessage = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?: @"There was a problem logging in. Please try again later.";
        NSString *alertTitle = error.userInfo[FBSDKErrorLocalizedTitleKey] ?: @"Oops";
        [[[UIAlertView alloc] initWithTitle:alertTitle
                                        message:alertMessage
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil] show];


        } else if (result.isCancelled) {
            // Handle cancellations
        } else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            if ([result.grantedPermissions containsObject:@"email"]) {
                // Do work
            }
        }
    }];


}
此代码与其他代码不同,但我想在本机iOS应用程序中打开一个自定义
ui按钮
单击的登录对话框


因此,请用一些代码建议正确的方法,提前感谢您使用Objective-C中的自定义按钮登录Facebook 4.x

- (IBAction)btnFacebookPressed:(id)sender {
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    login.loginBehavior = FBSDKLoginBehaviorBrowser;
    [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
     {
         if (error)
         {
             // Process error
         }
         else if (result.isCancelled)
         {
             // Handle cancellations
         }
         else
         {
             if ([result.grantedPermissions containsObject:@"email"])
             {
                 NSLog(@"result is:%@",result);
                 [self fetchUserInfo];
                 [login logOut];
             }
         }
     }];
}

- (void)fetchUserInfo {
    if ([FBSDKAccessToken currentAccessToken])
    {
        NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);

        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location , friends ,hometown , friendlists"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error)
             {
                 NSLog(@"resultis:%@",result);

             }
             else
             {
                 NSLog(@"Error %@",error);
             }
         }];
    }
}

使用Swift中的自定义按钮登录Facebook 4.x

@IBAction func btnFacebookPressed(_ sender: Any) {

    let loginManager = FBSDKLoginManager()
    loginManager.loginBehavior = FBSDKLoginBehavior.browser;

    loginManager.logIn(withReadPermissions: ["email"], from: self, handler: {(result : FBSDKLoginManagerLoginResult?, error : Error?) -> Void in
        if error != nil {
            // Process error
        }
        else if (result?.isCancelled)! {
            // Handle cancellations
        }
        else if (result?.grantedPermissions.contains("email"))! {
            print("result is: \(result)");
            self.fetchUserInfo()
            loginManager.logOut()
        }
    })
}


func fetchUserInfo() {
    if let accessToken = FBSDKAccessToken.current()?.tokenString {
        print("Token is available : \(accessToken)")

        FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location , friends ,hometown , friendlists"]).start(completionHandler: { (connection : FBSDKGraphRequestConnection?, result : Any?, error : Error?) in

            if let error = error {
                print("Error \(error)")
            }
            else if let result  = result {
                print("result:\(result)")
            }
        })
    }
}

如何注销当前用户?当我再次按下登录按钮时,它会直接进入“您已经授权的演示应用程序”。我使用另一个按钮进行注销,@Hirenkanetiya yes,将此代码添加到您的注销按钮中action@Hirenkanetiya
[[FBSDKLoginManager new]注销]从登录按钮的代码中删除注销代码,然后单击按钮注销自己。你也可以检查这个答案