2013-03-20 2 views
0

Я пытаюсь реализовать facebook логин в моем приложении, я следовал эти два направляющих к письму:IOS Facebook Войти - ошибки компоновщика

http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/ https://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/

Но я получаю ошибку компоновщика при попытке для компиляции приложения для эмулятора iPhone.

Undefined symbols for architecture i386: 
    "_FBSessionStateChangedNotification", referenced from: 
     -[AppDelegate sessionStateChanged:state:error:] in AppDelegate.o 
     -[LoginViewController viewDidLoad] in LoginViewController.o 
     -[AppDelegate sessionStateChanged:state:error:] in AppDelegate.o 
     -[LoginViewController viewDidLoad] in LoginViewController.o 
ld: symbol(s) not found for architecture i386 

Я убедился, что все необходимые рамки и файлы находятся в нужном месте. Кроме того, я не вижу ошибок кода в Xcode, поэтому я действительно не знаю, что здесь не так.

Пожалуйста, любая помощь в значительной степени определяется.


EDIT:

//AppDelegate.h 

#import <UIKit/UIKit.h> 
#import <FacebookSDK/FacebookSDK.h> 

@interface AppDelegate : UIResponder <UIApplicationDelegate> { 

} 

@property (strong, nonatomic) UIWindow *window; 

extern NSString *const FBSessionStateChangedNotification; 
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI; 
- (void)closeSession; 
@end 

-

// AppDelegate.m 

#import "AppDelegate.h" 
#import "NetworkCheck.h" 


@implementation AppDelegate 

- (void)dealloc 
{ 
    [_window release]; 
    [super dealloc]; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    NSLog(@"Application launch"); 

    NetworkCheck *netCheck = [[NetworkCheck alloc] init]; 
    [netCheck startCheck]; 

    NSString *const FBSessionStateChangedNotification =  @"com.example.Login:FBSessionStateChangedNotification"; 


    return YES; 
} 

/* 
* If we have a valid session at the time of openURL call, we handle 
* Facebook transitions by passing the url argument to handleOpenURL 
*/ 
- (BOOL)application:(UIApplication *)application 
      openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication 
     annotation:(id)annotation { 
    // attempt to extract a token from the url 
    return [FBSession.activeSession handleOpenURL:url]; 
} 

/* 
* Callback for session changes. 
*/ 
- (void)sessionStateChanged:(FBSession *)session 
        state:(FBSessionState) state 
        error:(NSError *)error 
{ 
    switch (state) { 
     case FBSessionStateOpen: 
      if (!error) { 
       // We have a valid session 
       NSLog(@"User session found"); 
      } 
      break; 
     case FBSessionStateClosed: 
     case FBSessionStateClosedLoginFailed:[FBSession.activeSession closeAndClearTokenInformation]; 
      break; 
     default: 
      break; 
    } 

[[NSNotificationCenter defaultCenter] 
postNotificationName:FBSessionStateChangedNotification 
object:session]; 

if (error) { 
    UIAlertView *alertView = [[UIAlertView alloc] 
           initWithTitle:@"Error" 
           message:error.localizedDescription 
           delegate:nil 
           cancelButtonTitle:@"OK" 
           otherButtonTitles:nil]; 
    [alertView show]; 
} 
} 

/* 
* Opens a Facebook session and optionally shows the login UX. 
*/ 
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI { 
return [FBSession openActiveSessionWithReadPermissions:nil 
              allowLoginUI:allowLoginUI 
            completionHandler:^(FBSession *session, 
                 FBSessionState state, 
                 NSError *error) { 
             [self sessionStateChanged:session 
                  state:state 
                  error:error]; 
            }]; 
} 

- (void) closeSession { 
[FBSession.activeSession closeAndClearTokenInformation]; 
} 

- (void)applicationWillResignActive:(UIApplication *)application 
{ 
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
} 

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
} 

- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 
// Called as part of the transition from the background to the inactive state; here you  can undo many of the changes made on entering the background. 
} 

- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 

// We need to properly handle activation of the application with regards to Facebook Login 
// (e.g., returning from iOS 6.0 Login Dialog or from fast app switching). 
[FBSession.activeSession handleDidBecomeActive]; 
} 

- (void)applicationWillTerminate:(UIApplication *)application 
{ 
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
[FBSession.activeSession close]; 
} 

@end 

ответ

1

FBSessionStateChangedNotification является extern определение, которое должно было быть видно в любом файле заголовка импортируемого для того, чтобы быть доступными для кода вы пишете в своем приложении appDelegate.

Вам нужно передать эту строку:

NSString *const FBSessionStateChangedNotification = @"com.example.Login:FBSessionStateChangedNotification"; 

в файл, который сделает его видимым для других классов (не только приложение делегата).

+0

Спасибо, я добавил AppDelegate.h и .m на мой вопрос. – user1359448

+0

У меня есть кнопка входа в facebook в контроллере представления, а в контроллере представления я импортирую AppDelegate.h – user1359448

+0

Обновлен ответ – Stavash

Смежные вопросы