Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems migrating from Facebook iOS SDK 2.x to 3.x

Tags:

ios

facebook

sdk

We want to upgrade to 3.x so our users on iOS 6 / iPhone 5 will have the most streamlined FB experience possible... given that, am I facing a FB integration rewrite, or is it possible for me to use the depreciated headers and continue to use the 2.x APIs with the 3.1 SDK?

Some of the key methods and requests we're relying on are: [ad.facebook authorize:perms], shouldExtendAccessToken, extendAccessTokenIfNeeded, isSessionValid, dialog:@"feed" andParams:params andDelegate:delegate, "https://graph.facebook.com/me?fields=id,email,first_name&access_token=", et.al. Some searches in the 3.1 sample projects makes it look like all of these have been replaced — and I would imagine it's not just name changes.

I haven't found a 2.x to 3.x version of this Upgrading from 3.0 to 3.1 — if I've overlooked that, please advise.

When previously trying to upgrade to 3.0 recently, I ran into significant breakages (duplicate SBJson headers, non resolving FB headers) when trying to use the depreciated APIs, and once it compiled, handleOpenURL seemed broken and it would re-switch over to FB a 2nd time, then crash. And I've come across postings that indicate there could be issues with disabling 3.x's ARC (we can't use it as we have C++).

I haven't embarked on 2.x to 3.1. Perhaps that would go smoother, but I'd love to gain some insight from those who have gone before me before a 2nd lengthy at-bat — thanks so much.

like image 874
leontx Avatar asked Oct 02 '12 03:10

leontx


2 Answers

I just recently did this upgrade for my app. My reason for doing it was smoother flow for iOS 6 and future support for facebook since they are going to eventually deprecate the old sdk. The big changes were login flow and open graph calls. The dialog calls for posting on your wall still piggy back off the deprecated headers. For the methods you are interested in they would be replaced as follows:

[ad.facebook authorize:perms]

FBSession *session = [[FBSession alloc] initWithAppID:appId
                                permissions:permissionsArray
                            urlSchemeSuffix:urlSuffix
                         tokenCacheStrategy:nil];

[FBSession setActiveSession:session];
if(allowLoginUI == YES)
{
    [session openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent completionHandler:handler];
}
else if(session.state == FBSessionStateCreatedTokenLoaded)
{
    [session openWithCompletionHandler:^(FBSession *_session, FBSessionState status, NSError *error) {
        [self _sessionStateChanged:_session state:status error:error];            
    }];
}
[session release];

see for additional implementation instructions on login
https://developers.facebook.com/docs/howtos/share-appid-across-multiple-apps-ios-sdk/
https://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/

shouldExtendAccessToken, extendAccessTokenIfNeeded, - these are now gone and the facebook SDK implements the caching and extending the token if needed. If you see up in my first code snippit if the loginUI is not supposed to show, but the session state was in FBSessionStateCreatedTokenLoaded, you still want to open the session. When your session is in the state FBSessionStateCreatedTokenLoaded it means:

One of two initial session states indicating that a cached token was loaded; when a session is in this state, a call to open* will result in an open session, without UX or app-switching

checkout the SessionLoginSample for more info.

isSessionValid - this is now

FBSession.activeSession.isOpen

dialog:@"feed" andParams:params andDelegate:delegate - this is still the same, however you have to create the facebook instance like this before using it:

Facebook *facebook = [[Facebook alloc] initWithAppId:FBSession.activeSession.appID andDelegate:nil];
facebook.accessToken = FBSession.activeSession.accessToken;
facebook.expirationDate = FBSession.activeSession.expirationDate;
//... normal code to setup a feed post
[facebook dialog:@"feed" andParams:params andDelegate:self];
[facebook release];

see https://developers.facebook.com/docs/howtos/feed-dialog-using-ios-sdk/ for more info

"https://graph.facebook.com/me?fields=id,email,first_name&access_token=", - The graph calls are a lot simpler now. You can also batch them together pretty easily as well.

//[facebook requestWithGraphPath:@"me" andDelegate:self]; would become
[FBRequestConnection startForMeWithCompletionHandler:^
     (FBRequestConnection *connection, id result, NSError *error)   {}];

//[facebook requestWithGraphPath:@"me/albums" andParams:params andHttpMethod:@"POST" andDelegate:self]; would become
  [FBRequestConnection startWithGraphPath:@"me/albums"
                             parameters:params
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {}];

see https://developers.facebook.com/docs/howtos/batch-requests-ios-sdk/ for more info

like image 141
odyth Avatar answered Oct 08 '22 23:10

odyth


I'm about to do the same thing, and I found this article "Upgrading from 2.0 to 3.1" on Facebook's docs:

https://developers.facebook.com/docs/tutorial/iossdk/upgrading-from-2.0-to-3.1/

like image 21
humphriesj Avatar answered Oct 08 '22 22:10

humphriesj