Facebook iOS SDK 3.0 - session not open

11,074

Solution 1

i used this framework for my project. it works properly. this is my related code

   -(IBAction)logIn:(id)sender;
{
    AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    if (!FBSession.activeSession.isOpen) {
        [appdelegate sessionOpener];
    }
    else {
        [self loginHelp];
    }

and my sessionOpener function is;

    -(void) sessionOpener
{

    [FBSession sessionOpenWithPermissions:nil
                        completionHandler:^(FBSession *session,
                                            FBSessionState status,
                                            NSError *error) {
                            // session might now be open.
                            if (!error) {
                                [self.viewController loginHelp];
                            }
                        }];

     NSLog(@"%d", FBSession.activeSession.isOpen);
    NSLog(@"%@", FBSession.activeSession.description );
}

it works for me. may be helpful to you.

and my console print is:

     1
2012-08-16 22:24:55.899 TaraftarlikOyunu[838:c07] <FBSession: 0xd2512c0, state: FBSessionStateOpen, loginHandler: 0xd250240, appID: 433294056715040, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xd24fda0>, expirationDate: 2012-10-15 19:02:34 +0000, refreshDate: 2012-08-16 19:05:03 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
    )>

Solution 2

I had the same problem as you and I had mixed between using FBSession and instance of FBSession when calling handleOpenURL. I changed from

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {
    [FBSession.activeSession facebookSession handleOpenURL:url];
}

to this

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {
    [session facebookSession handleOpenURL:url];
}
Share:
11,074

Related videos on Youtube

MohamMad Salah
Author by

MohamMad Salah

iOS &amp; Unity3D

Updated on October 19, 2022

Comments

  • MohamMad Salah
    MohamMad Salah over 1 year

    I am using the latest Facebook iOS SDK 3.0

    I need a help in in the login process:

    First I declare this property in AppDelegate.h:

    @property (nonatomic, strong) FBSession *session;
    

    and in ViewController class I get this to use it in the code as this:

    AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
    [delegate.session someproperty];
    

    I also have this method in ViewController that get called from viewDidLoad:

    -(void)login
    {
        AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
        [delegate.session accessToken];
        NSLog(@"%d",delegate.session.isOpen);
        if (!delegate.session.isOpen)
        {
            delegate.session = [[FBSession alloc] init];
            if (delegate.session.state == FBSessionStateCreatedTokenLoaded)
            {
                [delegate.session openWithCompletionHandler:^(FBSession *session,
                                                          FBSessionState status,
                                                          NSError *error) 
                {
                  NSLog(@"%d", delegate.session.isOpen); // First Line //////////////////
                }];
            }
            NSLog(@"%@", delegate.session.description);   // Second Line //////////////////
        }
     }
    

    After the facebook app get authorized the firs NSLog print zero, and the second NSLog indicate that the session state is FBSessionStateCreated not FBSessionStateOpen?

    this is the output for the second NSLog:

    2012-08-16 18:37:24.327 Facebook3[2418:f803] <FBSession: 0x6890ff0, state:    FBSessionStateCreated, loginHandler: 0x0, appID: 193716877424306, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x6890f20>, expirationDate: (null), refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:()>
    

    What I am missing here.

    Note : in the app setting at https://developers.facebook.com I configure the app as this: 1- Configured for iOS SSO: Enabled 2- iOS Native Deep Linking: Enabled 3- iOS Bundle ID : com.mycompany.appname

  • MohamMad Salah
    MohamMad Salah over 11 years
    thnx for your answer I will try it ,,, but is the different between using FBSession and instance of FBSession class?
  • meth
    meth over 11 years
    have you got a - (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
  • MohamMad Salah
    MohamMad Salah over 11 years
    Yes I have one in the ViewController class but it never get called, do you know why?
  • meth
    meth over 11 years
    it should be in the appdelegate. because you define the session in appdelegate.
  • meth
    meth over 11 years
    ok. did you make request. can you get any information about session.
  • MohamMad Salah
    MohamMad Salah over 11 years
    I don't know what do you mean with request, my current session state is FBSessionStateOpen ,,, note that these operation done in ViewController
  • meth
    meth over 11 years
    sorry for misunderstanding. i am checking whether the session is opened or not with NSLog(@"%d", FBSession.activeSession.isOpen); it prints 1.
  • meth
    meth over 11 years
    i guess after creating the session it makes the session active. and you can check it with this code. i edited my code
  • Moritz
    Moritz over 11 years
    [session facebookSession handleOpenURL:url] is syntactically not correct.
  • Christien
    Christien about 11 years
    @meth can u take a look at this stackoverflow.com/questions/14414118/…
  • Katedral Pillon
    Katedral Pillon about 9 years
    Is this answer outdated? There seems to be no such method now.