我正在为iphone写一个应用程序,我需要在某个时间间隔内自动发送电子邮件和短信到一个号码和电子邮件ID。但每次在一段时间后进入该部分时,电子邮件和短信都会出现弹出窗口,当我按下发送按钮时,只有它发送电子邮件或短信。
如何让它自动化,这样我就不必再次按下发送按钮,它会自动执行操作。我发现这段代码用于发送电子邮件和短信,我只是为了我的目的而使用此代码。如何修改它以使其自动化。
//
// MessageViewController.m
// EmailExample
//
// Copyright http://iphoneapp-dev.blogspot.com. All rights reserved.
//
#import "MessageViewController.h"
@implementation MessageViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Message sending";
}
- (IBAction)btnEmail_Clicked:(id)sender
{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:[NSArray arrayWithObject:@"user@gmail.com"]];
[controller setSubject:@"iPhone Email Example Mail"];
[controller setMessageBody:@"http://iphoneapp-dev.blogspot.com" isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
}
- (IBAction)btnMessage_Clicked:(id)sender
{
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"Hello Friends this is sample text message.";
controller.recipients = [NSArray arrayWithObjects:@"+919999999999", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultFailed:
NSLog(@"Failed");
break;
case MessageComposeResultSent:
NSLog(@"Send");
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
if (result == MFMailComposeResultSent) {
NSLog(@"It's away!");
}
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)btnCall_Clicked:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"+919999999999"]];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
答案 0 :(得分:3)
如果可能的话,您可以向高级服务发送一些SMS
,并且用户可能会收到高额的电话费。这就是为什么Apple不允许这样做的原因。
如果您通过服务器发送SMS
/电子邮件,或者直接通过SMTP
发送电子邮件,则可以执行此操作。
答案 1 :(得分:0)
// Build request
NSString *urlString = [NSString stringWithFormat:@"https://%@:%@@api.twilio.com/2010-04-01/Accounts/%@/SMS/Messages", kTwilioSID, kTwilioSecret, kTwilioSID];
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostFormat:NSUTF8StringEncoding];
[request setPostValue:kFromNumber forKey:@"From"];
[request setPostValue:kToNumber forKey:@"To"];
[request setPostValue:kMessage forKey:@"Body"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestFail:)];
hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//hud.mode = MBProgressHUDModeAnnularDeterminate;
hud.labelText = @"Please wait...";
hud.detailsLabelText = @"Sending message";
hud.delegate = self;
hud.square = NO;
hud.dimBackground = YES;
[request startAsynchronous];
您可以根据需要使用此代码并更改参数,我希望这可以帮助您发送短信。