发布网友 发布时间:2024-10-04 17:06
共1个回答
热心网友 时间:2024-10-04 17:12
如何利用系统的Message进行短信发送1、导入包 MessageUI.framework2、主要内容(1) 代码主题部分 MFMessageComposeViewController* controller = [[MFMessageComposeViewControlleralloc] init]; //Before presenting a message composition view, call the canSendText class method to ensure that the user’s device is appropriately configured if ([MFMessageComposeViewControllercanSendText]) { //The initial content of the message controller.body = message; //An array of strings containing the initial recipients of the message. controller.recipients = substrings; // 代理方法 controller.messageComposeDelegate = self; [selfpresentModalViewController:controller animated:YES];(2) 执行代理方法 //Tells the delegate that the user finished composing the message -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [selfdismissModalViewControllerAnimated:YES]; if (result == MessageComposeResultCancelled) NSLog(@"Message cancelled"); elseif (result == MessageComposeResultSent) NSLog(@"Message sent"); else NSLog(@"Message failed"); }总结:(1) 发送短信之前,需要验证设备是否具有发送短信的能力(2) property Message 即为短信的内容(3) property recipents 即为短信的发送人信息,注意,其类型为NSArray2013 - 01 - 02上岛