Search code examples
iosunit-testingfacebook-ios-sdkfacebook-test-users

How to set FBPLISTAppIDKey and FBPLISTAppSecretKey with FBTestSession


I am getting an exception using FBTestSession when using FBTestSession *fbSession = [FBTestSession sessionWithSharedUserWithPermissions:@[@"email"]];

If you look at the code below you can see Facebook decided to load app settings from NSProcessInfo: https://github.com/facebook/facebook-ios-sdk/blob/master/src/FBTestSession.m#L506

NSDictionary *environment = [[NSProcessInfo processInfo] environment];
    NSString *appID = [environment objectForKey:FBPLISTAppIDKey];
    NSString *appSecret = [environment objectForKey:FBPLISTAppSecretKey];
    if (!appID || !appSecret || appID.length == 0 || appSecret.length == 0) {
        [[NSException exceptionWithName:FBInvalidOperationException
                                 reason:
          @"FBTestSession: Missing App ID or Secret; ensure that you have an .xcconfig file at:\n"
          @"\t${REPO_ROOT}/src/tests/TestAppIdAndSecret.xcconfig\n"
          @"containing your unit-testing Facebook Application's ID and Secret in this format:\n"
          @"\tIOS_SDK_TEST_APP_ID = // your app ID, e.g.: 1234567890\n"
          @"\tIOS_SDK_TEST_APP_SECRET = // your app secret, e.g.: 1234567890abcdef\n"
          @"To create a Facebook AppID, visit https://developers.facebook.com/apps"
                               userInfo:nil]
         raise];
    }

The problem is, I'm not able to figure out how to set FBPLISTAppIDKey and FBPLISTAppSecretKey correctly and there is no other setter to use.


Solution

  • You need to add them as environment variables in your scheme.

    {scheme} >> Run >> Arguments (Tab) >> add the test app id and test app secret.