【问题标题】:IOS local notifications always appear when I enter backgroundIOS本地通知总是在我进入后台时出现
【发布时间】:2017-03-12 13:38:28
【问题描述】:
This is code

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // calendar1 
       NSCalendar * calendar1 = [NSCalendar currentCalendar];
       NSDateComponents * Datecomps1 = [[NSDateComponents alloc] init];
       [Datecomps1 setDay: 12];
       [Datecomps1 setMonth:03];
       [Datecomps1 setYear: 2017];
       [Datecomps1 setHour: 23];
       [Datecomps1 setMinute: 59];
       NSDate *MyDate1 = [calendar dateFromComponents:Datecomps1];
       [self addToSchedult:MyDate1];
    }

    - (void)addToSchedult:(NSDate *)date {
        UIApplication* app = [UIApplication sharedApplication];
        UILocalNotification* localNotifi = [[UILocalNotification alloc] init];
        if (localNotifi) {

        NSLog(@"date:%@",date);
        localNotifi.fireDate = date;
        localNotifi.timeZone = [NSTimeZone defaultTimeZone];
        localNotifi.repeatInterval = 0;
        localNotifi.soundName = @"";

        [app scheduleLocalNotification:localNotifi];
        }
    }

我该怎么办?

我对本地通知有疑问。 我为日程安排和本地通知设置了两个日期, 我的约会准时工作。 但是当我每次进入后台时,这两个通知都会出现在屏幕上。 我怎样才能取消它?并且让两个本地通知只准时出现

【问题讨论】:

    标签: ios objective-c notifications local schedule


    【解决方案1】:

    我已经解决了这个问题。

    如果我添加以前的时间添加到本地通知,当我进入后台时,它会出现在屏幕上。

    所以应该检查这个日期是否是以前的时间,如果以前的时间没有添加到本地通知中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多