如何在 iOS 中设置闹钟? [英] How to set an Alarm in iOS?

查看:39
本文介绍了如何在 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:

在 iOS 中使用 UILocalNotification 设置提醒.

但是,它似乎对我不起作用.

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

我需要每天设置闹钟,比如说每天 下午 5 点.我无法使用日期选择器来选择时间.

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)

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

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:

iOS 中的本地通知.

您发布的有关如何执行此操作的教程.

tutorial you posted on how to do this.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆