iOS 在单一操作中触发电子邮件和短信

发布于 2025-01-08 18:14:27 字数 2253 浏览 1 评论 0原文

首先感谢您对以下查询的帮助。

我正在开发一个 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 技术交流群。

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

发布评论

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

评论(3

有深☉意 2025-01-15 18:14:27

我认为动画导致短信模式的显示发生冲突。另外,dismissModalViewController 已被弃用,因此请使用:

[self dismissViewControllerAnimated:YES completion:^ {
        [self sendSMS];
}]; 

I believe that the animation is causing the display of the SMS modal to conflict. Also dismissModalViewController is deprecated so use:

[self dismissViewControllerAnimated:YES completion:^ {
        [self sendSMS];
}]; 
太阳哥哥 2025-01-15 18:14:27

在显示 SMS 消息模式之前尝试关闭邮件模式。

- (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 dismissModalViewControllerAnimated:YES]; 
[self showSMSPicker];

Try dismissing the Mail Modal before presenting the SMS Message modal.

- (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 dismissModalViewControllerAnimated:YES]; 
[self showSMSPicker];
南巷近海 2025-01-15 18:14:27

我使用了一种调整方法来完成此任务,创建了一个布尔值(如果设置为 true),然后在 ViewDIDAppear 方法中调用 showSMS 方法

  - (void) viewDidAppear:(BOOL)animated
{
   if (self.isSMSRequired) {
      [self showSMSPicker];
       self.isSMSRequired = FALSE;
    }
}

,并在

- (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.isSMSRequired = TRUE;
[self dismissModalViewControllerAnimated:YES]; 

此工作...

I used a tweak method to get this accomplished, created a boolean if set to true then in ViewDIDAppear method call showSMS method

  - (void) viewDidAppear:(BOOL)animated
{
   if (self.isSMSRequired) {
      [self showSMSPicker];
       self.isSMSRequired = FALSE;
    }
}

and in

- (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.isSMSRequired = TRUE;
[self dismissModalViewControllerAnimated:YES]; 

This worked...

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