iPhone發送短信實現
我們知道可以使用這樣的代碼在iphone中發送短信:
[[UIApplication sharedApplication] openURL:@"sms:12345678"];
但這樣的方式無法指定短信內容。那么我們可以使用MessageUI框架。
首先在程序中導入MessageUI.framework。import頭文件:#import "DeviceDetection.h"
然后在代碼中使用下面的語句來調用短信發送窗口,并指定號碼和短信內容:
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease]; controller.body = @"zc"; controller.recipients = [NSArray arrayWithObjects:@"106295598", nil]; controller.messageComposeDelegate = self; [self presentModalViewController:controller animated:YES];
同時實現協議MFMessageComposeViewControllerDelegate, 在協議方法messageComposeViewController:didFinishWithResult:
switch (result) { case MessageComposeResultCancelled: NSLog(@"Cancelled"); break; case MessageComposeResultFailed: [self alert:@"發送短信錯誤!"]; break; case MessageComposeResultSent: break; default: break; } [self dismissModalViewControllerAnimated:YES];
本文由用戶 plnc5486 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!