Inconsistent crash while posting to facebook using FBNativeDialogs on iOS6.0
After a lot of experimenting with my application and looking into Facebook SDK source I realized 3 things:
Creating a
SLComposeViewController
by yourself doesn't help. Facebook SDK is pretty simple in this, it just creates the controller exactly like the code in the answer with bonus.When you are authorizing the FB session, your application is deactivated once or more times. This is caused by the permission confirmation alerts appearing.
The
UIRemoteViewController
is actually theSLComposeViewController
which is run in a different process.
What caused my error?
- User confirms FB permissions
- This triggers
applicationDidBecomeActive:
- It also triggers FB callback to present the dialog.
- My
applicationDidBecomeActive:
was doing something with the UI what was not supposed to be done when the FB dialogs were appearing (tirggering a table reload).
Also, there is another thing to be careful of - the handler of presentShareDialogModallyFrom...
is not called on any particular thread (see SLComposeViewController
docs). That means that you should use dispatch_async(dispatch_get_main_queue(), ...)
from the handler if you are updating UI from it.
EDIT:Obviously, the previous steps fixed some crashes but one of the crashes was not solved. After a lot of googling and searching Apple Developer forums, I think there is a bug in iOS 6 connected with Remote Controllers and using UIAppearance
, especially the appearance of UINavigationBar
. I am currently removing the use of UIApperance
from my app.
This is a very strange way to post a post to Facebook. Here is a much simpler way that never crashes.
ViewController.h
#import <UIKit/UIKit.h>#import <Social/Social.h>#import <Accounts/Accounts.h>@interface ViewController : UIViewController {SLComposeViewController *mySLComposerSheet;}- (IBAction)PostToFacebook:(id)sender;@end
ViewController.m@implementation ViewController
- (IBAction)PostToFacebook:(id)sender {mySLComposerSheet = [[SLComposeViewController alloc] init];mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];[mySLComposerSheet setInitialText:@"Place Text Here"];[self presentViewController:mySLComposerSheet animated:YES completion:nil];}@end
If needed, there is a video here.
Sorry some of this is rather guessing, but I thought I would try:
Are you sure that canPresentShareDialogWithSession is safe to call from a non-UI thread?
You have a line in both stacks of _NSDictionaryEnumerate. It looks like from higher functions, that something is calling enumerateKeysAndObjectsUsingBlock:.
Based on your note of things crashing just after [presentShareDialogModallyFrom:sender]. Is there something being released when sender's view disappears?
Variable "image" is either retained or autoreleased depending on which code path it took.