iPhone: Comment définir le répéter tous les jours/horaires de notification locale?
Je veux tester ajouter notification locale. Je veux qu'il se répète tous les jours/toutes les heures. Comment puis-je le faire?
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
//Get the current date
NSDate *now = [NSDate date];
//Break the date up into components
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit )
fromDate:now];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit)
fromDate:now];
//Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]+10];
//Notification will fire in one minute
NSDate *itemDate = [calendar dateFromComponents:dateComps];
[dateComps release];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
//Notification details
localNotif.alertBody = @"Hello World";
//Set the action button
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
applicationIconBadgeNumber++;
localNotif.applicationIconBadgeNumber = applicationIconBadgeNumber;
//Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
Vous pourriez essayer de formater votre code correctement.
OriginalL'auteur Quy | 2010-08-06
Vous devez vous connecter pour publier un commentaire.
Si vous souhaitez configurer les Notifications à un moment donné, à tous les jours ... .ensuite, vous devez définir la notification repeatInterval de la propriété.iOS poignées;s propre sur la notification.Il suffit d'ajouter cette ligne unique ...qui vous a manqué. Sinon, vous code est beau & fonctionne.
vous allez probablement avoir à créer manuellement chaque aléatoire du jour firetime, ce n'est pas normal "intervalle de répétition".
OriginalL'auteur Ajay Sharma
Votre code serait beaucoup plus simple si vous avez utilisé dateByAddingComponents:jour:options:.
(dateByAddingTimeInterval: ne pas gérer des calendriers correctement, par exemple, les changements de fuseau horaire.)
Si vous voulez qu'il le répète, je pense que vous devez ajouter plusieurs, ou ajouter de nouveau lorsque votre application est lancé suivant. Autrement, une notification l'informant que répéter chaque seconde serait incroyablement ennuyeux.
OriginalL'auteur tc.
Découvrez ce tutoriel: http://useyourloaf.com/blog/2010/9/13/repeating-an-ios-local-notification.html
OriginalL'auteur jodm
OriginalL'auteur SURESH SANKE