Facebook iOS SDK 3.0 - session not open
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];
}
Related videos on Youtube
Comments
-
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 secondNSLog
indicate that thesession
state isFBSessionStateCreated
notFBSessionStateOpen
?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 over 11 yearsthnx for your answer I will try it ,,, but is the different between using
FBSession
and instance ofFBSession
class? -
meth over 11 yearshave you got a - (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
-
MohamMad Salah over 11 yearsYes I have one in the
ViewController
class but it never get called, do you know why? -
meth over 11 yearsit should be in the appdelegate. because you define the session in appdelegate.
-
meth over 11 yearsok. did you make request. can you get any information about session.
-
MohamMad Salah over 11 yearsI don't know what do you mean with request, my current session state is
FBSessionStateOpen
,,, note that these operation done inViewController
-
meth over 11 yearssorry for misunderstanding. i am checking whether the session is opened or not with NSLog(@"%d", FBSession.activeSession.isOpen); it prints 1.
-
meth over 11 yearsi guess after creating the session it makes the session active. and you can check it with this code. i edited my code
-
Moritz over 11 years[session facebookSession handleOpenURL:url] is syntactically not correct.
-
Christien about 11 years@meth can u take a look at this stackoverflow.com/questions/14414118/…
-
Katedral Pillon about 9 yearsIs this answer outdated? There seems to be no such method now.