且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从iPhone应用程序发送彩信

更新时间:2022-12-21 10:24:16

这样可以正常工作

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; 
pasteboard.persistent = YES;
pasteboard.image = [UIImage imageNamed:@"PDF_File.png"];

NSString *phoneToCall = @"sms:";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];    

if([MFMessageComposeViewController canSendText]) {
    NSMutableString *emailBody = [[NSMutableString alloc] initWithString:@"Your Email Body"];
    picker.messageComposeDelegate = self;
    picker.recipients = [NSArray arrayWithObject:@"123456789"];
    [picker setBody:emailBody];// your recipient number or self for testing
    picker.body = emailBody;
    NSLog(@"Picker -- %@",picker.body);
    [self presentModalViewController:picker animated:YES];
    NSLog(@"SMS fired");
}