2011-10-22 162 views
1

我一直在將SMS消息傳遞到我的應用程序中。不幸的是,無論什麼時候我測試它,我總是會得到默認結果,即使它發送了消息並且我在另一端收到它。我做錯了什麼,我比較了其他的例子,我的外表看起來一樣。 這是否適用於iMessage?現在,即使我發短信,我也會一直收到它,因爲它會說失敗。發送短信

// feedback message field with the result of the operation. 
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller 
      didFinishWithResult:(MessageComposeResult)result { 

switch (result) 
{ 

    case MFMailComposeResultCancelled:   

     [self displayStickieUniversalViewControllerTitleString:@"Cancelled" bodyString:@"You cancelled sending the SMS.The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3]; 

     break; 
    case MFMailComposeResultSent: 

     [self displayStickieUniversalViewControllerTitleString:@"SMS sent" bodyString:@"Your SMS was sent. The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3]; 

     break; 
    case MFMailComposeResultFailed: 
     [self displayStickieUniversalViewControllerTitleString:@"Failed" bodyString:@"Failed to send SMS. The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3]; 

     break; 
    default: 
     [self displayStickieUniversalViewControllerTitleString:@"Failed" bodyString:@"Failed to send SMS. The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3];  
     break; 

} 
[self dismissModalViewControllerAnimated:YES]; 
    } 

/////

if (actionClicked == @"smsEvent") { 
    if ([attendeesArray count]!=0) { 
     NSLog(@"Yes clicked, will send sms confirmation"); 
     Class messageClass = (NSClassFromString(@"MFMessageComposeViewController")); 

     if (messageClass != nil) {   
      if ([messageClass canSendText]) { 
       [self displaySMSComposerSheet]; 
      } 
      else { 

       [self displayStickieUniversalViewControllerTitleString:@"Device not configured to send SMS." bodyString:@"The event will be saved in the calendar." buttonString:@"Save Event" bodyTextSize:14.0f buttonTextLines:2]; 

      } 
     } 
     else { 

     [self displayStickieUniversalViewControllerTitleString:@"Device not configured to send SMS." bodyString:@"The event will be saved in the calendar." buttonString:@"Save Event" bodyTextSize:14.0f buttonTextLines:2]; 
     } 

       } 
} 
+0

嘗試檢查,看看有什麼你的結果實際上是......'default'只是一個全面的情況,如果switch參數與任何情況都不匹配,那麼它將被執行。 –

+1

您是否測試過您是否可以發送短信? Doc:在呈現消息組合視圖之前,調用canSendText類方法以確保用戶的設備已正確配置。如果canSendText方法返回NO,則不要嘗試呈現消息組合視圖。如果短信傳送不可用,您可以通知用戶或者簡單地禁用應用程序中的SMS功能。 – jbat100

+0

我已經有應用程序中的東西來捕捉它不能發送短信。我如何打印出真正的結果。 –

回答

0

看起來你使用了錯誤的枚舉或許真的用它做我的是這樣的:

switch (result) 
{ 
    case MessageComposeResultCancelled: 
     break; 
    case MessageComposeResultSent: 
     break; 
    case MessageComposeResultFailed: 
     break; 
    default: 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"SMS" message:@"Sending Failed - Unknown Error :-(" 
                 delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     [alert show]; 
     [alert release]; 
    } 

     break; 
}