[英]sending sms programmatically in iphone
如何通过编程方式将短信发送到iPhone中联系人列表中选择的特定号码?
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
目前,这是从您的应用发送短信的唯一方法。 除非您只想打开SMS应用程序。 如果您不担心邮件的正文,可以执行以下操作:
NSString *smsURL = @"sms:12345678";
NSURL *url = [NSURL URLWithString:smsURL];
[[UIApplication sharedApplication] openURL:url];
嗯...我认为在这里进行一些讨论会有所帮助。 我(可能是错误地)提出了一个问题,“ ...以编程方式发送SMS ...”是指在幕后发送SMS,然后弹出MFMessageComposeViewController。
如果这是问题所在,则以上答案的绿色复选标记是不正确的。 我将假设这就是问题所在(我敢打赌我不是唯一的一个),并提供一些子弹来节省其他人花在我这里的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.