当用户询问并弹出撰写视图时,我的应用程序将发送一条短信。我可以使用此代码来执行此操作,并将硬编码的数字和消息设置为默认值:
[self sendSMS:@"messageTextGoesHere" recipientList:[NSArray arrayWithObjects:@"phoneNumberGoesHere", nil]];
和
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
[controller dismissViewControllerAnimated:YES completion:nil];
}
但我想要做的是将收件人和消息设置为 NSUserDefaults 字符串。这是我尝试过的:
NSString *messageNumbers = [[NSUserDefaults standardUserDefaults] objectForKey:@"phoneNumber"];
NSString *textMessage = [[NSUserDefaults standardUserDefaults] objectForKey:@"messageText"];
[self sendSMS:textMessage recipientList:[NSArray arrayWithObjects:messageNumbers, nil]];
而不是通常的弹出消息编辑器,它会挂起一会儿,然后屏幕变黑,所以你必须退出应用程序。控制台给了我这个:
2013-10-27 17:29:45.428 *APP*[4006:60b] <CKSMSComposeRemoteViewController: 0x1844fb90> timed out waiting for fence barrier from com.apple.mobilesms.compose
2013-10-27 17:29:45.936 *APP*[4006:60b] Warning: Attempt to dismiss from view controller <ViewController: 0x14e02700> while a presentation or dismiss is in progress!
有人可以告诉我我做错了什么或者我是否需要使用不同的代码?
谢谢!