iphone - 如何在特定时间发送短信

标签 iphone objective-c ios nsdateformatter

我是 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
    }
}

}

如果时间等于当前时间,则立即发送短信(无需在任何地方存储消息)。

否则,当当前时间变为指定时间时,我需要发送该短信。直到到达如何保留(存储)消息并按时发送的时间。

问候,

拉金德兰.B

最佳答案

您无法在 iOS 中使用计时器发送短信,Apple 不允许此功能。

see this

关于iphone - 如何在特定时间发送短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13559500/

相关文章:

php - Objective-C->JSON->PHP 数组

ios - 为什么 breaking-retain-cycle 不会像这样陷入无限循环?

iphone - 如何在 iPhone 上设置按钮背景颜色?

ios - IBAction 不让我进入下一页? swift Xcode

iphone - 有没有办法以编程方式(通过应用程序)添加 AppStore 评论?

iphone - 应用商店名称和info.plist

ios - 当搜索栏文本为空时,UISearchController searchResultsController 消失

ios - iOS 13:如何检测“语音控制”是否正在运行

ios - 将 DatePicker 日期转换为 UTC 格式返回 NULL

ios - 如何检索healthkit数据并显示?