3

我正在使用带有 ios 5 的 facebook sdk 3。我想每次向用户询问登录窗口。期望不同的用户使用应用程序。我试过下面的代码。它在应用程序内的弹出视图中显示登录,而不是使用 safari。但是在我登录或关闭窗口后应用程序崩溃。

NSArray *permissions = [NSArray arrayWithObjects:@"publish_actions", @"user_photos", nil];
FBSessionLoginBehavior behavior = FBSessionLoginBehaviorForcingWebView;
FBSessionTokenCachingStrategy *tokenCachingStrategy = [[FBSessionTokenCachingStrategy alloc]
                                                       initWithUserDefaultTokenInformationKeyName:@"FBTest"];


FBSession *session = [[FBSession alloc] initWithAppID:@"Appid"
                                          permissions:permissions
                                      urlSchemeSuffix:nil 
                                   tokenCacheStrategy:tokenCachingStrategy];

[session openWithBehavior:behavior
        completionHandler:^(FBSession *session,
                            FBSessionState status,
                            NSError *error) {
            // this handler is called back whether the login succeeds or fails; in the 
            // success case it will also be called back upon each state transition between
            // session-open and session-close
            if (error) {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                    message:error.localizedDescription
                                                                   delegate:nil
                                                          cancelButtonTitle:@"OK"
                                                          otherButtonTitles:nil];
                [alertView show];
            }
            NSLog(@"SUCEEES");
            [self sessionStateChanged:session state:session.state error:error]; 
        }];
4

1 回答 1

0
FBLoginView *loginview = [[FBLoginView alloc] init];

loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;

[self.view addSubview:loginview];

[loginview sizeToFit];

这将要求每次登录窗口

于 2013-04-16T07:47:39.277 回答