Reputation: 3267
When I log the description of the local notification
`<UIConcreteLocalNotification: 0x1edd4d40>{fire date = Thursday, September 26, 2013, 11:15:00 AM India Standard Time, time zone = Asia/Kolkata (GMT+05:30) offset 19800, repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Thursday, September 26, 2013, 11:15:00 AM India Standard Time, user info = {
UID = "38BF41F8-05D3-48E2-A20F-7B84609F4E85";
}}`
And I found "repeat count" parameter. Is there any option to set the repeat count such that it will repeat for this no of count and expired
Upvotes: 3
Views: 1284
Reputation: 66
It's an old post but i just had a similar thing and maybe it helps some one: I made similar like suggestions above but I just added an expiration date to the UNMutableNotificationContent
content.userInfo = ["expiration": expirationDate]
Then in the notification center delegate i can check this and remove the notification if it's expired. something like this:
in UNUserNotificationCenterDelegate, willPresent notification:
let expDate = notification.request.content.userInfo["expiration"] as? Date
Upvotes: 0
Reputation: 496
You can give the repeat count as a number. When notification fired in Appdelegate
didReceiveLocalNotification
method will be called. In that method you can get the repeat count. There you can decrease the repeat count and reschedule your notification. if the repeat count is 0 then you no need to reschedule that notification
.
For example:
if ([[notification.userInfo objectForKey:@"repeat"]intValue] != 0) {
//You can again schedule your notification here with decrementing the repeat count.
}else{
}
//Here you can cancel the current notification
[[UIApplication sharedApplication]cancelLocalNotification:notification];
Hope this helps :)
Upvotes: 0
Reputation: 6445
You couldnt set any repeat count for this purpose. But instead you can modify the fireDate with necessary checking after receiving notification and then it can be scheduled again.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
localNotif = notification;
int no_of_days = [self getNumberOfDaysToNextAlarmInDays];
int day = 24*60*60;
NSTimeInterval interval = day *no_of_days;
localNotif.fireDate = [NSDate dateWithTimeInterval:interval sinceDate:[NSDate date]];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
-(int)getNumberOfDaysToNextAlarmInDays {
//do the necessary calculations here
return count ;
}
A small problem here is it only works when the didReceiveLocalNotification invoked.
Upvotes: 0
Reputation: 1807
A possible workaround was asked in this question. Cancelling single occurence of repeating local notification
But, as this suggests I dont think it is possible to have a repeating Local notification distinguished by its repeat count.
Upvotes: 0