Facebook Developers
DocsToolsSupportNewsApps
Log In
  • Social Plugins
  • Facebook Login
  • Open Graph
  • Facebook APIs
  • Games
  • Media
  • Payments
  • App Center
  • Promote Your App
  • iOS
  • Android
  • Web
  • Technology Partners
  • Topics
    • Facebook SDK for iOS
  • Authentication
    • Using Facebook Login
    • Adding Facebook Login
    • iOS 6 Integration
    • Understanding Sessions
    • Handling App Links
  • Data Access
    • Fetch User Data
    • Run FQL Queries
  • Sharing & Distribution
    • Sharing on iOS
    • Publish to Feed
    • iOS Share Sheet
    • Feed Dialog
    • Link To Your Native App
    • Send Requests
    • Setup for App Center
  • Customization
    • Add Search to Friend Selector
    • Manage Your Own Token Cache
    • Share an App ID Across Apps
  • Optimization
    • Batch Requests
    • Caching
    • Select Friends by Device
    • Handling Errors

Share an App ID Across Apps

Documentation › Share an App ID Across Apps

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.


Step 1: Initiate a Session with the URL Scheme Suffix

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;
}

Step 2: Set Up Your Callback URL

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".

iOS Impl

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.


Step 3: Configure Distribution in the App Dashboard

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.

iOS Impl

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.

Updated about 5 months ago
Facebook © 2013 · English (US)
AboutAdvertisingCareersPlatform PoliciesPrivacy Policy