You can use one Facebook app ID in multiple iOS apps. One scenario where you could do this is if you have a free and paid version of your iOS app.
This article walks you through how to configure multiple apps with one ID. Before you start, run through the iOS tutorial and set up Facebook Login.
Facebook allows you to define a URL Scheme Suffix parameter, urlSchemeSuffix
, that you can pass into the initWithAppID:permissions:urlSchemeSuffix:tokenCacheStrategy:
method in the FBSession
class. This modifies the outgoing authentication calls to include the suffix information. When authentication takes place, the Facebook app will try and return control to your app. Set up the Facebook Login callback URL to include this suffix information, so the correct app opens.
Note: The URL Scheme Suffix must be lowercase and contain only letters.
Let's define a URL Scheme Suffix named ''foo'' that we will use for illustration purposes. When calling the initWithAppId:urlSchemeSuffix:andDelegate:
method, pass in the URL Scheme Suffix, ''foo''.
If you followed the Facebook Login doc, you should have a openSessionWithAllowLoginUI:
method defined in your app delegate implementation file. Open the app delegate implementation file and modify the code to pass in the URL Scheme Suffix info:
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI { BOOL result = NO; FBSession *session = [[FBSession alloc] initWithAppID:nil permissions:nil urlSchemeSuffix:@"foo" tokenCacheStrategy:nil]; if (allowLoginUI || (session.state == FBSessionStateCreatedTokenLoaded)) { [FBSession setActiveSession:session]; [session openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent completionHandler: ^(FBSession *session, FBSessionState state, NSError *error) { [self sessionStateChanged:session state:state error:error]; }]; result = session.isOpen; } return result; }
The default Facebook Login setup results in fbYOUR_APP_ID as the entry for the URL Scheme Suffix fbYOUR_APP_ID. Modify the URL Schemes entry from fbYOUR_APP_ID to fbYOUR_APP_IDYOUR_URL_SCHEME_SUFFIX (the literal characters fb, followed by your app ID and URL Scheme Suffix). For example, if your app ID is "1234", your new URL should be "fb1234foo".
Build and run the app to make sure the Login with Facebook flow works correctly. That's all you have to do to support Facebook Login from multiple iOS apps with one app ID.
When you've properly set up and configured Facebook Login, you can get Facebook distribution to your iOS app. If you have multiple apps with one Facebook app ID, you'll need to add a configuration to the App Dashboard to list the URL Scheme Suffix information for the apps that share the ID.
The order in which you list the suffixes determines the order that the Facebook app searches for the installed app when linking to your app. For example, if you list two URL Scheme Suffix entries, ''freeapp'' (for your free app) and ''paidapp'' (for your paid app), the Facebook app will look for the free app first, followed by the paid app.