我已成功在iOS 4.3应用中实施单点登录。现在我想发布一个指向用户Facebook墙的链接,这样当他/她的朋友也拥有该应用程序点击链接时,他们应该被重定向到我的应用程序。我解释http://developers.facebook.com/docs/mobile/ios/build/#deeplink的方式是委托函数之一
- (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]键解析共享链接。但是,我无法让这个工作。我使用以下方法成功发布了指向用户新闻Feed的链接:
NSDictionary* params=[[NSDictionary alloc] initWithObjectsAndKeys:myFacebookAppID,@"app_id",
linkToPost,@"link",nil];
[_facebook dialog:@"feed" andParams:params andDelegate:self]
帖子出现在我的新闻Feed中,但是当我点击链接时,没有调用上面提到的任何委托方法。我应该对链接做一些特别的事情,我尝试在链接前添加“fb:myFacebookAppID://”,但这根本不起作用。我误解了什么吗?
我的应用程序尚未在AppStore上运行,并且在developers.facebook.com上有一个字段,我被要求输入我的AppStore ID,这可能是问题吗?如果是这样,有没有解决方法?我想在将我的应用程序发送到AppStore之前测试它是否正常工作。
感谢您的帮助!
答案 0 :(得分:4)
您需要在AppDelegate中设置您的facebook,例如:
@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中你必须实现:
- (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:
FacebookAppDelegate *fbAppDelegate = (FacebookAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *permissions = [[NSArray alloc] initWithObjects:@"publish_stream",@"create_event",@"offline_access", nil];
[[fbAppDelegate facebook] authorize:permissions];