MFMessageComposeViewController alloc返回nil [英] MFMessageComposeViewController alloc returns nil

查看:94
本文介绍了MFMessageComposeViewController alloc返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,MFMailComposeViewController工作正常,但创建MFMessageComposeViewController的新实例失败。

In my application, MFMailComposeViewController works fine but creating a new instance of MFMessageComposeViewController fails.

以下是两者的代码:

-( IBAction)sendSMS: (id)sender
{
 MFMessageComposeViewController *picker = [[[MFMessageComposeViewController alloc] init] autorelease];
 picker.messageComposeDelegate = self;

 NSArray *toRecipients = [NSArray arrayWithObject: cell.currentTitle ]; 

 picker.recipients = toRecipients;

 [self presentModalViewController:picker animated:YES];
}

-( IBAction)sendEmail: (id)sender
{
 MFMailComposeViewController *picker = [[[MFMailComposeViewController alloc] init] autorelease];
 picker.mailComposeDelegate = self;

 NSArray *toRecipients = [NSArray arrayWithObject: email.currentTitle ]; 

 [picker setToRecipients:toRecipients];

 [self presentModalViewController:picker animated:YES];
}

由于电子邮件视图控制器工作正常,所以一切都正确链接似乎很明显。是否有一些我可能缺少配置的东西?

Its seemingly obvious that everything is linking correctly because the email view controller works fine. Is there something I am missing maybe configuration wise?

推荐答案

你检查过 + [MFMessageComposeViewController canSendText]

来自 MFMessageComposeViewController类参考


在呈现消息编写视图之前,调用 canSendText 类方法以确保正确配置用户的设备。如果canSendText方法返回NO,请不要尝试显示消息组合视图。如果短信发送不可用,您可以通知用户或只是禁用应用程序中的短信功能。

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.

从iOS 5开始,您可以注册以获得通知通过 MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification 通知更改发送短信的可用性。

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.

可能返回的原因 nil


  • 设备未运行iOS 4 。

  • 设备是没有启用iMessage的iPod Touch / iPad。

  • 没有SIM卡? (该视图现在显示在iOS 6中;应用程序未收到消息发送失败的通知。)

  • 设备实际上是模拟器。 (也许这也适用于iOS 6。)

  • Device isn't running iOS 4.
  • Device is an iPod Touch/iPad without iMessage enabled.
  • No SIM card? (The view now shows in iOS 6; the app is not notified of the message send failure.)
  • "Device" is actually the simulator. (Perhaps this works in iOS 6 too.)

同样, [[MFMailComposeViewController alloc] init] 在没有启用邮件帐户时返回 nil (您可以通过在设置中禁用帐户来快速测试),还会显示未配置邮件帐户警报为你。 MFMessageComposeViewController不会这样做。

Similarly, [[MFMailComposeViewController alloc] init] returns nil when no mail accounts are enabled (you can quickly test this by disabling accounts in Settings), but also shows a "No mail accounts configured" alert for you. MFMessageComposeViewController does not do this.

这篇关于MFMessageComposeViewController alloc返回nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆