2013-08-20 63 views
0

我正在使用「圖形API」爲Facebook登錄與我的應用程序。我成功地登錄和使用此代碼如何檢查是否已經在ios上登錄Facebook?

facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:self.viewController]; 

註銷,並使用我下面的代碼已經在

if (![facebook isSessionValid]) { 

    [facebook authorize:permissions ]; 
} 

我的問題是登錄Facebook我安裝的Facebook應用程序,我通過Facebook應用程序登錄。然後我運行我的應用程序,它再次要求登錄Facebook。我如何解決這個問題。它應該採用默認的FB應用程序登錄憑據。我看到很多使用此功能的應用程序。任何人都知道解決方案

回答

2
1. In your AppDelegate.m file 

define NSString *const FBSessionStateChangedNotification = 
      @"com.example:FBSessionStateChangedNotification"; 
replace com.example with your bundle identifier name 

2.- In method 
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [FBSession setActiveSession:[FBSession new]]; 
    if ([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded) 
    { 
     // means u are already logged in 
     //do ur code 
     [self openSessionWithAllowLoginUI:NO]; 
    } 
    else 
    {  //do ur code 
      [self openSessionWithAllowLoginUI:YES]; 
    } 
} 
3. whenenever and wherever this method is called after end of switch case write 
    - (void)sessionStateChanged:(FBSession *)session 
         state:(FBSessionState) state 
         error:(NSError *)error 
{ 

[[NSNotificationCenter defaultCenter] 
    postNotificationName:FBSessionStateChangedNotification 
    object:session]; 
} 

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI 
{ 
    return [FBSession openActiveSessionWithReadPermissions:@"email" 
               allowLoginUI:allowLoginUI 
             completionHandler:^(FBSession *session,  FBSessionState state, NSError *error) 
      { 
       [self sessionStateChanged:session state:state error:error]; 
      }]; 
} 

Sorry in your appDelegate.h file it should be 
extern NSString *const FBSessionStateChangedNotification; 
+0

我沒有FBSession類。我有Facebook.h和Facebook.m和Facebook.h它有FBSessionDelegate協議有 – banu

+0

朋友我從來沒有使用這個類,它是更好地添加Facebook的SDK框架,並做它它有更多的功能也 –

+0

和我的問題,我已經通過Facebook App登錄Facebook。不在我的應用程序。所以我需要找到已經登錄並使用該憑據。 – banu

相關問題