我一步一步跟着Facebook上的Facebook SDK教程。除了fbDidLogin被調用之外,我還有一些工作...授權過程正常工作。有人告訴我做:IOS - Facebook SDK fbDidLogin未調用 - 初始化視圖控制器。
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[controller facebook] handleOpenURL:url];
}
問題是,我不完全知道如何初始化頁頭我的視圖控制器。這裏是我的應用程序的委託.H:
#import <UIKit/UIKit.h>
#import "FBConnect.h"
@interface fb2AppDelegate : UIResponder <UIApplicationDelegate, FBSessionDelegate> {
Facebook *facebook;
UIViewController *fb2ViewController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic) Facebook *facebook;
@property (nonatomic, strong) UIViewController *fb2ViewController;
@end
與.m:
#import "fb2AppDelegate.h"
@implementation fb2AppDelegate
@synthesize window = _window;
@synthesize facebook;
@synthesize fb2ViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.fb2ViewController = [[UIViewController alloc] init];
facebook = [[Facebook alloc] initWithAppId:@"key_here" 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];
}
return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[fb2ViewController 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];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"key_here", @"app_id",
@"http://developers.facebook.com/docs/reference/dialogs/", @"link",
@"http://fbrell.com/f8.jpg", @"picture",
@"Facebook Dialogs", @"name",
@"Reference Documentation", @"caption",
@"Using Dialogs to interact with users.", @"description",
nil];
[facebook dialog:@"feed" andParams:params andDelegate:self];
}
作爲視圖控制器...我還沒有把任何代碼在其中。
,我收到的錯誤是:
爲「UIViewController的」沒有明顯的@interface聲明選擇「Facebook的
我到底做錯了什麼?
thx!
你是什麼意思的第二個版本的實施? – stackOverFlew 2012-08-19 05:42:32
雖然...不起作用,但...給出以下錯誤: 不可見@interface for'UIViewController'聲明選擇器'Facebook'=( – stackOverFlew 2012-08-19 05:50:00
[iphone SSO Facebook實現]的可能重複(http:// stackoverflow .com/questions/10403697/iphone-sso-facebook-implementation) – CodaFi 2012-08-19 05:51:55