在特定时间在 Iphone 中显示警报/通知(由用户或开发人员设置)

发布于 2024-11-14 08:53:41 字数 266 浏览 3 评论 0原文

我想知道使用什么 IOS 功能来使我能够在 iPhone 上的特定时间显示警报/通知。用户或开发人员可以使用 UIDatePicker 设置时间。运行本地通知教程,警报/通知仅当应用程序位于后台时才会显示(如果我错了,请纠正我)

如果有人可以帮助我解决这个问题,那就太好了。

I would like to know what IOS functionality to use to enable me to display a alert/notification at a particular time on the iphone. The time would be set either by the user or the developer using the UIDatePicker. Running the Local Notification Tutorial, the alert/notification is getting displayed only when the app is in the background(please correct me if I am wrong)

It would be great if someone could help me out with this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋心╮凉 2024-11-21 08:53:41

所以我认为你在这里的方向是正确的:不确定我还可以添加什么。

您可以使用本地通知在任何给定时间显示警报。正如您从教程中看到的,当您的应用程序位于前台时,不会触发通知。

但是,没有什么可以阻止您在应用程序中编写代码,以便在应用程序位于前台时需要通知时提醒用户:这可能更理想。您可能希望利用在前台提供的 UI 选项来执行不同的操作,或者您可以只显示自己的 UIAlertView。

So I think you're on the right track here: not sure what more I can add.

You can use a local notification to display an alert at any given time. As you see from the tutorial, notifications aren't triggered when your app is in the foreground.

But there's nothing to stop you from writing code in your app to alert users at the time the notification is required when your app is in the foreground: and this is probably more ideal. You may want to take advantage of the UI options offered to you when in the foreground to do something different, or you could just display your own UIAlertView.

离不开的别离 2024-11-21 08:53:41

我可以给你我的简短代码来确定日期的具体时间......
我试图计算特定月份的时间。
示例(从 2011 年 1 月 1 日到 2011 年 1 月 2 日上午 0:0:00)。
在我住的地方,格林威治标准时间有 2 小时的时差。

dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];


components = [[NSDateComponents alloc] init];
NSCalendar *gregorian = [NSCalendar currentCalendar];
[components setMonth:1];
[components setHour:0];
[components setMinute:0];
[components setSecond:0];
dategre = [gregorian dateByAddingComponents:components toDate:[datePicker date]  options:0];

//These steps below are important to put your specific date, in this case specific hour
selected2 = [dateFormatter stringFromDate:dategre];
dategre = [dateFormatter dateFromString:selected2];

//你会在调试器控制台上看到类似这样的内容:
//datePicker.date = 2011-01-01 08:42:16 GMT
//dategre = 2011-01-31 22:00:00 GMT(对我们来说,这等于 2011 年 2 月 1 日上午 0:00:00)

我希望我能帮助你,

再见,

威利。

I can give you my short code to put a specific time on date...
I was trying to calculate an specific month time.
Example (from 1-1-2011 to 2-1-2011 at 0:0:00 am).
Where I live, I have 2h of difference respect of GMT.

dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];


components = [[NSDateComponents alloc] init];
NSCalendar *gregorian = [NSCalendar currentCalendar];
[components setMonth:1];
[components setHour:0];
[components setMinute:0];
[components setSecond:0];
dategre = [gregorian dateByAddingComponents:components toDate:[datePicker date]  options:0];

//These steps below are important to put your specific date, in this case specific hour
selected2 = [dateFormatter stringFromDate:dategre];
dategre = [dateFormatter dateFromString:selected2];

//You would see on debugger console something like this:
//datePicker.date = 2011-01-01 08:42:16 GMT
//dategre = 2011-01-31 22:00:00 GMT (for us, this is equal to 2-1-2011 at 0:00:00 am)

I hope I can help you,

bye,

Willy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文