如何在iOS中设置闹钟

如何在iOS中设置闹钟

本文介绍了如何在iOS中设置闹钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题多次在 StackOverflow 上问过,但我无法在我的应用中设置闹钟,因为我对iOS很新?我正在按照本教程设置警报:

I know this question has asked many times on StackOverflow but i couldn't able to set alarm in my app because i am very new to iOS? I am following this tutorial to set an alarm:

然而,它似乎对我不起作用。

However, it doesn't seems to be working for me.

我需要每天设置闹钟,让我们每天说 5.00 PM 。我不能使用日期选择器来选择时间。

I am in need to set alarm daily lets say 5.00 PM daily. I can't use date picker for choosing the time.

推荐答案


  1. 首先在你的 xib ,(或代码)设置日期选择器模式:时间(默认为日期和时间)

  1. First on your xib, (or code) set the date picker mode: Time (Default is date & time)

系统假定fireate是当前日期,时间是用户选择的时间。这不是问题,因为您设置了重复间隔,因此它将起作用。我测试了它。

The system assumes that the firedate is the current date, and the time is the time the user have chosen. This is not a problem because you set a repeat interval so it will work. I have tested it.

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
[localNotif setFireDate:datePicker.date];
[localNotif setRepeatInterval:NSDayCalendarUnit];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];


PS:这是一个好主意使用 NSDateComponents 类将秒设置为 0 ,以便将闹钟设置为在您的第一分钟响铃想。您可以查看:

PS: It would be a good idea to set the seconds to 0 using NSDateComponents class so as to set the alarm to ring at the first second of the minute you want. You can check the:

您发布的教程关于如何做到这一点。

tutorial you posted on how to do this.

这篇关于如何在iOS中设置闹钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:22