MFMessageComposeViewController 分配返回 nil

发布于 2024-09-15 03:27:09 字数 879 浏览 10 评论 0原文

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

这是两者的代码:

-( 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];
}

看起来很明显,一切都正确链接,因为电子邮件视图控制器工作正常。我是否缺少一些配置方面的东西?

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

Here is the code for both:

-( 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自在安然 2024-09-22 03:27:09

您检查过+[MFMessageComposeViewController canSendText]吗?

MFMessageComposeViewController 类参考

在显示消息撰写视图之前,调用 canSendText 类方法以确保用户的设备已正确配置。如果 canSendText 方法返回 NO,则不要尝试显示消息撰写视图。如果 SMS 传送不可用,您可以通知用户或简单地禁用应用程序中的 SMS 功能。

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

可能返回 nil 的原因:

  • 设备未运行 iOS 4。
  • 设备是未启用 iMessage 的 iPod Touch/iPad。
  • 没有SIM卡? (该视图现在在 iOS 6 中显示;应用程序不会收到消息发送失败的通知。)
  • “设备”实际上是模拟器。 (也许这也适用于 iOS 6。)

类似地,当没有启用邮件帐户时,[[MFMailComposeViewController alloc] init] 返回 nil(您可以通过禁用帐户来快速测试这一点)在“设置”中),同时还会向您显示“未配置邮件帐户”警报。 MFMessageComposeViewController 不执行此操作。

Have you checked +[MFMessageComposeViewController canSendText]?

From the MFMessageComposeViewController Class Reference,

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.

Reasons it might be returning nil:

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文