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卡或消息發送功能是否存在。 任何人都可以幫忙或建議我。
在此先感謝。
但是當我在設備上運行它總是顯示成功發送。 –
然後發送消息,你認爲爲什麼不發送? – rckoenes
但沒有SIM卡,也沒有號碼也顯示成功發送。 –