reason: 'Unknown key, "NSColor" in title text attributes dictionary

iOS 6 和 iOS 7 兼容性问题,在调用内部发短信接口时候,出现了异常崩溃,原来一直在iOS7 下测试,一切正常,但是在iOS 6下却突然崩溃,具体代码如下:

- (void)showMessageViewWithRecipients:(NSArray *)recipients body:(NSString *)bodyMess
{
    if( [MFMessageComposeViewController canSendText] ){
  	  <span style="font-family: Arial, Helvetica, sans-serif;"> [[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];</span>
            [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor darkGrayColor],NSForegroundColorAttributeName,		[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
 
        MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
        controller.recipients = recipients;
        controller.body = bodyMess;
        controller.messageComposeDelegate = self;
        [self presentViewController:controller animated:NO completion:nil];
        
    }else{
        [self alertWithTitle:@"提示信息" msg:@"设备没有短信功能"];
    }
}

注意:中间有一段是设置短信导航标题的代码,然后爆出如下异常:

Assertion failure in NSDictionary *_UIRecordArgumentOfInvocationAtIndex(NSInvocation *, NSUInteger, BOOL)(), /SourceCache/UIKit/UIKit-2380.17/UIAppearance.m:1118
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unknown key, "NSColor" in title text attributes dictionary'

解决方案如下即可:

1,删除这段修改短信标题的代码,似乎不起作用,汗..

2,版本判断   #define OS_VERSION [[UIDevice currentDevice].systemVersion floatValue]

- (void)showMessageViewWithRecipients:(NSArray *)recipients body:(NSString *)bodyMess
{
    if( [MFMessageComposeViewController canSendText] ){
        
        
        if (OS_VERSION>=7.0) {
            [[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
            [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor darkGrayColor],NSForegroundColorAttributeName,[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
        }

        MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
        controller.recipients = recipients;
        controller.body = bodyMess;
        controller.messageComposeDelegate = self;
        [self presentViewController:controller animated:NO completion:nil];
        
    }else{
        [self alertWithTitle:@"提示信息" msg:@"设备没有短信功能"];
    }
}


即可适配 iOS6 和 iOS 7 发送短信功能。


个人开发者梦工厂之 微推:www.micropush.cn



你可能感兴趣的:(reason: 'Unknown key, "NSColor" in title text attributes dictionary)