2012-06-21 59 views
0

在我的應用程序中使用MFMessageComposeViewController發送消息。 以下代碼爲i用於發送消息從iPhone發送消息到另一個手機

 MFMessageComposeViewController *msgController = [[[MFMessageComposeViewController alloc] init] autorelease]; 
     if([MFMessageComposeViewController canSendText]) 
     { 
      msgController.messageComposeDelegate = self; 
      msgController.body = [NSString stringWithFormat:@"%@", appDelegate.finalConactStr ]; 
      [self presentModalViewController:msgController animated:YES]; 
     } 

的例子和正在通過使用以下代碼

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result 
{ 
    switch (result) 
    { 
    case MessageComposeResultCancelled: 
     cancelAlert = [[UIAlertView alloc] initWithTitle:@"SMS a Contact" message:@"Cancelled"delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     [cancelAlert show]; 
     [cancelAlert release]; 
     NSLog(@"Result: canceled"); 
     break; 
    case MessageComposeResultSent: 
     successAlert = [[UIAlertView alloc]initWithTitle:@"SMS a Contact" message:@"Successfully sent" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [successAlert show]; 
     [successAlert release]; 
     NSLog(@"Result: sent"); 
     break; 
    case MessageComposeResultFailed: 
     failAlert = [[UIAlertView alloc]initWithTitle:@"SMS a Contact" message:@"Failed" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [failAlert show]; 
     [failAlert release]; 

     NSLog(@"Result: failed"); 
     break; 
    default: 
     notSentAlert = [[UIAlertView alloc]initWithTitle:@"SMS a Contact" message:@"Not Sent" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [notSentAlert show]; 
     [notSentAlert release]; 

     NSLog(@"Result: not sent"); 
     break; 
    } 
    [self dismissModalViewControllerAnimated:YES]; 
} 

但沒有SIM還它顯示像成功發送

警報檢查結果

我們怎樣才能檢查設備是否有SIM卡或消息發送功能是否存在。 任何人都可以幫忙或建議我。

在此先感謝。

回答

0

自Apple推出iMessage以來,所有可以運行iOS5的設備都將能夠通過MFMessageComposeViewController發送消息。

因此,沒有真正的需要檢查設備中是否安裝了SIM卡,只需相信[MFMessageComposeViewController canSendText]告訴您設備是否可以發送信息。

  • MessageComposeResultCancelled:用戶取消了構圖。
  • MessageComposeResultSent:用戶成功排隊或發送消息。
  • MessageComposeResultFailed:用戶嘗試保存或發送郵件失敗。
+0

但是當我在設備上運行它總是顯示成功發送。 –

+0

然後發送消息,你認爲爲什麼不發送? – rckoenes

+0

但沒有SIM卡,也沒有號碼也顯示成功發送。 –

相關問題