iOS开发之发送短信

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

    //  调用系统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(@"失败");  
        }  
      
    }