13
votes

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

10
interesting, can you please show your code? - Woodstock
Thank you for a comment. I edited question. - Yu Tamura
Can you try to set animated:no on transitions? - Woodstock
There is no difference about TWTweetComposeViewController. About MFMailComposeViewController,does not appear ViewController and crash(EXC_BAD_ACCESS). - Yu Tamura
I've encountered the exact same problem but only on an iPhone. An iPad does not exhibit the same problem for me. Unless I hear otherwise I believe it's an iOS 7 bug. If you set a breakpoint on the ending delegate method the result for the mail controller is MFMailComposeResultCancelled. - Ryan

10 Answers

24
votes

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.

7
votes

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.

3
votes

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.

2
votes

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.

1
votes

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!

0
votes

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];
}
0
votes

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

0
votes

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.

0
votes

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

0
votes

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