当前位置:  开发笔记 > 编程语言 > 正文

如何在iOS 8和9中14天后重复本地通知

如何解决《如何在iOS8和9中14天后重复本地通知》经验,为你挑选了1个好方法。

注册通知的代码是:

   UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
        UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];

以及安排通知的代码:

UILocalNotification *notification = [[UILocalNotification alloc] init];
[self setNotificationTypesAllowed];
if (notification)
{
    if (allowNotif)
    {
        notification.timeZone = [NSTimeZone defaultTimeZone];
        if ( [statusString isEqualToString:@"daily"]) {
            notification.fireDate = _timePick.date;

                notification.repeatInterval = NSCalendarUnitDay;
        }else if ( [statusString isEqualToString:@"weekly"]) {
            notification.fireDate = _timePick.date;

                notification.repeatInterval = NSCalendarUnitWeekOfYear;

        }else if ( [statusString isEqualToString:@"fortnightly"]) {
            notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60*60*24*14];;
            notification.repeatInterval = NSCalendarUnitMinute;

            //notification.repeatInterval = NSCalendarUnitYear;
        }else{
                notification.repeatInterval = 0;
        }
    }
    if (allowsAlert)
    {
        notification.alertBody = [NSString stringWithFormat:@"Do you really want to send message to %@",name];
    }
    if (allowsBadge)
    {

        notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
    }
    if (allowsSound)
    {
        notification.soundName = UILocalNotificationDefaultSoundName;
    }
    notification.alertAction = @"Yes";
    notification.timeZone = [NSTimeZone defaultTimeZone];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showSMS) name:@"showSMS" object:nil];

    // this will schedule the notification to fire at the fire date
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];

我可以每天和每周重复本地通知,但不是每两周重复一次,请帮忙



1> Ekta Padaliy..:

是的@Nikos建议,请尝试以下代码:

    取消UILocalNotification.

    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    

    安排本地通知

    UILocalNotification *notification = [[UILocalNotification alloc]init];
    notification.userInfo = @{@"notification_identifier":@"After14Days"};
    notification.fireDate = [[NSDate date] dateByAddingTimeInterval:(60*60*24*14)];
    notification.alertBody = @"Text to display";
    notification.repeatInterval = NSCalendarUnitDay;
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    

如果您有任何疑问,请告诉我.


您应该将答案标记为已接受@PoojaBorkar,错字:D
推荐阅读
小白也坚强_177
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有