0

I want to set a notification that repeats every 14 days(2 week).I am using old notification framework "UILOCAL NOTIFICATION" as i want it to work with only ios 9.

kishan
  • 203
  • 1
  • 6
  • 15
  • I think this links will help you: repeat daily/hourly local notification [http://stackoverflow.com/questions/3426882/iphone-how-to-set-repeat-daily-hourly-local-notification] and custom time interval [http://stackoverflow.com/questions/4363847/how-to-set-local-notification-repeat-interval-to-custom-time-interval] – Nazir Mar 03 '17 at 07:21

2 Answers2

1

Either you must do as this answer says: Repeating a Local Notification after every 14 days(two weeks)? or you must let your app handle this by scheduling a local notification for the first occurrence, and then when this notification is received by your app, reschedule it for another 14 days.

Community
  • 1
  • 1
Bjørn Ruthberg
  • 336
  • 1
  • 15
1

Yes you can do easly,

Epic: When the user leave the app, we set UINotification and then send it. if the user not enter in 2 days(2*24*60*60), the notification will send end of the 2 days. if you want to send after 14 days, you can change the fireDate time with 14*24*60*60

in AppDelegate :

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.timeZone = [NSTimeZone defaultTimeZone];
    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:2*24*60*60];
    //[[NSDate date] dateByAddingTimeInterval:5];[NSDate dateWithTimeIntervalSinceNow:24*60*60]
    NSLog(@"%@",notification.fireDate);
    notification.alertBody = NSLocalizedString(@"NOTIFICATION_MSG", @"Message");
    notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];

}


- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    application.applicationIconBadgeNumber = 0;
}
Emre Gürses
  • 1,992
  • 1
  • 23
  • 28