美文网首页
UILocalNotification设置重复提醒的坑

UILocalNotification设置重复提醒的坑

作者: tengpeng_ye | 来源:发表于2017-10-12 10:52 被阅读0次

    个人整理关于UILocalNotification的坑

    网上查找一般都是这样:

    //初始化
    UILocalNotification *locationNotification = [[UILocalNotification alloc]  init];
    
    //设置推送时间,这里使用相对时间,如果fireDate采用GTM标准时间,timeZone可以至nil
    locationNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
    locationNotification.timeZone = [NSTimeZone defaultTimeZone];
    
    //设置重复周期
    locationNotification.repeatInterval = NSWeekCalendarUnit;
    
    //设置通知的音乐
    locationNotification.soundName = UILocalNotificationDefaultSoundName;
    
    //设置通知内容
    locationNotification.alertBody = @"通知内容";
    
    //设置程序的Icon数量
    locationNotification.applicationIconBadgeNumber = 1;
    
    //执行本地推送
    [[UIApplication sharedApplication] scheduleLocalNotification:locationNotification];
    

    因为项目需要设置重复提醒,所以周期得设置成每一周,查找了一下是这样:

    // 重复间区
    notification.repeatInterval = kCFCalendarUnitWeek;
    

    然而我用了并不好使,经过多次验证,得使用:

    notification.repeatInterval = NSCalendarUnitWeekOfYear;
    

    相关文章

      网友评论

          本文标题:UILocalNotification设置重复提醒的坑

          本文链接:https://www.haomeiwen.com/subject/knynyxtx.html