特定时间iPhone本地通知 [英] iPhone local notification at particular time
本文介绍了特定时间iPhone本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想每周晚上10点(不论国家/地区)发出通知。我需要使用timeZone吗?目前我使用下面的代码来解雇每周的通知,但是如何在晚上10点准确发布通知。
I want to fire a notification at 10PM(irrespective of country) every week. Do i need to use timeZone. Currently I am using below code to fire notification for every week but there how to fire notification exactly at 10PM.
NSDate *date = [NSDate date];
NSDate* myNewDate = [date dateByAddingTimeInterval:7*24*60*60];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = myNewDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatInterval = NSWeekCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
推荐答案
我认为将你的fireDate设置为22:00在您想要获得通知的那一天(而不是从现在开始的一周)可以做您想要的。您可能希望使用 NSCalendar
来执行此操作。
I would think that setting your fireDate to 22:00 on the day you want to get the notification (rather than "a week from now") would do what you want. You'll probably want to use NSCalendar
to do that.
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
NSDate *currentDate = [NSDate date];
NSDate *fireDate = nil;
[dateComponents setDay:3]; // ...or whatever day.
[dateComponents setHour:22];
[dateComponents setMinute:0];
fireDate = [gregorian dateByAddingComponents:dateComponents
toDate:currentDate
options:0];
[localNotification setFireDate:fireDate];
[dateComponents release];
这篇关于特定时间iPhone本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文