iOS 在单一操作中触发电子邮件和短信
首先感谢您对以下查询的帮助。
我正在开发一个 iPhone 应用程序,其中要求用户单击按钮,应用程序应调出带有默认测试的电子邮件面板,一旦用户决定“发送”或“取消”,应用程序应调出短信面板供用户执行操作“ “发送”或“取消”
应用程序确实会以默认文本滑入电子邮件窗口,并且一旦用户按下“发送”或“取消”程序就会返回到方法“didFinishWithResult”,但稍后不会显示 SMS 窗口。当我评论发送邮件并直接跳转到短信应用程序时,确实会显示短信窗口。
我相信这是因为当应用程序请求电子邮件时,它会启动不同的线程,然后当线程返回到 didFinishWithResult 方法时,发送短信不起作用。我不知道如何解决这个问题。
请帮助,
- (void) mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Result: Mail sending canceled");
break;
case MFMailComposeResultSaved:
NSLog(@"Result: Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Result: Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Result: Mail sending failed");
break;
default:
NSLog(@"Result: Mail not sent");
break;
}
[self showSMSPicker]; <<<<<====== call for SMS
[self dismissModalViewControllerAnimated:YES];
之后代码正确地流向方法 [self showSMSPicker]。在showSMSPicker方法中
-(void)showSMSPicker {
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if (messageClass != nil) {
// Check whether the current device is configured for sending SMS messages
if ([messageClass canSendText]) {
MFMessageComposeViewController *smsComposer = [[MFMessageComposeViewController alloc] init];
smsComposer.messageComposeDelegate = self;
if([MFMessageComposeViewController canSendText]) {
smsComposer.body = @"Sending SMS";
smsComposer.recipients = [NSArray arrayWithObjects:@"12345678", @"87654321", nil];
smsComposer.messageComposeDelegate = self;
[self presentModalViewController:smsComposer animated:YES];
}
[smsComposer release];
}
else {
NSLog( @"Device not configured to send SMS.");
}
}
else {
NSLog(@"Device not configured to send SMS.");
}
}
Firstly appreciate your help with regard to below query.
I am developing a iPhone app where requirement is that user will click a Button and application should bring up Email panel with default test and once user decides to "send" or "cancel", application should bring up SMS panel for user to action either "Send" or "Cancel"
Application does slide in eMail window with default text and once user presses "Send" or "Cancel" program flow back to Method "didFinishWithResult" but later SMS Window is not displayed. When I comment send of Mail and directly jump to SMS application does display SMS window.
I believe it is because when application request for eMail it starts different thread and later when thread returns back to didFinishWithResult method sending SMS is not working. I am not sure how to solve this problem..
Please help
- (void) mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Result: Mail sending canceled");
break;
case MFMailComposeResultSaved:
NSLog(@"Result: Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Result: Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Result: Mail sending failed");
break;
default:
NSLog(@"Result: Mail not sent");
break;
}
[self showSMSPicker]; <<<<<====== call for SMS
[self dismissModalViewControllerAnimated:YES];
after which Code correctly flows to method [self showSMSPicker]. In showSMSPicker method
-(void)showSMSPicker {
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if (messageClass != nil) {
// Check whether the current device is configured for sending SMS messages
if ([messageClass canSendText]) {
MFMessageComposeViewController *smsComposer = [[MFMessageComposeViewController alloc] init];
smsComposer.messageComposeDelegate = self;
if([MFMessageComposeViewController canSendText]) {
smsComposer.body = @"Sending SMS";
smsComposer.recipients = [NSArray arrayWithObjects:@"12345678", @"87654321", nil];
smsComposer.messageComposeDelegate = self;
[self presentModalViewController:smsComposer animated:YES];
}
[smsComposer release];
}
else {
NSLog( @"Device not configured to send SMS.");
}
}
else {
NSLog(@"Device not configured to send SMS.");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为动画导致短信模式的显示发生冲突。另外,dismissModalViewController 已被弃用,因此请使用:
I believe that the animation is causing the display of the SMS modal to conflict. Also dismissModalViewController is deprecated so use:
在显示 SMS 消息模式之前尝试关闭邮件模式。
Try dismissing the Mail Modal before presenting the SMS Message modal.
我使用了一种调整方法来完成此任务,创建了一个布尔值(如果设置为 true),然后在 ViewDIDAppear 方法中调用 showSMS 方法
,并在
此工作...
I used a tweak method to get this accomplished, created a boolean if set to true then in ViewDIDAppear method call showSMS method
and in
This worked...