// 调用系统API发送短信 - (void)didClickSendMessageButtonAction{ if ([MFMessageComposeViewController canSendText] == YES) { MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init]; // 设置代理<MFMessageComposeViewControllerDelegate> messageVC.messageComposeDelegate = self; // 发送To Who messageVC.recipients = @[@"18757289870"]; messageVC.body = @"hello world"; [self presentViewController:messageVC animated:YES completion:nil]; }else{ NSLog(@"此设备不支持"); } } - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{ switch (result) { case MessageComposeResultCancelled: NSLog(@"取消发送"); break; case MessageComposeResultFailed: NSLog(@"发送失败"); break; case MessageComposeResultSent: NSLog(@"发送成功"); break; default: break; } [self dismissViewControllerAnimated:YES completion:nil]; } // 调用系统应用程序发送消息 - (void)didClickSendMessage2ButtonAction{ NSURL *url = [NSURL URLWithString:@"sms:18656348970"]; if ([[UIApplication sharedApplication] canOpenURL:url] == YES) { [[UIApplication sharedApplication] openURL:url]; }else{ NSLog(@"失败"); } }
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/3391.html