2013-10-21 29 views
6

我现在以很长时间以编程方式发送短信。它在iOS6中没有任何问题。在iOS7中发送短信 - 从iOS6升级后出现问题

但是现在更新到iOS7后,一些用户对应用程序有疑问。他们需要卸载应用程序 - 重新启动iPhone - 重新安装它,然后它可以工作。只需重新安装它,而无需重新启动手机也不起作用。

什么可能是这个真正恼人的问题的原因?

此外,还有一些情况下,他们可以在此程序后发送几条短信,但然后iPhone短信对话显示得非常慢,并且没有再发送短信,直到他们重新启动iPhone。只是停止并重新启动应用程序并没有帮助。

这里是正常的短信代码:

MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init]; 
[messageVC setMessageComposeDelegate:self]; 
if ([MFMessageComposeViewController canSendText]) { 

    NSString *smsString = [NSString stringWithFormat:@"bla bla bla"]; 
    messageVC.body = smsString; 
    messageVC.recipients = @[userPhone]; 
    messageVC.messageComposeDelegate = self; 
[self presentViewController:messageVC animated:YES completion:nil]; 
} 

我甚至发布应用程序的新版本与最新的Xcode 5.0的部署目标5.1,因为我需要支持iOS5.1用户仍。

+0

我也遇到过这个问题。你有没有发现它周围的东西? – Teddy

+1

还没有 - 我在11月提交了一个bug报告 - 但苹果一直忽略它 - 没有其他应用程序可以发送短信在这种情况下 - 惊人的是,苹果逃脱这个如此安静... – user387184

+0

我从来没有向苹果报告错误。我应该在哪里尝试?在苹果bug记者 – Teddy

回答

0

没有足够的信息来说明造成问题的原因。顺便说一句,你为什么设置messageComposeDelegate两次?

这是苹果最近的示例代码,我修改了自己运行iOS 7和iOS 8的设备。确保导入MessageUI.framework。

/* ------------------------------------------------------------------------------- 
    showSMSPicker: 
    IBAction for the Compose SMS button. 
    ------------------------------------------------------------------------------- */ 
- (IBAction)showSMSPicker:(id)sender 
{ 
    /* Checks that the current device can send SMS messages. If no, [[MFMessageComposeViewController alloc] init] will return nil and the app will 
    crash when -presentViewController:animated:completion: is called with a nil view controller */ 

    if ([MFMessageComposeViewController canSendText]) 
     // The device can send email. 
    { 
     [self displaySMSComposerSheet]; 
    } 
    else 
     // The device can not send email. 
    { 
     self.feedbackMsg.hidden = NO; 
     self.feedbackMsg.text = @"Device not configured to send SMS."; 
    } 
} 


/* ------------------------------------------------------------------------------- 
    displayMailComposerSheet 
    Displays an SMS composition interface inside the application. 
    ------------------------------------------------------------------------------- */ 

- (void)displaySMSComposerSheet 
{ 
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init]; 
    picker.messageComposeDelegate = self; 

    /* One or more preconfigured recipients can be specified. The user has the option to remove 
    or add recipients from the message composer view controller */ 
    /* picker.recipients = @[@"Phone number here"]; */ 

    // Message body 
    picker.body = @"This is a message about how great this app is. Please download it by clicking on the link below."; 

    [self presentViewController:picker animated:YES completion:nil]; 
} 

/* ------------------------------------------------------------------------------- 
    messageComposeViewController:didFinishWithResult: 
    Dismisses the message composition interface when users tap Cancel or Send. 
    Proceeds to update the feedback message field with the result of the 
    operation. 
    ------------------------------------------------------------------------------- */ 

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller 
       didFinishWithResult:(MessageComposeResult)result 
{ 
    self.feedbackMsg.hidden = NO; 
    // Notifies users about errors associated with the interface 
    switch (result) 
    { 
     case MessageComposeResultCancelled: 
      self.feedbackMsg.text = @"Result: SMS sending canceled"; 
      break; 
     case MessageComposeResultSent: 
      self.feedbackMsg.text = @"Result: SMS sent"; 
      break; 
     case MessageComposeResultFailed: 
      self.feedbackMsg.text = @"Result: SMS sending failed"; 
      break; 
     default: 
      self.feedbackMsg.text = @"Result: SMS not sent"; 
      break; 
    } 

    [self dismissViewControllerAnimated:YES completion:NULL]; 
}