Cannot show modal ViewController in iOS7 - ios

I tried to show system defined viewcontrollers (MFMailComposeViewController, TWTweetComposeViewController,etc..) as a modal view.
But these viewcontrollers dosn't appear in iOS 7(these run in iOS5,iOS6).
Viewcontrollers created by me appear in iOS7(ex.HogeViewController).
I don't call presentViewController:animated:completion at viewDidLoad or viewWillAppear.
Does anybody have an idea?
Console logs:
init Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed. (Cocoa error 4097.)"
or
_serviceViewControllerReady:error: Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed. (Cocoa error 4097.)"
or
Unbalanced calls to begin/end appearance transitions for .
TWTweetComposeViewController(doesn't appear)
TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc]init];
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result){
NSLog(#"Result : %d",result);
};
[self presentViewController:viewController animated:YES completion:NULL];
Log
Result : 0
MFMailComposeViewController(appears a moment and dismiss soon)
- (void)send:(NSString*)email{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSArray *toRecipients = #[email];
[picker setToRecipients:toRecipients];
[picker setSubject:#"Subject"];
[picker setMessageBody:#"Body" isHTML:NO];
[self.navigationController presentViewController:picker animated:YES completion:NULL];
}
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissViewControllerAnimated:YES completion:^{
NSLog(#"error:%#,result:%d",error.description,result);
}];
}
Log
_serviceViewControllerReady:error: Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed. (Cocoa error 4097.)"
Unbalanced calls to begin/end appearance transitions for .
error:(null),result:0

Turns out the issue only shows up when customizing UIBarButtons. If we use the following in our 32-bit app running on iPhone 5s, we have the problem:
[[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, 1.0)
forBarMetrics:UIBarMetricsDefault];
Leaving out that line works around the problem. We have filed a radar.

This is an issue when you do not compile for 64bit (arm64) in your project settings. Though this may not always be an option for some people because currently Google Analytics does not support the 64bit devices.

You may be able to avoid this issue with some subclassing. I was having the same issue, and in my case the culprit was:
[[UISearchBar appearance] setSearchTextPositionAdjustment:UIOffsetMake(15.0f, 0.0f)];
I was already using a subclass of UISearchBar anyway, so I changed that to:
[[KA_SearchBar appearance] setSearchTextPositionAdjustment:UIOffsetMake(15.0f, 0.0f)];
That's resolved the issue for me. Only tested on an iPhone 5s, iOS 7.0.3.

I am getting the same behavior in the same situations. In my case it turned out to be caused by using the "setSeparatorInset" appearance selector of UITableView. Getting rid of that fixed the problem. This looks like a bug on Apple's end for sure, but at least there is a workaround.
This question shows someone having a similar problem and in their case getting rid of a UISearchBar appearance selector fixed it. So something is wrong with some of these UIAppearance selectors.

This post helped me find a solution to a similar issue. But my problem was not related to the tab bar, so I figured I'd share if anyone else comes across this post:
The mail modal opened when tapping a table cell, but would instantly dismiss. In my case, this code caused the problem:
[[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil] setFont:[UIFont systemFontOfSize:17.0]];
I deleted it, and everything works!

In My case, following code will cause the same issue on 64bit machine or simulator. Hope for helping someone met this issue.
if ([UITableViewCell instancesRespondToSelector:#selector(setSeparatorInset:)]) {
[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];
}

This Problem occurs in iPad air (64 bit) when app is not complied for 64 architecture. The problem I encountered was every UIAppearance selector which try to use UIOffsetMake/UIOffsetZero doesn't work properly!
example
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(1.0, 1.0) forBarMetrics:UIBarMetricsDefault];
or
[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsMake(0, 5, 0, 5)];
I think its a bug in Apple code and I tried few things but nothing works. Better if you can comment out places where you setInsets in UIAppearance selectors

I had the same error when use SLComposeViewController to share with Facebook or Twitter using the simulator of 64-Bits or an iPhone 5s, then i delete every line of code that use "appearance, for example [UITableViewCell appearance] or [UIBarButtonItem appearance], and every run ok.

I updated xcode to version 5.1 and it worked ok now.

NSXPCConnectionInterrupted = 4097. I would have your code retry the command as the error looks to be transient.

Related

dismissViewControllerAnimated crashing

I have Simple popOver controller in my project. i can dismiss it using action button with following code.
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
but sometimes app gets crash if i do something on that viewController
before dismiss it.
Example : There is a pickerView for selection and post button. but without posting it if i did some selection and cancel it im getting this error. its only happening occasionally. not everytime. if it happens onetime then it might happen everytime after that.
Can someone explain? is it memory leak or something?
I think have solved the problem . in that PopOver new window i was using locationManager and i was using just
[locationManager stopUpdatingLocation];
but i have added following thing as well
locationManager = nil;
no crash anymore
Sometimes if you have dealloc function as mentioned below, this issue may occur.
- (void)dealloc {
[_yourview release]; //don't do this
[super dealloc];
}
I hope this might help some one else

Azure Mobile Services crash

Using the ios WindowsAzureMobileServices.framework (v1.2.3) I get an [NSArray insertObject:atIndex] exception (object cannot be nil) in code I don't control when I use the following code to present a MSLoginController.
MSLoginController *loginController =
[self.client
loginViewControllerWithProvider:provider
completion:^(MSUser *user, NSError *error)
{
//some code
}];
[controller presentViewController:loginController animated:YES completion:nil];
Any one have ideas how to rectify? Or why this is occurring?
I expanded the stack trace when the crash occurs and discovered UIAppearance calls were in the stack when the UIViewController was presented. After some digging into our appearance customization code the following code causes the crash:
[[UIBarButtonItem appearance] setStyle:UIBarButtonItemStylePlain];
The Azure library uses the UIToolbar in a different manner than was used elsewhere in the app and produced the exception.

How to debug iOS7 shadowOffset crash

My app works fine on ios6. I made a copy and ran it on Xcode5 and it launches but a few seconds later it crashes with this error:
[UIDeviceRGBColor shadowOffset]: unrecognized selector sent to instance
I had some tableviewcontroller lines like this:
//[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
but I commented them all out thinking they were the issue. What else could be causing the crash?
//do this to see if the selector exists replace dismissViewController... with your selector that you want to check
if ([self respondsToSelector:#selector(dismissViewControllerAnimated:completion:)])
{[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];} //post-iOS6.0
else {[self dismissModalViewControllerAnimated:YES];} //pre-iOS6.0

iOS 5.0 simulator: GKLeaderBoardViewController not showing

The following piece of code works nice on iOS 6.0 (both simulator and device). The game center is presented allright. But it does nothing on iOS 5.0 simulator. Unfortunately I don't have a device with iOS 5.0, so I can't check if it is a simulator-related issue.
- (void)showLeaderboard:(NSString *)leaderboard
{
GKLeaderboardViewController * leaderboardViewController = [[GKLeaderboardViewController alloc] init];
leaderboardViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[leaderboardViewController setCategory:leaderboard];
[leaderboardViewController setLeaderboardDelegate:self];
[[[UIApplication sharedApplication] delegate].window.rootViewController presentViewController:leaderboardViewController animated:YES completion:^{
}];
[leaderboardViewController release];
}
So what happens? Nothing. No view is presented. It doesn't log any messages into the console. It does not even reach the completion block.
I tried to play around and here is what I've managed to figure out. I use CustomLeaderboardViewController inherited from GKLeaderboardViewController instead of pure GKLeaderboardViewController, and place a breakpoint in the shouldAutorotateToInterfaceOrientation method. It does not fire with the code above. But if I use
setCategory:nil
instead of
setCategory:leaderboard
then that breakpoint fires. Still nothing happens further and the completion block is not called.
Any thoughts why could such a thing happen?
Make sure that none of your variables (e.g., 'leaderboard') are non-nil, as Objective C likes to fail silently in such cases.
It turned out to be just a silly mistake. [[UIApplication sharedApplication] delegate].window.rootViewController was nil, because it was never set in case of iOS 5.0.

Inconsistent crash while posting to facebook using FBNativeDialogs on iOS6.0

I've been struggling with this issue for a while now and I just can't seem to reproduce it accurately enough to describe the exact use-case. Essentially, what I'm doing is issuing a request for opening a native iOS 6.0 Facebook share dialog (using the Facebook iOS SDK 3.1.1):
if ([[SocialManager sharedManager] isNativeFacebookShareDialogAvailable]) {
if (!url) {
url = [NSURL URLWithString:#""];
}
if (!imageUrl) {
imageUrl = [NSURL URLWithString:#""];
}
dispatch_async(backgroundQueue, ^{
NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
UIImage *image = [UIImage imageWithData:imageData];
if (!image) {
image = [[UIImage alloc] init];
}
if ([FBNativeDialogs canPresentShareDialogWithSession:[FBSession activeSession]]) {
dispatch_async(dispatch_get_main_queue(), ^{
[FBNativeDialogs presentShareDialogModallyFrom:sender initialText:initialText images:#[image] urls:#[url] handler:^(FBNativeDialogResult result, NSError *error) {
if (error) {
failBlock([[error userInfo] description]);
} else {
if (result == FBNativeDialogResultSucceeded) {
completionBlock();
} else if (result == FBNativeDialogResultCancelled) {
failBlock(#"User cancelled");
} else if (result == FBNativeDialogResultError) {
failBlock(#"Unknown error");
}
}
}];
});
} else {
LogErr(#"Can't display native share dialog for active session");
}
});
}
Right after presentShareDialogModallyFrom:sender is called, I either get the following crash log:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x1d161490> was mutated while being enumerated.'
*** First throw call stack:
(0x32ede2a3 0x326b097f 0x32eddd85 0x35da094d 0x32edb62f 0x35da07f5 0x35e7e5e5 0x35e0ccd7 0x35e0cb6d 0x372c490f 0x35e0ca61 0x35e160d5 0x372b783b 0x35e160b1 0x372b711f 0x372b699b 0x372b6895 0x372c5215 0x372c53b9 0x36f5fa11 0x36f5f8a4)
libc++abi.dylib: terminate called throwing an exception
OR I get no crash and the native share dialog appears as it should.
The stack implies a call on a thread called UIRemoteViewControllerCreationRequest at this point, here are 2 examples for two different crashes:
Thanks for your help
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 the SLComposeViewController 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.
I think the problem is what Walt already said. In your code, something is done outside the main thread.
In the crash log you can see that someone is setting the appearance (UIAppearance) on some UI element from a non-UI thread. That's the problem. This operation MUST be done ONLY in the UI (main) thread.
I believe this has to do with the combination of the UIAppearance methods and launching a UIRemoteViewController from a background thread. We're having the same issue in our app. I'm going to change our presenter class to present all our remote viewControllers from the main thread and see if that helps.
In your case, I guess something in the Facebook SDK is presenting something from a background thread.
I'll update after I've verified that my fix works.
This is a bug in iOS 6 and Social Framework, check answer here UINavigationBar appearance and Facebook-Sheet Bug
How to solve this?
Simply instead of using [UINavigationBar appearance] use [UINavigationBar appearanceWhenContainedIn:...]
You can use custom class for your navigation controller (eg. CustomNavigationController) and then apply it in appearance:
[UINavigationBar appearanceWhenContainedIn:[CustomNavigationController class], nil]
From my experiments it should be used on all appearance methods, not only UINavigationBar but also UIBarButtonItem etc. (on every object you send appearance message to)
I think you know what is obvious but I met this error once and it was an NSMutableArray that was mutated while being enumerated inside a for..in statement.
Look at the NSMutableArray, you'll find your error.
Byt the way, if you target ios6, why don't you use the social framework with native facebook implementation ?

Resources