이 작업을하는 데 가장 힘든 시간을 보내고 있습니다. IOS 앱이 있는데 Facebook SDK 3.1
에 통합하려고합니다. 사용자가 토큰을 캐싱하고 있다면 페이스 북에 로그인하도록 선택할 수 있습니다. 반환 된 토큰 만료 날짜는 몇 주 전이며 로그인/로그 아웃이 제대로 작동하고 전경으로 돌아갑니다. 그러나 앱을 종료 할 때마다 FBSession
은 유지되지 않습니다. 응용 프로그램이 다시 시작될 때 응용 프로그램 대리인이 [self openSessionWithAllowLoginUI:NO]
을 수행하고 세션을 새로 고치려고 시도하기 때문에이 사실을 알고 있습니다. 그러나 항상 null을 반환합니다. 나는 다른 튜토리얼과 다른 게시물을 따라 왔고 내가 애플 리케이션 델리게이트에서 내가 뭘 잘못하고있는 것처럼 보이지 않는 것 같다.앱을 닫을 때 IOS가 FBSession을 잃습니다.
나는 왜 내가이 세션을 앱을 닫을 때 잃어 버리고 있는지에 대해 벽에 머리를 치고있다. appDelegate를 첨부했습니다.
#import "AppDelegate.h"
@implementation AppDelegate
NSString *const [email protected]"ro.Tag:FBSessionStateChangedNotification";
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self openSessionWithAllowLoginUI:NO];
NSLog(@"%@",[[FBSession activeSession] accessToken]);
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.
// We need to properly handle activation of the application with regards to SSO
// (e.g., returning from iOS 6.0 authorization dialog or from fast app switching).
[FBSession.activeSession handleDidBecomeActive];
}
/*
* Callback for session changes.
*/
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
if (!error) {
// We have a valid session
NSLog(@"User session found");
NSLog(@"session %@",session);
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
[[NSNotificationCenter defaultCenter]
postNotificationName:FBSessionStateChangedNotification
object:session];
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
/*
* Opens a Facebook session and optionally shows the login UX.
*/
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"email",
@"user_games_activity",
@"user_location",
@"user_likes",
@"user_birthday",
nil];
//NSLog(@"permissions: %@",permissions);
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
/*
* If we have a valid session at the time of openURL call, we handle
* Facebook transitions by passing the url argument to handleOpenURL
*/
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBSession.activeSession handleOpenURL:url];
}
/*
*Logout
*
*/
- (void) closeSession {
[FBSession.activeSession closeAndClearTokenInformation];
}
@end
openSessionWithAllowLoginUI에서 오류를 인쇄 해 보았습니까? 오류가 생길 수 있습니다. – meth
Facebook iOS SDK 3.2 (.1)를 사용해보십시오. 3.2 업데이트에는 토큰 저장 및 기타 인증 흐름 문제와 관련된 버그가 수정되어 있습니다. – cbowns