2012-03-27 338 views
-2

我嘗試將facebook api集成到我的應用程序中以發佈到牆上。 現在我在我的appdelegate集成代碼,但我不知道在這行收到此errore: 「initWithAppId:未找到」facebook集成iphone

AppDelegate.h

#import <UIKit/UIKit.h> 
#import "FBConnect.h" 
#import "Facebook.h" 

@interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> { 
    UIWindow *window; 
    UITabBarController *tabBarController; 
    Facebook *facebook; 
} 

@property (retain, nonatomic) IBOutlet UIWindow *window; 
@property (retain, nonatomic) IBOutlet UITabBarController *tabBarController; 
@property (retain, nonatomic) Facebook *facebook; 

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    [self.window addSubview:self.tabBarController.view]; 

    facebook = [[Facebook alloc] initWithAppId:@"168377643283604"]; 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) { 
     facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; 
     facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; 
    } 
    [self.window makeKeyAndVisible]; 

    return YES; 
    } 
+1

你剛複製和粘貼的地方這個代碼? – 2012-03-27 08:53:53

回答

0

試試這個:

facebook = [[Facebook alloc] initWithAppId:@"YOUR_APP_ID" andDelegate:self]; 

而不是

facebook = [[Facebook alloc] initWithAppId:@"YOUR_APP_ID" ]; 

,不要忘記在.plist文件中添加YOUR APP ID了。

補充一點:

@interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate,FBSessionDelegate> 
+0

我已經在.plist中插入了APP ID。如果我添加「andDelegate:self」獲取此錯誤:<(id )> – Maurizio 2012-03-27 09:19:50

+0

請參閱我的編輯代碼: – 2012-03-27 09:33:30