ios push local notification

    UILocalNotification* localNotification = [[UILocalNotification alloc]init];

    localNotification.alertBody = @"this is a local notification";

    localNotification.soundName = UILocalNotificationDefaultSoundName;

 

  //schedule the time to push local notification

    NSCalendar* calendar = [NSCalendar autoupdatingCurrentCalendar];

    NSDate* currentDate = [NSDate date];

    NSDateComponents* currentDateComponents = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:currentDate];

    NSDateComponents* scheduledDateComponents = currentDateComponents;

 

    if (currentDateComponents != nil) {

        [scheduledDateComponents setDay:currentDateComponents.day + 7];

        [scheduledDateComponents setHour:17];

        [scheduledDateComponents setMinute:0];

        [scheduledDateComponents setSecond:0];

    }

  

    NSDate* scheduledDate = [calendar dateFromComponents:scheduledDateComponents];

    localNotification.fireDate = scheduledDate;

    

    [[UIApplication sharedApplication]cancelAllLocalNotifications];

    [[UIApplication sharedApplication]scheduleLocalNotification:localNotification];

 

 

 

/////SIMPLE WAY

http://stackoverflow.com/questions/10060578/uilocalnotification-fires-immediately-instead-of-at-scheduled-time

UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
localNotification.alertBody = @"Your alert message";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。