iOS发送短信

时间:2023-03-08 22:17:04
iOS发送短信
iPhone开发,发送短信的方法:
iPhone开发中,发送短信方法有二:
1。URL Scheme,这样不可以设置短信内容
1
2
3
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://10086"]];
//打电话可以这样
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];
2。MFMessageComposeViewController,这样可以设置短信的内容
1
2
3
4
5
6
7
8
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
        if ([MFMessageComposeViewController canSendText])        {
            if (![self.friendLabel.text isEqualToString:@"{好友}"])
                controller.recipients = [NSArray arrayWithObjects:self.friendLabel.text, nil];
                controller.body = self.shareMessageTextView.text;
                controller.messageComposeDelegate = self;
                [self presentModalViewController:controller animated:YES];
        }