MFMessageComposeViewController在iOS 6中崩溃

时间:2014-05-21 05:11:02

标签: ios sms

我使用以下功能发送短信。

if([MFMessageComposeViewController canSendText])
{
     MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
    controller.body = @"SMS Text";

    controller.messageComposeDelegate = (id)self;
    [self presentViewController:controller animated:TRUE completion:nil];
}

它在iOS 7及更高版本中运行良好。但它在6.0.1上运行的iPod崩溃并出现错误

  

* * NSDictionary中的断言失败* _UIRecordArgumentOfInvocationAtIndex(NSInvocation *,NSUInteger,BOOL)(),/ SourceCache / UIKit / UIKit-2372 / UIAppearance.m:1118

2014-05-21 11:33:38.170项目[764:4913] *由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'未知密钥,“NSColor”在标题文本属性字典中' * 第一次抛出调用堆栈: (0x36c922a3 0x3346997f 0x36c9215d 0x383b430b 0x37717925 0x37716a7b 0x36c8f62f 0x377167f5 0x377f45e5 0x37782cd7 0x37782b6d 0x359d390f 0x37782a61 0x3778c0d5 0x359c683b 0x3778c0b1 0x359c611f 0x359c599b 0x359c5895 0x359d4215 0x359d43b9 0x36163a11 0x361638a4) libc ++ abi.dylib:terminate调用抛出异常

任何帮助都会很明显

3 个答案:

答案 0 :(得分:1)

可能的原因是您的选择器是nil。该代码仅适用于可以发送文本的设备。对于相同的情况,您应该始终使用[MFMessageComposeViewController canSendText]检查邮件发送功能,然后才显示选择器。来自Apple的MFMessageComposeViewController文档:

Before presenting a message composition view, call the canSendText class method to ensure that the user’s device is appropriately configured. Do not attempt to present a message composition view if the canSendText method returns NO. If SMS delivery isn’t available, you can notify the user or simply disable the SMS features in your application.

Starting in iOS 5, you can register to be notified of changes to the availability of text message sending by way of the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification notification.

编辑: 使用UITextAttributeTextColor代替NSForegroundColorAttributeName,无论您使用应用中的NSForegroundColorAttributeName方法设置UIAppearance,都应该修复错误。

答案 1 :(得分:0)

你不能在iPod上使用短信,它只适用于iPhone。你应该这样做: -

 MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];

 if([MFMessageComposeViewController canSendText])
  {
   //TODO: your other code
    controller.body = @"SMS Text";
    controller.messageComposeDelegate = self;
    [self presentViewController:picker animated:YES completion:NULL];
  }

确保在视图控制器的标题上实现 MFMessageComposeViewControllerDelegate

以下链接也可能有所帮助: -

  1. Weird MFMailComposeViewController Crash
  2. MFMailComposeViewController Crashes because of Global Appearance Properties on iOS6

答案 2 :(得分:0)

试试这个:

if ([MFMessageComposeViewController canSendText])
// The device can send sms.
{
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;

// You can specify one or more preconfigured recipients.  The user has
// the option to remove or add recipients from the message composer view
// controller.
// You can specify the initial message text that will appear in the message
// composer view controller.

picker.body = @"Hello Text";

[self presentViewController:picker animated:YES completion:NULL];
}

您检查过+[MFMessageComposeViewController canSendText]吗?

参考:

canSendText

Returns a Boolean value indicating whether the current device is capable of sending text messages. + (BOOL)canSendText

返回值

YES if the device can send text messages or NO if it cannot. Discussion

Always call this method before attempting to present the message compose view controller. A device may be unable to send messages if it does not support messaging or if it is not currently configured to send messages. This method applies only to the ability to send text messages via iMessage, SMS, and MMS.

To be notified of changes in the availability of sending text messages, register as an observer of the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification notification. Availability

Available in iOS 4.0 and later.
Declared In MFMessageComposeViewController.h