Reputation: 14304
I'm having problems implementing this functionality after following Facebook's tutorial: https://developers.facebook.com/docs/howtos/share-appid-across-multiple-apps-ios-sdk/
Basically, I have 2 targets under the same project - one for the free version and one for the premium. I have created and set up a single Facebook app for this and added 2 url scheme suffixes:
Also, I've added the suffixes within the respective plist files. For example, the premium app is defined with:
Where the "xxxxx..." is just my Facebook app ID.
After all this, I still can't log in to the application on iOS 5.0 and 6.0 (using native FB dialog or the SDK dialog within Safari). This is what I get when I log in via Safari:
The code doing the login is:
NSArray *permissions = kInitialPermissions;
BOOL result = NO;
FBSession *session = [[FBSession alloc] initWithAppID:@"xxxxxxxxxxx"
permissions:@[]
urlSchemeSuffix:@"premium"
tokenCacheStrategy:nil];
if (allowLoginUI ||
(session.state == FBSessionStateCreatedTokenLoaded)) {
[FBSession setActiveSession:session];
}
result = [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:completion];
return result;
Any ideas will be appreciated. Thanks!
Upvotes: 11
Views: 4420
Reputation: 18922
As well as adding the fbxxxxxxxxxxpremium URL Scheme to the the URL Types array in the plist file (which you seem to be doing), add a new key/value:
key = FacebookUrlSchemeSuffix
value = premium
So in the plist file itself:
<key>FacebookUrlSchemeSuffix</key>
<string>premium</string>
This fixed it for me. The Facebook docs make reference to this but don't make it clear IMO.
Upvotes: 1
Reputation: 66242
Your issue is that the custom URL scheme is not being recognized by iOS. Here are some possible causes:
I see that you've correctly set the CFBundleURLSchemes
key in your plist to an array of supported schemes. You also need to set CFBundleURLName
to something like com.myApp.MyURLScheme. Have you done this?
After calling will and did finish launching methods, iOS will call your app delegate's - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
method. You must also implement this method and it must return YES
. Have you?
Make sure your URL format is correct. fbxxxxxxpremium://foo=bar
won't work, but fbxxxxxxpremium://?foo=bar
will (the ?
is mandatory).
Please note that the delegate methods will be slightly different if you are targeting iOS 4.1 or earlier.
For more info and sample code, see the Communicating with Other Apps section of Advanced App Tricks in the iOS SDK documentation.
Upvotes: 0
Reputation: 4212
I think the problem is when you're calling :
result = [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:completion];
the session that is being opened doesn't have the url scheme suffix.
So you should call
[session openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:completion];
Upvotes: 0