2013-10-21 52 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]; 
}