Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restoring sessions not working #5

Closed
lauraskelton opened this issue Aug 17, 2010 · 15 comments
Closed

Restoring sessions not working #5

lauraskelton opened this issue Aug 17, 2010 · 15 comments

Comments

@lauraskelton
Copy link

Everything is working great when I first run my app (or when I run the Run Around sample app). I can log in and publish to stream.

However, when I close the app, then reopen (having stored the session information in NSUserDefaults as in the Run Around example), then I try to publish to stream, the dialog just displays the message "An error occurred with . Please try again later." (I checked and the session expiration date is a long way off, and all of the session variables seem to have been stored + restored properly).

This happens both in my app and in the Run Around sample app when I close them, storing session info, and then open them again and try to run publishStream. Is there a working way to restore a session that you could give example code for? It's pretty important for my app.

Thanks!

@yujuan
Copy link

yujuan commented Aug 17, 2010

Thanks for your report. We know this issue and the reason is that when the app is restarted, though we had save the correct access token, but the cookie for the webview dialog is not kept. We are working on a way to resolve that. Thanks

@lauraskelton
Copy link
Author

OK, well I hope it gets fixed. Here's my workaround method that seems to be working (with the general setup used in the Run Around example) if anyone else is trying to do this-

in viewDidLoad:

_permissions =  [[NSArray arrayWithObjects: 
                  @"publish_stream",@"read_stream",@"offline_access",nil] retain];

_session = [[Session alloc] init];
_facebook = [[_session restore] retain];

if (_facebook == nil) {
    _facebook = [[[[Facebook alloc] init] autorelease] retain];
} else {

    NSData *cookiesdata = [[NSUserDefaults standardUserDefaults] objectForKey:@"FBCookies"];

    NSArray *cookies = [NSKeyedUnarchiver unarchiveObjectWithData:cookiesdata];

    NSHTTPCookie *cookie;
    for (cookie in cookies) {
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
    }
}

in userInfoDidLoad:

[_session setSessionWithFacebook:_facebook andUid:_userInfo.uid];
[_session save];

NSData *cookiesdata = [NSKeyedArchiver archivedDataWithRootObject:[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]];

[[NSUserDefaults standardUserDefaults] setObject:cookiesdata forKey:@"FBCookies"];

@shawnwall
Copy link

I just ran into this same issue, thanks for the workaround.

edit - couldn't get the workaround working. issue still persists. i may just go back to the facebook-iphone-sdk as it was 100x simpler to use.

@jessearmand
Copy link

For this issue, it turns out to be much simpler to just store the access token string and expiration date with NSUserDefaults. Then, restore it when we want to use it again by invoking the method in Facebook class isSessionValid.

@yujuan
Copy link

yujuan commented Aug 20, 2010

Preserve and reset the cookie is not recommend way. I just make a server side change which will accept a persistent cookie. Now this issue should be resolved.

@lauraskelton
Copy link
Author

It still gives me the same error unless I store the cookies in NSUserDefaults along with the access token and expiration date.

@yujuan
Copy link

yujuan commented Aug 20, 2010

Can you try theRunAround again and see if this is still the case?

@lauraskelton
Copy link
Author

It's still happening in theRunAround. If I log in, post something, then completely quit the app (not just make it in the background in iOS 4), then open the app again and try to post, I get the error "An error occurred with -MyFacebookApp-. Please try again later."

@yujuan
Copy link

yujuan commented Aug 20, 2010

You can first try on ios 3.2 by changing the base sdk. For iOs4, if you are using simulator, boot from xcode, it will reinstall the app again and the persistent cookie would not be there. let me know thx.

@lauraskelton
Copy link
Author

OK it seems to be working now, thanks!

@yujuan
Copy link

yujuan commented Aug 20, 2010

Cool!

@lauraskelton
Copy link
Author

I think I spoke too soon- I am using the Simulator so I don't know if this is an issue with the phone as well, but if I log in, quit the simulator (4.0), then start the simulator (not booting from xcode), and open theRunAround app again, I still get the error. I can't test on a phone though to see if you turn the phone off and back on if it would give the error but it's something you might want to check.

@yujuan
Copy link

yujuan commented Aug 20, 2010

I use the 4.0 simulator also and did not see this repro.. it works for me. Just in case, I have some minor fix recently, you have been updating for that is that correct? if yes you can also try the app id 230820755197 for the runAround?

@lauraskelton
Copy link
Author

I updated the files, and it works for app id 230820755197, but not for the app id for my app... do you know what could be happening? my app id is 115402728275

@lauraskelton
Copy link
Author

Well now it looks like it's working again, so hopefully it will stay that way!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants