在iphone中以编程方式发送短信

你怎样才能以编程方式发送短信到iPhone中的联系人列表中select的特定号码?

MFMessageComposeController是你在找什么。

要发送短信,你正在看这样的事情:

 #import <MessageUI/MessageUI.h> @interface myClass : NSObject <MFMessageComposeViewControllerDelegate>{ } @end @implementation -(void)sendMessage{ if([MFMessageComposeController canSendText]){ MFMessageComposeController *smsComposer = 
[[MFMessageComposeController alloc] init]; smsComposer.recipients = [NSArray arrayWithObject:@"12345678"]; smsComposer.body = @"SMS BODY HERE"; smsComposer.delegate = self; [self presentModalViewController:smsComposer animated:NO]; } else{ //You probably want to show a UILocalNotification here. } } - (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result{ /* You can use the MessageComposeResult to determine what happened to the
message. I believe it tells you about sent, stored for sending later, failed
or cancelled. */ [self dismissModalViewControllerAnimated:NO]; } @end

这是目前从您的应用程序发送短信的唯一方法。 除非你只是想打开短信应用程序。 如果你不担心信息的正文,你可以这样做:

 NSString *smsURL = @"sms:12345678"; NSURL *url = [NSURL URLWithString:smsURL]; [[UIApplication sharedApplication] openURL:url]; 

呃…我想在这里稍微讨论会有帮助。 我(可能是错误地)采取的问题,“…以编程方式发送短信…”意味着在幕后发送短信,MFMessageComposeViewControllerpopup。

上面的答案的绿色复选标记是不正确的,如果这是问题。 我会假设这是一个问题(我敢打赌,我不是唯一的),并提供一些子弹,以节省时间,我花了到这里来。

  1. 在堆栈中有一些讨论 ,无法在iOS中完成。 在这里
  2. Android的cordova插件做得很好
  3. iOS的cordova插件没有(暗示它不能完成)。
  4. 上面的代码没有办法运行。 它是一种伪代码。 在presentModalViewController上的animation:NO,防止vcpopup,但我总是最终在与MessageCancelled didFinishWithResult。
  5. 苹果公司为了防止这种情况的性质是正确的。