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!
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!
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