简体   繁体   English

Facebook登录可在iPhone模拟器上使用,但不能在iPhone设备上使用

[英]facebook login works on iphone simulator but not on iphone device

In my app, I want to take photos from the facebook. 在我的应用中,我想从Facebook上拍照。 so i used facebook ios sdk. 所以我用了facebook ios sdk。 i can be able to authorize from the below code: 我可以从以下代码进行授权:

 if (appDelegate.session.isOpen) {

            //[appDelegate.session closeAndClearTokenInformation];
            [self retrieveAlbums];

        } else {
            if (appDelegate.session.state != FBSessionStateCreated) {
                // Create a new, logged out session.
                appDelegate.session = [[FBSession alloc] init];
            }

            // if the session isn't open, let's open it now and present the login UX to the user
            [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                             FBSessionState status,
                                                             NSError *error) {
                // and here we make sure to update our UX according to the new session state
                //NSLog(@"%@",session.accessTokenData.accessToken);
                [self retrieveAlbums];
            }];

It works fine on iphone simulator. 在iPhone模拟器上可以正常工作。 But I can't able to login on my iphone 4 device. 但是我无法在iphone 4设备上登录。 When I tried to login it will open a safari and then shows the message Updating. 当我尝试登录时,它将打开一个野生动物园,然后显示消息“正在更新”。 Then it will redirect without authorization. 然后它将未经授权重定向。 access token retrieved as nil. 获取为nil的访问令牌。 So I cant able to retreive images. 所以我不能撤回图像。

Please help me. 请帮我。

EDIT 编辑

Thanks for everyone .Finally I solved my problem. 谢谢大家。最后我解决了我的问题。 It is because i enabled sandbox mode in facebook developer account settings. 这是因为我在Facebook开发者帐户设置中启用了沙箱模式。 When i disabled the sandbox mode, it works normally. 当我禁用沙箱模式时,它可以正常工作。

Try clearing the cookies and cache of your safari, going to Settings. 尝试清除“ Safari”的Cookie和缓存,然后转到“设置”。 Also if you do not want the app to redirect to Safari, just dont provide the URL Scheme in your info.plist that is something like "fb-AppId-" and it will open a popup for login 另外,如果您不希望应用程序重定向到Safari,只需在info.plist中不提供类似于“ fb-AppId-”之类的URL方案,它将打开一个用于登录的弹出窗口

I was having the similar problem and solved it by composing couple of solutions in this website. 我遇到了类似的问题,并通过在此网站中编写了几个解决方案来解决了这个问题。 First of all I got rid of the url scheme at my info plist. 首先,我在info plist上取消了url方案。 So now my app opens up the facebook login dialog inside my registration page. 因此,现在我的应用程序在我的注册页面中打开了Facebook登录对话框。 Which is a good thing because it doesn't go back and forth to safari for facebook authentication and you stay inside the app. 这是一件好事,因为它不会来回进行Safari进行Facebook身份验证,而您却留在应用程序内。 The second thing I made is, putting an error handling mechanism inside my code for facebook login. 我做的第二件事是,在我的代码中放置了一个错误处理机制以用于Facebook登录。 So if login with facebook fails, it uses another strategy for logging in. 因此,如果用facebook登录失败,它将使用另一种策略登录。

Here is my code. 这是我的代码。

  - (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error {

      NSArray *permissions = [[NSArray alloc] initWithObjects:
                        @"public_profile", @"user_friends", @"email",
                        nil];
      FBSession *session = [[FBSession alloc] initWithPermissions:permissions];
      [FBSession setActiveSession:session];

      [self openSessionWithAllowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
         if (!error && status == FBSessionStateOpen) {
           NSString *token = session.accessTokenData.accessToken;
           NSLog(@"Logged in! - Token -- %@", token);
         } else {
           NSLog(@"Something wrong happened");//you can check the error code here
         }
     }];
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 适用于iPhone Simulator,但不适用于设备 - Works on iPhone Simulator but not on device 代码可在iPhone模拟器上运行,但不能在设备上运行 - Code works on iPhone simulator but not on the device 应用程序只能在iPhone设备上运行,而不能在模拟器上运行 - App works on iPhone device, but not on Simulator iPhone 4:Touches在模拟器上有效,但在设备上无效 - iPhone 4: Touches works on simulator but not on device 在iPhone模拟器中工作正常,但在iPhone设备中锁定 - Works fine in iphone simulator but lockup in an iphone device iPhone HTTP服务器可在模拟器上运行,但不适用于iPhone设备 - iPhone HTTP server works on simulator but not on iPhone device 收听声音只能在iPhone模拟器上使用,而不能在设备上使用 - Listening to sounds works on the iPhone simulator but not on the device LAPACK 例程适用于 iPhone 模拟器,但不适用于设备 - LAPACK routine works on iPhone simulator, but not on device 我的iPhone应用程序可以在设备上运行,但不能在模拟器上运行 - My iPhone app works on the device, but not the simulator iPhone 6上的本机分辨率可在模拟器上使用,但不能在设备上使用 - Native resolution on iPhone 6, works on simulator but not on device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM