我是 iphone 应用程序开发的新手。
我正在创建一个发送短信的应用程序。
在我的应用程序中,我需要在指定时间发送短信。
我有一个时间选择器来指定 UITextField 中的时间。
-(void)sendInAppSMS { NSLog(@"SendMessage");
if([textFieldRounded.text isEqualToString:@""] || [textFieldRounded1.text isEqualToString:@""] || [textFieldRounded2.text isEqualToString:@""] || [textFieldRounded.text isEqualToString:@"(null)"] || [textFieldRounded1.text isEqualToString:@"(null)"] || [textFieldRounded1.text isEqualToString:@"(null)"] || [textFieldRounded.text isEqualToString:nil] || [textFieldRounded1.text isEqualToString:nil]|| [textFieldRounded2.text isEqualToString:nil])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"SMS" message:@"Please Enter All Fields!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
else
{
NSLog(@"Done");
NSDateFormatter *SentTime = [[NSDateFormatter alloc] init];
[SentTime setDateFormat:@"dd/MM/YYYY hh:mm aa"];
NSDate *now1 = [NSDate date];
NSString *Time1 = [SentTime stringFromDate:now1];
NSLog(@"Time is :%@",Time1);
NSString *Sentime=[NSString stringWithFormat:@"%@",textFieldRounded2.text];
if([Sentime isEqualToString:Time1])
{
NSLog(@"Time Matching... can send msg now");
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
NSString *Message = [NSString stringWithFormat:@"%@, %@",textFieldRounded1.text,textFieldRounded2.text];
NSLog(@"Message is %@", Message);
controller.body = Message;
controller.recipients = [NSArray arrayWithObjects:@"+919999999999" , nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
else
{
NSLog(@"Send Message when time reach at %@",textFieldRounded2.text);
//Here What code i should write
}
}
}
如果时间等于当前时间,则立即发送短信(无需将消息存储在任何地方)。
否则,当当前时间变为指定时间时,我需要发送该短信。直到时间到达如何保存(存储)消息并按时发送。
问候,
拉金德兰