未配置帐户时登录不起作用

时间:2014-03-13 08:23:18

标签: objective-c ios7 facebook-sdk-3.1

我在我的应用程序中使用Facebook sdk登录控件,只要用户在iOS的设置部分配置了他的Facebook帐户,该工作正常。

问题是没有配置帐户报告的用户无法登录。

为了测试这个问题,我删除了我的帐户,确实 - 尝试登录时,我看到应用程序正在打开Facebook应用程序/浏览器并立即将其关闭并返回登录屏幕。

是否有登录控件的特殊配置或实现登录的替代方法,以便它支持所有用户?

我的代码:

     FBLoginView *loginView = [[FBLoginView alloc] init];
    loginView.delegate=self;
    loginView.readPermissions = @[@"basic_info", @"email"];
    loginView.defaultAudience=FBSessionDefaultAudienceEveryone;


    loginView.frame = CGRectOffset(loginView.frame, (self.view.center.x - (loginView.frame.size.width / 2)), 270);
    [self.view addSubview:loginView];

1 个答案:

答案 0 :(得分:1)

将以下代码添加到AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
     [FBLoginView class];

     return YES;
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    [[FBSession activeSession] handleDidBecomeActive];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    [[FBSession activeSession] close];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    // Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
    BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];

    // You can add your app-specific url handling code here if needed

    return wasHandled;
}