是否可以使用UILocal Notification ios 9设置每14天重复一次的通知

时间:2017-03-03 07:10:00

标签: objective-c ios9 uilocalnotification

我想设置一个每14天(2周)重复一次的通知。我正在使用旧的通知框架" UILOCAL NOTIFICATION"因为我希望它只与ios 9一起使用。

2 个答案:

答案 0 :(得分:1)

您必须按照以下答案执行操作:Repeating a Local Notification after every 14 days(two weeks)?或者您必须让您的应用通过为第一次出现安排本地通知来处理此问题,然后当您的应用收到此通知时,请将其重新安排给其他人14天。

答案 1 :(得分:1)

是的,你可以轻松做到,

史诗:当用户离开应用程序时,我们设置UINotification然后发送它。如果用户未在2天内输入(2 * 24 * 60 * 60),通知将发送2天结束。如果您想在14天后发送,可以使用14 * 24 * 60 * 60

更改fireDate时间 在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;
}