Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

objective c - How to fire daily localnotification at specific time in iOS

I want to get daily notification and for that I have googled and I got some solution from this iPhone : Daily local notifications but I couldn't recognise properly

NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay: 3];
[components setMonth: 7];
[components setYear: 2012];
[components setHour: 6];
[components setMinute: 0];
[components setSecond: 0];
[calendar setTimeZone: [NSTimeZone defaultTimeZone]];
NSDate *dateToFire = [calendar dateFromComponents:components];

Let's say suppose current time is 3:13, and current date is 20-11-2014 in this I want to set local notification at time of 3:14, 20-11-2014 can anybody please help me, because I have tried with following things but not working

    [components setDay: 20];
    [components setMonth: 11];
    [components setYear: 2014];
    [components setHour: 15];
    [components setMinute: 14];
    [components setSecond: 0]; 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
 NSDate *date = [NSDate date];
NSDate *newDate1 = [date dateByAddingTimeInterval:60*60*24];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = newDate1;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = [[NSUserDefaults standardUserDefaults] objectForKey:@"NotificationText"];
localNotif.alertAction = @"View";
localNotif.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

try this one hope this may help you. Thank you


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...