I have implemented Single-Sign-On in my iOS 4.3 app successfully. Now I want to publish a link to the users facebook wall so that when his/her friends that also own the app clicks the link they should be redirected to my app. The way I interpret http://developers.facebook.com/docs/mobile/ios/build/#deeplink , is that one of the delegate functions
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url, (pre iOS 4.2)
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation , (iOS 4.2+)
will be called and that the shared link can be parsed from the [target_link] key. However, I can't get this to work. I successfully post my link to the users news feed using:
NSDictionary* params=[[NSDictionary alloc] initWithObjectsAndKeys:myFacebookAppID,@"app_id",
linkToPost,@"link",nil];
[_facebook dialog:@"feed" andParams:params andDelegate:self]
The post appear on my news feed but when i click the link none of the delegate methods mentioned above is being called. Should I do something special with the link, I have tried adding "fb:myFacebookAppID://" in front of the link but that doesn't work at all. Have I misunderstood something?
My app is not yet live on AppStore and there is a field on developers.facebook.com where I am asked to enter my AppStore ID, could this be the problem? If so, is there any workaround? I want to test that this works as it should before sending my app to AppStore.
Thank you for your help!
You need to have your facebook instace in AppDelegate for example:
@interface FacebookAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController;
@property (nonatomic, strong) Facebook *facebook;
@end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[FacebookViewController alloc] initWithNibName:@"FacebookViewController" bundle:nil];
self.facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:(id)self.viewController];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
self.facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
self.facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
And inside AppDelegate you have to implement:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [self.facebook handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [self.facebook handleOpenURL:url];
}
And if you want to implement protocol in your own class you have to call facebook on this:
FacebookAppDelegate *fbAppDelegate = (FacebookAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *permissions = [[NSArray alloc] initWithObjects:@"publish_stream",@"create_event",@"offline_access", nil];
[[fbAppDelegate facebook] authorize:permissions];