Iphone 如何在特定时间发送短信

Iphone 如何在特定时间发送短信,iphone,objective-c,ios,nsdateformatter,Iphone,Objective C,Ios,Nsdateformatter,我是iphone应用程序开发新手 我正在创建一个应用程序来发送短信 在我的应用程序中,我需要在指定的时间发送短信 我有一个时间选择器来指定UITextField中的时间 -(无效)sendInAppSMS { NSLog(@“发送消息”) } 如果时间等于当前时间,则立即发送短信(无需将短信存储在任何位置) 另一方面,当当前时间变为指定时间时,我需要发送短信。直到时间到达,如何保存(存储)信息并按时发送 问候, Rajendran.B你不能在iOS中使用定时器发送短信,苹果不允许使用此功能 就用

我是iphone应用程序开发新手

我正在创建一个应用程序来发送短信

在我的应用程序中,我需要在指定的时间发送短信

我有一个时间选择器来指定UITextField中的时间

-(无效)sendInAppSMS { NSLog(@“发送消息”)

}

如果时间等于当前时间,则立即发送短信(无需将短信存储在任何位置)

另一方面,当当前时间变为指定时间时,我需要发送短信。直到时间到达,如何保存(存储)信息并按时发送

问候,


Rajendran.B

你不能在iOS中使用定时器发送短信,苹果不允许使用此功能


就用户体验而言,您的代码不太可能允许用户发送消息,除非当前时间与指定时间的精确分钟相匹配。检查时间是在指定时间之后还是在指定时间的某个范围内更有意义。同样值得注意的是,如果不比较字符串文字,那么进行这些比较会更容易。(使用NSDate和相关方便方法进行这些比较)


就在特定时间发送消息而言,这可能需要一个服务器组件,您在其中注册要发送的消息和应该发送的时间,然后以指定的间隔处理消息发送队列中的消息。

正如其他答案中指出的,不可能“保存”用户在
MFMessageComposeViewController
中编写的消息,以供以后发送(也没有其他方法)

你的选择是:

  • 提前收集SMS的详细信息,然后在正确的时间提示用户。如果应用程序可能已关闭,您可以为此使用
    UILocalNotification
    。您可以在
    MFMessageComposeViewController
    实例上使用
    setTitle:
    setBody:
    setRecipients:
    打开预先填充了正确详细信息的邮件,因此用户只需点击send

  • 将消息详细信息发送回服务器,并使用一些SMS系统(如api)在正确的时间发送SMS。这将大大增加复杂性,而且短信不会来自用户的电话号码


是的,我刚刚发布了这篇文章。请分享您的努力并编写一些代码。textFieldRounded2.text这包含指定的时间。。。
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
    }
}