Facebook SDK 3.0 HelloFacebookSample build errors

十年热恋 提交于 2020-01-03 04:40:15

问题


I'm having trouble compiling the HelloFacebookSample app that comes with Facebook SDK 3.0.

Firstly, I should say I'm using Xcode 4.0.2, iOS SDK 4.3 and OS X 10.6.8. (I'm struggling to find a way to download Xcode 4.2 without upgrading to Lion or Mountain Lion, which I'm reluctant to do.)

When I try to build the sample project, I get the following build errors:

1) Unexpected '@' in program

int main(int argc, char *argv[])
{
    @autoreleasepool {    // error on this line
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([HFAppDelegate class]));
    }
}

2) Expected identifier

- (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];    // error on this line
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // FBSample logic
    // if the app is going away, we close the session object
    [FBSession.activeSession close];                       // error on this line
}

I can "resolve" these problems (not sure if I resolved them correctly), but then I then get the following linking error:

Framework not found Accounts

Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1

Can anyone help me at all? I won't have much luck integrating Facebook into my app if I can't even build the sample projects!


回答1:


I resolved all the issues. It appears the sample is not immediately compatible with iOS 4.3 or Xcode 4.0.2. Here's what I did:

1) Unexpected @ in program; changed to the following:

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([HFAppDelegate class]));
}

2) Expected identifier; replaced

    return [FBSession.activeSession handleOpenURL:url];    // error on this line
...
    [FBSession.activeSession close];                       // error on this line

with

    return [[FBSession activeSession] handleOpenURL:url];
...
    [[FBSession activeSession] close];

3) Framework not found Accounts; turns out it's not required, so I just deleted the framework from the Frameworks group in the Project Navigator.

4) I forgot to say in my original post: keyword strong was unknown, so I macro'd it as retain at the top of the file FacebookSDK/FacebookSDK.h as follows:

#define strong retain

And now the HelloFacebookSample app compiles with no errors or warnings and it works fine. All interactions with Facebook work.

Hope this helps someone else in the future! If it helps you, please vote it up!




回答2:


I'm not an expert, but I'll do my best.

The first error is because your'e using @autoreleasepool. I think this is quite new syntax for the auto release pool. Before it was something like this:

NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
NSString *string;
string = [[[NSString alloc] init] autorelease]; // NSString or any other allocated objects
                                                // With autorelease tag
/* use the string */
[pool drain];

You should look at projects for X-code 4.0.2 and your iOS SDK to find how the main function is there.

I'm looking at the other error, I believe it has something to do with the iOS SDK you're using. Isn't it possible to update only the SDK? without updating xcode?

if I'll find something, I'll let you know



来源:https://stackoverflow.com/questions/12359436/facebook-sdk-3-0-hellofacebooksample-build-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!