我在定制我的应用时感到非常沮丧。 我已经创建并设计了几乎整个应用程序,包括导航栏,工具栏,tabBar等,但每次MFMailComposeViewController,MFMessageComposerViewController,Twitter或Facebook共享者甚至是QuickLook View Controller都会发挥作用时,应用程序会崩溃并显示以下消息:
*** Assertion failure in -[UICGColor encodeWithCoder:].
*** Terminating app due to uncaught exception 'NSInternalInconsistencyExceptionì, reason: 'Only RGBA or White color spaces are supported in this situation.'
我已经读到这是因为iOS 6将作曲家作为远程控制器进行管理,但我真的不知道如何解决这个问题。
由于这个原因,我不想删除邮件撰写功能或邮件撰写功能。
任何人都遇到过这个错误吗?
我已经编写了代码。问题是由于自定义UINavigationBars元素,UIAppearance正在使应用程序崩溃。 代码。
-(void)message{
if (_progressHUD){
[_progressHUD hide:YES];
}
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init] ;
[controller setMessageComposeDelegate:self];
if([MFMessageComposeViewController canSendText])
{
controller.body = descriptionString;
controller.recipients = nil;
[self presentViewController:controller animated:YES completion:nil];
}
}
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)email {
if (_progressHUD){
[_progressHUD hide:YES];
}
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:nil];
[composer setSubject:[NSString stringWithFormat:@"%@",nameString]];
[composer setMessageBody:[NSString stringWithFormat:@"%@",descriptionString] isHTML:NO]; [composer addAttachmentData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageString]] mimeType:@"png" fileName:imageString];
[composer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:composer animated:YES completion:nil];
}
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if (error) {
SIAlertView *alert = [[SIAlertView alloc] initWithTitle:@"Error"
andMessage:[NSString stringWithFormat:@"Error %@", [error description]]];
[alert addButtonWithTitle:@"OK" type:SIAlertViewButtonTypeDestructive handler:^(SIAlertView *alertView){}];
[alert show];
[self dismissViewControllerAnimated:YES completion:nil];
}
else {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
外观
- (void)customizeAppearance
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
UINavigationBar Appearance
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationBarBackground"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
UITextAttributeTextColor,
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"HelveticaNeue" size:0.0],
UITextAttributeFont,
nil]];
//ToolBar Appearance
[[UIToolbar appearance] setTintColor:[UIColor whiteColor]];
//Switch Appearance
[[UISwitch appearance] setOnTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"greenBackground"]]];
//Search Bar Appearance
[[UISearchBar appearance] setTintColor:[UIColor whiteColor]];
//Tab Bar Appearance
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabBarBackground"]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"transparent"]];
}
答案 0 :(得分:8)
在各种调试会话之后,我整理出了给我这些崩溃的代码行
//Switch Appearance
[[UISwitch appearance] setOnTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"greenBackground"]]];
所以我删除了它,一切正常。 显然,我不能直接在AppDelegate中设置外观,但我必须在交换机所在的类中进行。
对于refreshControl外观也是如此:必须在tableView的类中设置它。
答案 1 :(得分:1)
您需要为twitter,facebook添加必要的框架。
对于电子邮件,请执行以下操作:
将MessageUI.framework
添加到您的项目
在你的.h文件中
#import <MessageUI/MessageUI.h>
@interface CustomController : UIViewController<MFMailComposeViewControllerDelegate>
在你的.m文件中
- (IBAction)actionEmail:(id)sender
{
NSLog(@"actionEmail Called");
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[self presentViewController:mc animated:YES completion:NULL];
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}
答案 2 :(得分:0)
在您的.h文件中添加代理 <MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate>
在您的.m文件中添加以下
-(void)ShareByEmail:(NSString *)strEmail {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
NSString *bodyData = @"Boy data place here";
NSString *strRecipients = [NSString stringWithFormat:@"%@",strEmail];
strRecipients = [strRecipients stringByReplacingOccurrencesOfString:@"mailto:" withString:@""];
NSArray * arrayRecipients = [strRecipients componentsSeparatedByString:@""];
[mail setToRecipients:arrayRecipients];
[mail setSubject:@"Subject"];
[mail setMessageBody:bodyData isHTML:NO];
[self presentViewController:mail animated:YES completion:nil];
}
mail = nil;
return NSLog(@"%@",strEmail);
}
-(void)shareBySMS:(NSString *)strSMS {
if([strSMS length] > 0) {
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
if(picker) {
picker.messageComposeDelegate = self;
picker.recipients = @"Youre Recipients";
//picker.recipients = [NSArray arrayWithObject:tel];
picker.body = strSMS;
[self presentViewController:picker animated:NO completion:nil];
picker = nil;
}
NSLog(@"SMS fired");
}
}
#pragma mark Mail Composer Delegate Methods
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
// Notifies users about errors associated with the interface
switch (result) {
case MFMailComposeResultCancelled:
break;
case MFMailComposeResultSaved:
break;
case MFMailComposeResultSent:
break;
case MFMailComposeResultFailed:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Result: canceled");
break;
case MessageComposeResultSent:
NSLog(@"Result: sent");
break;
case MessageComposeResultFailed:
NSLog(@"Result: failed");
break;
default:
NSLog(@"Result: not sent");
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}