首页 > 移动平台 > 详细

ios push local notification

时间:2015-04-20 12:59:05      阅读:289      评论:0      收藏:0      [点我收藏+]

    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];

ios push local notification

原文:http://www.cnblogs.com/yibinpan/p/4440991.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!