18

I'm using the latest facebook iOS SDK (supporting SSO) to connect my iPhone app with facebook. So far so good..

Since my current app is free with ads, I would like to create another version without ads (which i will charge for). I prefer not to use the in-app purchase approach.

The problem i'm facing is that with the facebook SSO, I need to bind the iOS application to a URL which is based on the facebook app ID. Since I have only one facebook app to be used by both of the iphone apps, the two iOS apps are binded to the same URL and therefore when both of them are installed on a device the callback from facebook to my app does not work (or opens the other app instead).

Is there a solution for that besides creating another facebook app dedicated to the new version of the iphone app?

Thanks.

Amir Naor
  • 2,236
  • 20
  • 27
  • Do either of your iOS apps need the URL callback? I've used the same AppID for several iOS apps and it has worked fine. – Joey Schluchter May 18 '11 at 01:25
  • In the latest facebook iOS SDK, every app must add the URL binding otherwise the login success message will never get to your app (SSO flow). – Amir Naor May 19 '11 at 09:14
  • You do not necessarily have to use that URL scheme in the FB iOS SDK. That's only what they recommend for their SSO and multitasking. I suggest you look at Facebook.m and see how they handle they auth passing. – Joey Schluchter May 19 '11 at 14:38
  • I'm aware I can disable the SSO by changing the SDK code to show the login dialog internally by default, but I wish to use the SSO approach in both of my apps. – Amir Naor May 20 '11 at 14:36

2 Answers2

29

I had to use FBLoginView in my app, and none of this solutions worked. The only missing thing was that i needed to add a new entry in the plist file: FacebookUrlSchemeSuffix (documented here, in the Step 2).

Suppose that your App ID is 123456, what i had to do was:

1) In your facebook app, add a URL Scheme Suffix in the iOS section:

enter image description here

2) In both of your applications, go to the app's .plist, and add the following entry:

enter image description here

Note that the Value must be one of the URL Scheme Suffixes added.

3) Also change your URL Scheme for Facebook in the .plist file to fb. For example, fb123456client

enter image description here

lucaslt89
  • 2,431
  • 1
  • 20
  • 30
27

In the latest Facebook iOS SDK on Github there's a method called authorize:delegate:localAppId: initWithAppId:urlSchemeSuffix:andDelegate:. You can use the localAppId urlSchemeSuffix parameter to distinguish multiple iOS Apps that use the same Facebook application id. The method documentation says:

urlSchemeSuffix is a string of lowercase letters that is appended to the base URL scheme used for SSO. For example, if your facebook ID is "350685531728" and you set urlSchemeSuffix to "abcd", the Facebook app will expect your application to bind to the following URL scheme: "fb350685531728abcd". This is useful if your have multiple iOS applications that share a single Facebook application id (for example, if you have a free and a paid version on the same app) and you want to use SSO with both apps. Giving both apps different urlSchemeSuffix values will allow the Facebook app to disambiguate their URL schemes and always redirect the user back to the correct app, even if both the free and the app is installed on the device.

urlSchemeSuffix is supported on version 3.4.1 and above of the Facebook app. If the user has an older version of the Facebook app installed and your app uses urlSchemeSuffix parameter, the SDK will proceed as if the Facebook app isn't installed on the device and redirect the user to Safari.

Community
  • 1
  • 1
Zargony
  • 9,615
  • 3
  • 44
  • 44
  • Didn't find method you mentioned. But I found "- (id)initWithAppId:(NSString *)appId urlSchemeSuffix:(NSString *)urlSchemeSuffix andDelegate:(id)delegate {" – Cullen SUN Jan 17 '12 at 05:32
  • Seems like they removed localAppId from authorize and added it as urlSchemeSuffix to an init method. I just updated my answer, thanks for the hint. – Zargony Jan 17 '12 at 11:05
  • 2
    I've had the same problem and (using this answer) I've solved it by setting: "fb40000000000006${PRODUCT_NAME}" as my URL scheme, and set the urlSchemeSuffix to the product name obtained as suggested here: http://stackoverflow.com/questions/1247142/getting-an-iphone-apps-product-name-at-runtime . This way, SSO binds correctly in apps that share same Facebook App Id, with no extra effort. – DannyA Jul 05 '12 at 08:27
  • Apparently my previous solution only works in the simulator. Anyone have any idea why? – DannyA Jul 10 '12 at 13:49
  • Ive gone through this process, and its launching the correct app, but the session always returns LoginFailed, even though it launch the permissions required page, and launched subsequent App. – Woodmister1 Feb 18 '13 at 12:32