Facebook的iOS SDK的Xcode 4.3 /故事板

我一直在看教程几个星期了,没有能够find任何在iOS中实现FB的故事板的例子。

我有我的应用程序打开FBloginscreen,请求用户authentication的应用程序,然后返回到应用程序…像一些其他用户,fbdidlogin和handleopenurl方法不会被调用。 我相信我做错了什么,但不知道是什么。 我在故事板中使用默认的视图控制器(我没有编程创build一个VC),所以我可能需要做的事情。

从我理解的handleopenurl方法需要在我的应用程序的delegate.m文件,而不是在我的视图controller.m文件,但我不知道它应该如何写,以及如何连接一个UIViewController对象,我创build到VC我的故事板(与我使用的button和标签的故事板)。

ViewController.h (relevant to FB) #import "FBConnect.h" @interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, FBSessionDelegate, FBDialogDelegate> { Facebook *facebook; } @property (nonatomic,retain) Facebook *facebook;' 

 ViewController.m (relevant to FB) #import "ViewController.h" @implementation ViewController; @synthesize facebook; -(void)LogintoFB { facebook = [[Facebook alloc] initWithAppId:@"345872345487883" andDelegate:self]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) { facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; } if (![facebook isSessionValid]) { [facebook authorize:nil]; NSLog(@"did log in"); } } // Pre iOS 4.2 support - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { NSLog(@"-4.2 got calleld"); return [facebook handleOpenURL:url]; } // For iOS 4.2+ support - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { NSLog(@"4.2+ got called"); return [facebook handleOpenURL:url]; } } - (void)fbDidLogin { NSLog(@"fbDidLogin"); NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"]; [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"]; [defaults synchronize]; [facebook dialog:@"feed" andDelegate:self]; }' 

另外如果你可以指导我在iOS中使用Facebook时使用storyboard的教程,那将是非常棒的。

谢谢!

-(BOOL)application:openURL:sourceApplication:annotation:应该在应用程序委托中实现。

添加一个属性到appDelegate:

 @property (nonatomic, strong) Facebook *facebook; 

合成它!

在你的logintoFB方法中,在创buildFacebook对象后添加这个(AppDelegate应该是你的appDelegate类的名字)

 AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; appDelegate.facebook = facebook;