Facebook SDK 3.5 for iOS introduces improved handling of incoming links to your app from the Facebook for iOS app. FBAppCall
is a class that helps apps make and respond to cross-app calls in the iOS environment. On iOS, one application calls another using a URL to open the other app; this calls the receiving app's handleOpenURL
call. When the receiving app has finished executing, it returns to the calling app by passing another URL back to the calling app's handleOpenURL
call. This mechanism is used to make cross-app calls between your app and the Facebook for iOS app, ex:
In both of these cases, your app should use FBAppCall
when you override handleOpenURL
in your app delegate. FBAppCall
will recognize these URLs and help you process them. Unrecognized URLs are ignored and left alone for your app to process. Here's a simple example that lets you handle deep links and Facebook Login:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
BOOL urlWasHandled = [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
fallbackHandler:^(FBAppCall *call) {
// handle deep links and responses for Login or Share Dialog here
}];
return urlWasHandled;
}
If your app uses Facebook Login and is responding to a successful URL that marks completion of the Facebook Login flow, this will set an open FBSession
instance at [FBSession activeSession]
. The access token and other login related data can be read using:
[call accessTokenData];
For more details, see FBAccessTokenData;
If your app is responding to a deep link, the deep link's properties and raw URL are available from FBAppLinkData
. The target_url
can be read using:
[[call appLinkData] targetURL];
The raw query parameters can be read using:
[[call appLinkData] rawParameters];
For more details, see FBAppLinkData;
When your app is called after showing the Share Dialog, the response data can be read using:
[call dialogData];
For more details, see FBDialogsData.
In all cases, errors detected by FBAppCall
can be detected by reading:
[call error];
For more details, see FBAppLink;