簡體   English   中英

編譯器錯誤為clang:錯誤:鏈接器命令失敗,退出代碼為1(使用-v查看調用),且應用程序已完成

[英]Compiler error as clang: error: linker command failed with exit code 1 (use -v to see invocation) with completed app

我已經創建了一個應用程序並成功完成,我只想在Fcebook中共享,我通過參考一些教程進行了嘗試。 這是我在viewcontroller.m文件中的代碼。

//
#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)登錄或注銷;
  • (IBAction)發布;

    @結束

誰能說y我遇到這些錯誤。

編輯:

從您的評論看來,您似乎還將Facebook SDK示例隨附的main.c文件復制到了您的項目中(或者您可以刪除您的文件; main.c僅包含樣板代碼)。 刪除它(或者最好刪除與該示例相關的所有文件),它應該可以工作。

我的猜測是您沒有正確地將您的應用程序與Facebook框架鏈接,但是您應該真正查看從編譯器獲得的確切錯誤消息。

關於第一點,請檢查以下內容: 創建您的iOS項目

至於第二個,在Xcode 4中,單擊“警告”圖標,如圖所示。

在此處輸入圖片說明

如果您需要更多幫助,請報告從鏈接器獲得的確切錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM