I'm trying to integrate FB into an existing iOS app.
I've modified the HelloFacebookSample app to use my app ID, display name, and bundle identifier. I can run it and post from it just fine (running in the iOS 6 emulator). So that leads me to believe my settings on developers.facebook.com are correct.
Next I looked at the code in the app delegate and view controller in the sample and duplicated it in my own code. The first bit of Facebook code that gets executed is in the app delegate, in applicationDidBecomeActive:
. I execute the same two lines as the sample app:
[FBAppEvents activateApp];
[FBAppCall handleDidBecomeActive];
If I run my program, I eventually get EXC_BAD_ACCESS (code=2, address=0x0)
. In the debug navigator I see:
#0 0x0253309f in objc_msgSend ()
#1 0x0251eb2e in objc_setProperty_non_gc ()
#2 0x0251ed0d in objc_setProperty ()
#3 0x00446798 in -[FBRequestMetadata setCompletionHandler:] at /Users/chrisp/tmp/build- sdk/ios-sdk/src/FBRequestConnection.m:70
#4 0x004464eb in -[FBRequestMetadata initWithRequest:completionHandler:batchEntryName:] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBRequestConnection.m:94
#5 0x00446cb6 in -[FBRequestConnection addRequest:completionHandler:batchEntryName:] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBRequestConnection.m:324
#6 0x00446bdb in -[FBRequestConnection addRequest:completionHandler:] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBRequestConnection.m:312
#7 0x0044048a in -[FBRequest startWithCompletionHandler:] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBRequest.m:149
#8 0x0045ec70 in +[FBUtility fetchAppSettings:callback:] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBUtility.m:263
#9 0x0046e06b in +[FBSettings publishInstall:withHandler:isAutoPublish:] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBSettings.m:334
#10 0x0046dc0c in +[FBSettings autoPublishInstallImpl:] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBSettings.m:217
#11 0x00e27e83 in __NSFireDelayedPerform ()
#12 0x02a9d376 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#13 0x02a9ce06 in __CFRunLoopDoTimer ()
#14 0x02a84a82 in __CFRunLoopRun ()
#15 0x02a83f44 in CFRunLoopRunSpecific ()
#16 0x02a83e1b in CFRunLoopRunInMode ()
#17 0x0339f7e3 in GSEventRunModal ()
#18 0x0339f668 in GSEventRun ()
#19 0x0120665c in UIApplicationMain ()
#20 0x0000230d in main at /Users/craig/Documents/Projects/MyProject/main.m:14
If I remove [FBAppCall handleDidBecomeActive]
I get the same result. So this seems to be a result of [FBAppEvents activateApp]
.
If I remove [FBAppEvents activateApp]
, which I understand to be optional anyway, and only call [FBAppCall handleDidBecomeActive]
, I can launch the app. But then when I try to create an instance of FBLoginView
in my view controller:
FBLoginView * loginview = [[FBLoginView alloc] init];
I get the same error (EXC_BAD_ACCESS (code=2, address=0x0)
):
#0 0x0253309f in objc_msgSend ()
#1 0x0251eb2e in objc_setProperty_non_gc ()
#2 0x0251ed0d in objc_setProperty ()
#3 0x0046d47d in -[FBLoginView setSessionStateHandler:] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBLoginView.m:52
#4 0x0046b6f8 in -[FBLoginView initializeBlocks] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBLoginView.m:177
#5 0x0046ba1c in -[FBLoginView initialize] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBLoginView.m:212
#6 0x0046b432 in -[FBLoginView initWithFrame:] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBLoginView.m:119
#7 0x0124528f in -[UIView init] ()
#8 0x0046b252 in -[FBLoginView init] at /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBLoginView.m:80
#9 0x0001c0ea in -[MyViewController postToFacebook:] at /Users/craig/Documents/Projects/MyProject/Classes/MyViewController.mm:8040
#10 0x00015c18 in -[MyViewController copy:to:] at /Users/craig/Documents/Projects/MyProjects/Classes/MyViewController.mm:6624
#11 0x000225ee in -[MyViewController menuItemSelected:] at /Users/craig/Documents/Projects/MyProjects/Classes/MyViewController.mm:10003
#12 0x00e27e83 in __NSFireDelayedPerform ()
#13 0x02a9d376 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#14 0x02a9ce06 in __CFRunLoopDoTimer ()
#15 0x02a84a82 in __CFRunLoopRun ()
#16 0x02a83f44 in CFRunLoopRunSpecific ()
#17 0x02a83e1b in CFRunLoopRunInMode ()
#18 0x0339f7e3 in GSEventRunModal ()
#19 0x0339f668 in GSEventRun ()
#20 0x0120665c in UIApplicationMain ()
#21 0x0000230d in main at /Users/craig/Documents/Projects/MyProject/main.m:14
Don't be fooled by the fact that I'm obviously not creating my FBLoginView
in viewDidLoad
. The point is that the first call to anything that tries to do anything with my Facebook session fails in the same way. It looks like it's trying to do something with a handler in both cases. The identical code works with MY Facebook identifier, bundle ID, etc. in the sample code, but doesn't work in my app. I'm suspecting compiler/linker settings or some other configuration difference between my app and the sample, but I'm not sure where to begin to look. Everything I've looked at looks the same between my app and the sample.
I've tried a lot of different ways to open a Facebook session and get the permissions I need, but they all fail the same way. This seemed like a good one to post here since the sample works but the same code in my app doesn't.
Thanks for your help.
EDIT: I see in my build settings that the sample app uses ARC. I do not. I'm hesitant to convert a large, functioning app at this point in its lifecycle.