really, really odd error
I have an app that was working fine in iOS5/.1, now I'm having a few transition problems with iOS6 but this one is confusing.
I have some code that launches a mail composer, and since iOS 6 it causes a crash with this error:
* Assertion failure in -[UICGColor encodeWithCoder:], /SourceCache/UIKit/UIKit-2372/UIColor.m:1191 2012-09-26 02:14:38.044 MyCQs Medical[2126:1b03] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only support RGBA or the White color space, this method is a hack.'
Any suggestions? Through trial and error commenting out various lines it seems to be the alloc/init line that causes the error, though when all the lines are uncommented, all of the NSLogs are executed, including "present" which indicates that everything that should be called, has been. the app crashes before the mailcomposer is presented on screen, I'd really appreciate any advice here
if (indexPath.row == 3) {
if([MFMailComposeViewController canSendMail]){
mailComposer = [[MFMailComposeViewController alloc]init];
NSLog(@"Alloc, init");
mailComposer.mailComposeDelegate = self;
NSLog(@"Set delegate");
NSArray *toArray = [[NSArray alloc]initWithObjects:@"[email protected]", nil];
NSLog(@"To array");
[mailComposer setToRecipients:toArray];
NSLog(@"To recipients");
[mailComposer setSubject:@"Message from a MyCQs user!"];
NSLog(@"Subject");
NSLog(@"About to present mail composer");
[[mailComposer navigationBar] setTintColor:[UIColor blackColor]];
[self presentModalViewController:mailComposer animated:YES];
NSLog(@"Present");
}
}
Ok only a partial solution but it's the best one I can think of without some fairly disruptive code changes.
For anyone else who gets this problem in future, I think it's a bug in iOS 6, MFMailComposeViewController crashes when you have set the UITableView separatorStyle to a colorWithPatternImage, but it works fine when you use a solid colour, so:
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 5.2) { NSLog(@"Using iOS 5x"); [[UITableView appearance]setSeparatorColor:[UIColor colorWithRed:142.0/255.0 green:130.0/255.0 blue:76.0/255.0 alpha:1.0]]; } else { NSLog(@"Using iOS 6x, Table view use pattern color"); [[UITableView appearance]setSeparatorColor:[UIColor colorWithPatternImage: [UIImage imageNamed:@"dotted-line2.png"]]]; }
Actually I believe this is a significant bug, did anybody file a radar, yet?
As it seems to me, the assertion throws whenever you use "colorWithPatternImage" ANYWHERE in your presenting view controller's appearance proxies.
I think what happens is that iOS tries to store the appearance of your App before switching to a separate service (which is what MFMailComposeViewController does, it's now a "remote view controller" that gets presented by your App but which is managed by another App/process), since the Mail App wants to determine the appearance itself so it changes things like tint colors etc. More about remote view controller here, in case somebody is interested: http://oleb.net/blog/2012/10/remote-view-controllers-in-ios-6/
This seems to fail. This has to be a bug, the image should be encodable.
Workarounds may be hard. I tried to exchange the patterned color for a plain one right before presenting the view controller but found you at least have to make sure it really gets redrawn on screen and gave up (I don't really needed the pattern).
My problem was also due to using colorWithPatternImage but I found that it seems to only cause an issue when used on elements that are shown on the MFMailCompserViewController e.g.:
[[UINavigationBar appearance] setTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"navbar"]]];
I've found that MFMailComposeViewController only crashes when colorWithPatternImage
is used in [[UITableView appearance]
statement. I've had no problem when I set the background and separatorColor in the table's viewDidLoad. The only problem is you need to do this for each table.
[self.tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]]];
[self.tableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With