13

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

Yu Tamura
  • 143
  • 1
  • 9
  • Can you try to set animated:no on transitions? – Woodstock Sep 24 '13 at 11:09
  • There is no difference about TWTweetComposeViewController. About MFMailComposeViewController,does not appear ViewController and crash(EXC_BAD_ACCESS). – Yu Tamura Sep 24 '13 at 11:20
  • 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 Sep 29 '13 at 00:19
  • We are only seeing that on iPhone 5s, currently running iOS 7.0.2 (11A501). Compiling the exact same code and running it on iPhone 5 does not show the issue. Build was 32-bit only, so it's not a 64-bit issue in our app. However, it seems to be a 32- vs 64-bit issue on Apple's side. When compiling our app with arm64, those views display correctly. Can anyone please confirm? – flo_muc Sep 30 '13 at 14:13
  • I am getting the same behavior in the same situations using UIActivityViewController and SLComposeViewController – Dima Sep 30 '13 at 23:21
  • see my answer for details – Dima Sep 30 '13 at 23:34
  • Related question with similar answer: http://stackoverflow.com/questions/20411489/qlpreviewcontroller-quicklookd-failing-to-load – Graham Perks Jan 23 '14 at 20:59

10 Answers10

24

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.

Navnath Godse
  • 2,233
  • 2
  • 23
  • 32
flo_muc
  • 264
  • 1
  • 4
  • 1
    Thank you for response.I removed **[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -1)];** and fixed this issue! – Yu Tamura Oct 04 '13 at 08:26
  • 1
    I've reported this issue as well as rdar://15165678 – Alex Pretzlav Oct 07 '13 at 15:59
  • 5
    This is insane, I applaud you for finding the bug in Apple's code. – runmad Oct 09 '13 at 16:24
  • Same issue here with QLPreviewController. Customizing UIBarButtonItem's titlePosition in versions less than 7 fixed my issue. – Ian Hoar Oct 15 '13 at 20:16
  • I had the same experience while using the UISearchBar appearance APIs. [searchBarApperance setPositionAdjustment:UIOffsetMake(100, 0) forSearchBarIcon:UISearchBarIconClear]; – Sonny Saluja Oct 16 '13 at 22:44
  • I removed [[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0f, -3.0f)]; Going to open a radar about that. iPhone5S / iOS 7.0.x / XCode 5.0 – loretoparisi Oct 25 '13 at 12:50
  • Brandyn Brosemer's answer helped me: building on 64bit solves the problem. – de. Feb 13 '14 at 14:58
7

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.

  • and I'm eating my previous words here; had an incorrect build setting, and once that was fixed, and was able to build for 64, this problem went away. Upvoting... ;-) – wkhatch Jan 28 '14 at 18:16
3

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.

Sean Mahan
  • 469
  • 3
  • 13
2

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.

Community
  • 1
  • 1
Dima
  • 23,484
  • 6
  • 56
  • 83
1

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!

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
SuperRunt
  • 29
  • 4
0

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];
}
Ken Kuan
  • 809
  • 6
  • 8
0

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

Chamira Fernando
  • 6,836
  • 3
  • 23
  • 23
0

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.

Jaime Leon
  • 21
  • 1
0

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

0

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