码迷,mamicode.com
首页 > 移动开发 > 详细

ios push local notification

时间:2015-04-20 12:59:12      阅读:183      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!