-(voID)notification{ UIlocalnotification *localnotification = [[[UIlocalnotification alloc] init] autorelease]; if (!localnotification) return; // Current date NSDate *date = [NSDate date]; NSDate *datetoFire = //Everyday: 6AM; // Set the fire date/time [localnotification setFireDate:datetoFire]; [localnotification setTimeZone:[NSTimeZone defaultTimeZone]]; [localnotification setAlertbody:@"Notification" ]; [[UIApplication sharedApplication] schedulelocalnotification:localnotification];}- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; [self notification];}解决方法 使用CalendarComponents将小时设置为6,并将localnotification.repeatInterval设置为NSDayCalendarUnit
NSCalendar *calendar = [NSCalendar currentCalendar]; // gets default calendarNSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]]; // gets the year,month,day,hour and minutesfor today's date[components setHour:18];[components setMinute:0];localnotification.fireDate = [calendar dateFromComponents:components];总结
以上是内存溢出为你收集整理的iphone – xcode – 按时间安排本地通知(每天早上6点)全部内容,希望文章能够帮你解决iphone – xcode – 按时间安排本地通知(每天早上6点)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)