2

我正在使用Facebook-ios-sdk 3.0.8登录我的应用程序。它在第一次运行良好并给了我Username来自FbGraph但它在我下次登录时崩溃了 Xcode.. 原因是什么...请检查代码并让我知道...

- (IBAction)buttonClickHandler:(id)sender {
// get the app delegate so that we can access the session property
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];

// this button's job is to flip-flop the session from open to closed
if (appDelegate.session.isOpen) {

    [appDelegate.session closeAndClearTokenInformation];

} else {
    if (appDelegate.session.state != FBSessionStateCreated) {

        appDelegate.session = [[FBSession alloc] init];
    }


    [FBSession.activeSession openWithBehavior:FBSessionLoginBehaviorForcingWebView

                        completionHandler:^(FBSession *session,

                                            FBSessionState state,

                                            NSError *error) {
                            // and here we make sure to update our UX according to the new session state
                            [self updateView];
                            NSLog(@" state=%d",state);

                            [FBRequestConnection
                             startForMeWithCompletionHandler:^(FBRequestConnection *connection,
                                                               id<FBGraphUser> user,
                                                               NSError *error) {

                                 userInfo = @"";

                                 // Example: typed access (name)
                                 // - no special permissions required
                                 userInfo = user.username;

                                 NSLog(@"string %@", userInfo); 


                             }];




                        }];    } 


}

首次登录输出

2013-01-16 13:56:35.613 facebooktest[2690:f803]  state=513
2013-01-16 13:56:36.335 facebooktest[2690:f803] string christien.101012

下次登录时低于输出

 2013-01-16 13:56:42.747 facebooktest[2690:f803] *** Terminating app due to uncaught exception 'com.facebook.sdk:InvalidOperationException', reason: 'FBSession: an attempt was made to open an already opened or closed session'
*** First throw call stack:
(0x15ca052 0x175bd0a 0x15c9f11 0x1249f 0x3043 0x15cbec9 0x11b5c2 0x11b55a 0x1c0b76 0x1c103f 0x1c02fe 0x140a30 0x140c56 0x127384 0x11aaa9 0x14b4fa9 0x159e1c5 0x1503022 0x150190a 0x1500db4 0x1500ccb 0x14b3879 0x14b393e 0x118a9b 0x1e38 0x1d95 0x1)

和**有什么区别**

[FBSession.activeSession openWithBehavior:FBSessionLoginBehaviorForcingWebView

                        completionHandler:^(FBSession *session,

                                            FBSessionState state,

                                            NSError *error)

 [appDelegate.session openWithBehavior:FBSessionLoginBehaviorForcingWebView

                        completionHandler:^(FBSession *session,

                                            FBSessionState state,

                                            NSError *error) 

用简单的话来说appDelegate.sessionFBSession.activeSession因为如果我使用appDelegate.session它而不是它不会给我user.username并且不会崩溃......而且我第一次使用FBSession.activeSession它给了我user.username然后下次它崩溃..

4

0 回答 0