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];
}