每天下午5点重复UILocalNotification [英] Repeat UILocalNotification daily at 5 pm
本文介绍了每天下午5点重复UILocalNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何每天下午5点重复UILocalNotification?以下是我的代码设置自定义时间。但我想通知用户每天在自定义或可能是静态时间。我使用iOS 6。
How to repeat UILocalNotification daily at 5 pm ? Following is my code to set custom time. But i want to notify the user daily at custom or may be static time. I am using iOS 6.
-(void)scheduleNotification{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"h:mm a"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:timeStr];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = dateFromString;
localNotif.repeatInterval = kCFCalendarUnitDay;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotif.alertBody = @"Reminder is set";
// Set the action button
localNotif.alertAction = @"Ok";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Local Push received while running", @"key", nil];
localNotif.userInfo = infoDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
推荐答案
。它可以帮助你
NSDateFormatter *dat= [[NSDateFormatter alloc]init];
[dat setLocale:[NSLocale currentLocale]];
[dat setTimeZone:[NSTimeZone systemTimeZone]];
//[dat setDateFormat:@"YYYY-MM-dd"];// YYYY-MM-dd hh:mm a
//NSString *dateM=[dat stringFromDate:datM];
//[dat setDateFormat:@"YYYY-MM-dd h:mm a"];
NSDate *reminderDate=[NSDate date];
reminderDate =[reminderDate dateByAddingTimeInterval:1*24*60*60];
UILocalNotification *missingDreamNotify=[[UILocalNotification alloc]init];
missingDreamNotify.fireDate=reminderDate;
missingDreamNotify.timeZone = [NSTimeZone defaultTimeZone];
missingDreamNotify.alertBody = @"Reminder is set";
missingDreamNotify.alertAction = @"Show me";
missingDreamNotify.soundName = UILocalNotificationDefaultSoundName;
missingDreamNotify.applicationIconBadgeNumber = 1;
missingDreamNotify.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:missingDreamNotify];
这篇关于每天下午5点重复UILocalNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文