2012-06-01 4 views
1

앱을 만들었고 성공적으로 완료했습니다. 단지 Fcebook에서 공유하려고하고 자습서를 참조하여 시도했습니다. . 여기 viewcontroller.m 파일에 내 코드가있다.clang으로 컴파일러 오류가 발생했습니다 : 오류 : 종료 코드 1을 사용하여 링커 명령이 실패했습니다 (호출을 보려면 -v 사용)

// 
#import "ViewController.h" 


@interface ViewController() 

@end 

@implementation ViewController 

@synthesize btnLogin; 
@synthesize btnPublish; 
@synthesize lblUser; 
@synthesize actView; 
@synthesize facebook; 
@synthesize permissions; 
@synthesize isConnected; 

-(void)checkForPreviouslySavedAccessTokenInfo 
{ 
// Initially set the isConnected value to NO. 
isConnected = NO; 

// Check if there is a previous access token key in the user defaults file. 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
if ([defaults objectForKey:@"FBAccessTokenKey"] && 
    [defaults objectForKey:@"FBExpirationDateKey"]) { 
    facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; 
    facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; 

    // Check if the facebook session is valid. 
    // If it’s not valid clear any authorization and mark the status as not connected. 
    if (![facebook isSessionValid]) { 
     [facebook authorize:nil]; 
     isConnected = NO; 
    } 
    else { 
     isConnected = YES; 
    } 
} 
} 


-(void)setLoginButtonImage{ 
UIImage *imgNormal; 
UIImage *imgHighlighted; 
UIImageView *tempImage; 

// Check if the user is connected or not. 
if (!isConnected) { 
    // In case the user is not connected (logged in) show the appropriate 
    // images for both normal and highlighted states. 
    imgNormal = [UIImage imageNamed:@"LoginNormal.png"]; 
    imgHighlighted = [UIImage imageNamed:@"LoginPressed.png"]; 
} 
else { 
    imgNormal = [UIImage imageNamed:@"LogoutNormal.png"]; 
    imgHighlighted = [UIImage imageNamed:@"LogoutPressed.png"]; 
} 

// Get the screen width to use it to center the login/logout button. 
// We’ll use a temporary image view to get the appopriate width and height. 
float screenWidth = [UIScreen mainScreen].bounds.size.width;  
tempImage = [[UIImageView alloc] initWithImage:imgNormal]; 
[btnLogin setFrame:CGRectMake(screenWidth/2 - tempImage.frame.size.width/2, btnLogin.frame.origin.y, tempImage.frame.size.width, tempImage.frame.size.height)]; 

// Set the button’s images. 
[btnLogin setBackgroundImage:imgNormal forState:UIControlStateNormal]; 
[btnLogin setBackgroundImage:imgHighlighted forState:UIControlStateHighlighted]; 

// Release the temporary image view. 
[tempImage release]; 
} 

-(void)showActivityView{ 
// Show an alert with a message without the buttons. 
UIAlertView *msgAlert = [[UIAlertView alloc] initWithTitle:@"My test app" message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; 
[msgAlert show]; 

// Show the activity view indicator. 
actView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0, 0.0, 40.0, 40.0)]; 
[actView setCenter:CGPointMake(160.0, 350.0)]; 
[actView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray]; 
[self.view addSubview:actView]; 
[actView startAnimating]; 
} 


-(void)stopShowingActivity{ 
[actView stopAnimating]; 
UIAlertView *msgAlert = nil; 
[UIAlertView:msgAlert dismissWithClickedButtonIndex:0 animated:YES]; 
} 

-(void)saveAccessTokenKeyInfo{ 
// Save the access token key info into the user defaults. 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"]; 
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"]; 
[defaults synchronize]; 
} 

-(void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response { 
// Keep this just for testing purposes. 
NSLog(@"received response"); 
} 


-(void)request:(FBRequest *)request didLoad:(id)result{ 
// With this method we’ll get any Facebook response in the form of an array. 
// In this example the method will be used twice. Once to get the user’s name to 
// when showing the welcome message and next to get the ID of the published post. 
// Inside the result array there the data is stored as a NSDictionary.  
if ([result isKindOfClass:[NSArray class]]) { 
    // The first object in the result is the data dictionary. 
    result = [result objectAtIndex:0]; 
} 

// Check it the “first_name” is contained into the returned data. 
if ([result objectForKey:@"first_name"]) { 
    // If the current result contains the "first_name" key then it's the user's data that have been returned. 
    // Change the lblUser label's text. 
    [lblUser setText:[NSString stringWithFormat:@"Welcome %@!", [result objectForKey:@"first_name"]]]; 
    // Show the publish button. 
    [btnPublish setHidden:NO]; 
} 
else if ([result objectForKey:@"id"]) { 
    // Stop showing the activity view. 
    [self stopShowingActivity]; 

    // If the result contains the "id" key then the data have been posted and the id of the published post have been returned. 
    UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"My test app" message:@"Your message has been posted on your wall!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
    [al show]; 
    [al release]; 
} 
} 

-(void)request:(FBRequest *)request didFailWithError:(NSError *)error{ 
NSLog(@"%@", [error localizedDescription]); 

// Stop the activity just in case there is a failure and the activity view is animating. 
if ([actView isAnimating]) { 
    [self stopShowingActivity]; 
} 
} 

-(void)fbDidLogin{ 
// Save the access token key info. 
[self saveAccessTokenKeyInfo]; 

// Get the user's info. 
[facebook requestWithGraphPath:@"me" andDelegate:self]; 
} 

-(void)fbDidNotLogin:(BOOL)cancelled{ 
// Keep this for testing purposes. 
//NSLog(@"Did not login"); 

UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"My test app" message:@"Login cancelled." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
[al show]; 
} 

-(void)fbDidLogout{ 
// Keep this for testing purposes. 
//NSLog(@"Logged out"); 

// Hide the publish button. 
[btnPublish setHidden:YES]; 
} 

- (IBAction)LoginOrLogout { 
// If the user is not connected (logged in) then connect. 
// Otherwise logout. 
if (!isConnected) { 
    [facebook authorize:permissions]; 

    // Change the lblUser label's message. 
    [lblUser setText:@"Please wait..."]; 
} 
else { 
    [facebook logout:self]; 
    [lblUser setText:@"Tap on the Login to connect to Facebook"]; 
} 

isConnected = !isConnected; 
[self setLoginButtonImage]; 
} 

- (IBAction)Publish { 
// Show the activity indicator. 
[self showActivityView]; 

// Create the parameters dictionary that will keep the data that will be posted. 
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
           @"My test app", @"name", 
           @"http://www.google.com", @"link", 
           @"FBTestApp app for iPhone!", @"caption", 
           @"This is a description of my app", @"description", 
           @"Hello!\n\nThis is a test message\nfrom my test iPhone app!", @"message",    
           nil]; 

// Publish. 
// This is the most important method that you call. It does the actual job, the message posting. 
[facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
// Set the permissions. 
// Without specifying permissions the access to Facebook is imposibble. 
permissions = [[NSArray arrayWithObjects:@"read_stream", @"publish_stream", nil] retain]; 

// Set the Facebook object we declared. We’ll use the declared object from the application 
// delegate. 
facebook = [[Facebook alloc] initWithAppId:@"236058923xxxxxx" andDelegate:self]; 

// Check if there is a stored access token. 
[self checkForPreviouslySavedAccessTokenInfo]; 


// Depending on the access token existence set the appropriate image to the login button. 
[self setLoginButtonImage]; 

// Specify the lblUser label's message depending on the isConnected value. 
// If the access token not found and the user is not connected then prompt him/her to login. 
if (!isConnected) { 
    [lblUser setText:@"Tap on the Login to connect to Facebook"]; 
} 
else { 
    // Get the user's name from the Facebook account. The message will be set later. 
    [facebook requestWithGraphPath:@"me" andDelegate:self]; 
} 

// Initially hide the publish button. 
[btnPublish setHidden:YES]; 

} 

- (void)viewDidUnload 
{ 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

- (void)dealloc { 
[btnLogin release]; 
[lblUser release]; 
[btnPublish release]; 
[actView release]; 
[facebook release]; 
[permissions release]; 
[super dealloc]; 
} 


@end 

viewcontroller.h 그리고 파일의 코드

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

@interface ViewController : UIViewController <FBSessionDelegate, FBRequestDelegate,  FBDialogDelegate>{ 
UIButton *btnLogin; 
UIButton *btnPublish; 
UILabel *lblUser; 
UIActivityIndicatorView *actView; 

Facebook *facebook; 

NSArray *permissions; 
BOOL isConnected;  

}이다

@property (retain, nonatomic) IBOutlet UIButton *btnLogin; 
@property (retain, nonatomic) IBOutlet UIButton *btnPublish; 
@property (retain, nonatomic) IBOutlet UILabel *lblUser; 
@property (retain, nonatomic) UIActivityIndicatorView *actView; 
@property (retain, nonatomic) Facebook *facebook; 
@property (retain, nonatomic) NSArray *permissions; 
@property (nonatomic) BOOL isConnected; 
  • (IBAction를) LoginOrLogout;
  • (IBAction) Publish; 내가 이러한 오류를 받고 있어요 Y

    @end

는 사람이 말할 수 있습니다.

답변

1

편집 :

귀하의 코멘트에서

, 당신은 또한 당신의 프로젝트에 페이스 북 SDK 샘플과 함께 제공되는 main.c 파일을 복사 (또는 당신 삭제 될 수 있습니다; main.c를 만 상용구 코드를 포함하는) 것 같다. 그것을 제거 (또는 더 나은, 샘플과 관련된 모든 파일을 제거), 그리고 그것은 작동합니다.

내 생각에 앱을 페이스 북 프레임 워크와 올바르게 연결하지 않았지만 컴파일러에서 얻은 정확한 오류 메시지를 실제로 살펴 봐야한다.

첫 번째 사항은 Create your iOS project입니다.

두 번째로, Xcode 4에서 첨부 된 그림과 같은 "경고"아이콘을 클릭하십시오. 당신이 더 많은 도움이 필요하면

enter image description here

, 당신은 링커에서 얻을 정확한 오류를보고하십시오.

+0

: /Users/vishnuprasathprasath/Library/Developer/Xcode/DerivedData/fb-gqtdwixfwoauihfzyixydvqrkqdc/Build/Intermediates/fb.build/Debug-iphonesimulator/fb에 _main 중복 기호 : 창에 내가 LD로 오류를 얻고있다. 빌드/Objects-normal/i386/main-20DA0707CEFEE534.o 및 /Users/vishnuprasathprasath/Library/Developer/Xcode/DerivedData/fb-gqtdwixfwoauihfzyixydvqrkqdc/Build/Intermediates/fb.build/Debug-iphonesimulator/fb.build/Objects-normal /i386/main-9AFAFE5A7ABE9554.o 아키텍처 i386에 대한 – Dany

+0

프로젝트에서 페이 스북 샘플 프로젝트를 삭제하십시오 – Martin

+0

@Martin : Tks ... 샘플 프로젝트를 삭제 한 후 작동합니다. 시뮬레이션 응용 프로그램은 성공적으로 FB 페이지를로드했습니다.하지만 로그인하지 않은 상태에서 신청서로 돌아왔다 .... 어떤 생각? .. – Dany

관련 문제