使用SSO facebook的故事链接流-未调用openURL [英] Story link flow using SSO facebook - openURL not being called

查看:139
本文介绍了使用SSO facebook的故事链接流-未调用openURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的iOS 4.3应用程序中成功实现了单点登录.现在,我想发布一个指向用户facebook墙的链接,以便当他/她同时拥有该应用程序的朋友单击该链接时,他们应该重定向到我的应用程序.我解释 http://developers.facebook.com/docs/mobile/ios/build/#deeplink ,是委托函数之一

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+)

将被调用,并且可以从[target_link]键中解析共享链接.但是,我无法使它正常工作.我成功使用以下方法将链接发布到用户新闻提要:

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]

该帖子出现在我的新闻提要中,但是当我单击链接时,不会调用上述任何委托方法.如果我对链接做一些特殊的事情,我尝试在链接前面添加"fb:myFacebookAppID://",但这根本不起作用.我误会了吗?

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?

我的应用程序尚未在AppStore上运行,并且在developers.facebook.com上有一个字段,要求我输入我的AppStore ID,这可能是问题吗?如果是这样,是否有任何解决方法?在将我的应用发送到AppStore之前,我想测试一下是否可以正常工作.

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.

谢谢您的帮助!

推荐答案

您需要在AppDelegate中拥有您的Facebook实例,例如:

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

在AppDelegate内部,您必须实现:

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

如果您想在自己的课程中实现协议,则必须在此调用facebook:

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

这篇关于使用SSO facebook的故事链接流-未调用openURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆