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

查看:12
本文介绍了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,请不要尝试显示消息组合视图.如果 SMS 传送不可用,您可以通知用户或直接在您的应用程序中禁用 SMS 功能.

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.)

同样,[[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天全站免登陆