2014-10-18 4 views
0

iOS의 Facebook SDK에 문제가 있습니다. 모든 것이 완벽하게 작동하지만 로그인 흐름에 문제가 있습니다. 사용자가 "Facebook에 로그인"버튼을 클릭하면 내 앱이 권한을 얻을 수 있도록 Facebook에 연결됩니다. 괜찮아. 그러나 아이폰 OS 내 앱에 브라우저에서 변경하고 나는이 오류 메시지가 요청을 만들려고 할 때 :앱이 포 그라운드로 입장 한 후 Facebook 요청

나는 응용 프로그램을 닫고 다시 시작하고 가서이없이 작동 나의 요청을 실행하고있어
FBSDKLog: Error for request to endpoint 'search?q=concert&type=event&limit=10': An open FBSession must be specified for calls to this endpoint. 

오류. 나는 내 힘을 얻는다. 그게 내 코드인데, 나는 그 코드가 아주 산뜻하지 않다는 것을 안다.

의 viewDidLoad :

- (void)viewDidLoad { 
[super viewDidLoad]; 


    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; 

//Some other Code 



if ([[FBSession activeSession]state]) 
{ 
    NSLog(@"User is logged in"); 
    [loginView setHidden:TRUE]; 


} else { 
    // try to open session with existing valid token 
    NSArray *permissions = [[NSArray alloc] initWithObjects: 
          @"user_events", 
          nil]; 
    FBSession *session = [[FBSession alloc] initWithPermissions:permissions]; 
    [FBSession setActiveSession:session]; 
    if([FBSession openActiveSessionWithAllowLoginUI:NO]) { 

    } else { 
     NSLog(@"User is logged out"); 

     //Create the FB Login-Button 
     loginView = [[FBLoginView alloc] initWithReadPermissions:@[@"user_events"]]; 
     // Align the button in the center horizontally 
     loginView.frame = CGRectOffset(loginView.frame, (self.view.center.x - (loginView.frame.size.width/2)), 200); 

     [self.view addSubview:loginView]; 


    } 
} 

[self getEvents]; 

} 

getEvents는 :

-(void)getEvents{ 
//Get General Events 



[FBRequestConnection startWithGraphPath:@"search?q=concert&type=event&limit=10" 
         completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 


          if (!error) { 
            //Some Code 

          else { 
           // An error occurred, we need to handle the error 
           // See: https://developers.facebook.com/docs/ios/errors 

          } 

         }]; 


    } 

는 appDidEnterForeground

- (void)appDidEnterForeground:(NSNotification *)notification { 
NSLog(@"App did enter forground again."); 


[self viewDidLoad]; 

}

답변

0

좋아, 난 내 자신의 문제를 해결 아니라 : 나는 다시 문서를 읽어 이자형 (FBLoginView * : (무효) loginViewShowingLoggedInUser - 그럼 미안 내 같은 요청이

// Logged-in user experience 

이 포함되어 내 방법을 실행

// Whenever a person opens the app, check for a cached session 
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) { 

    // If there's one, just open the session silently, without showing the user the login UI 
    [FBSession openActiveSessionWithReadPermissions:@[@"public_profile"] 
             allowLoginUI:NO 
            completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { 
             // Handler for session state changes 
             // This method will be called EACH time the session state changes, 
             // also for intermediate states and NOT just when the session open 
             [self sessionStateChanged:session state:state error:error]; 
            }]; 



} 

} 



// This method will handle ALL the session state changes in the app 


-(void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error: (NSError *)error 
    { 
     // If the session was opened successfully 
    // customize your code... 

    } 

과 : xtremely 조심스럽게 다시 모든 것을했다, 내 대리인에게이 추가) loginView { NSLog (@ "로그인하셨습니다 (방법 : loginviewshowingloggedinuser");

//If the User is logged in we can fetch the events 
[self getEvents]; 

}

관련 문제