入门浅析UILocalNotification本地消息的推送,UIDatePicke计时器。

上个头文件方便下面的理解;

下面是UIDatePicker的一些简单的用法

     //autoupdatingCurrentCalendar 自动调取本电脑中的时间格式

   NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

// Get the current date

NSDate *pickerDate = [self.datePicker date];

// Break the date up into components在建NsDateComponent时要先实例话一个Calendar,()括号里面事放需要输出的那些时间段,格局calendar的格式输出pickdate中的内容,选择()中的内容。(年月日)

NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnitNSDayCalendarUnit  )

  fromDate:pickerDate];


    //同上 只是输出的事小时分钟,秒

NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit

  fromDate:pickerDate];

// Set up the fire time

    NSDateComponents *dateComps = [[NSDateComponents alloc] init];

    [dateComps setDay:[dateComponents day]];

    [dateComps setMonth:[dateComponents month]];

    [dateComps setYear:[dateComponents year]];

    [dateComps setHour:[timeComponents hour]];

// Notification will fire in one minute

    [dateComps setMinute:[timeComponents minute]];

    [dateComps setSecond:[timeComponents second]];

    NSDate *itemDate = [calendar dateFromComponents:dateComps];

    [dateComps release];

正式进入消息推送

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

        //确保代码兼容  确保本地通知可用

    if (localNotif != nil)

    {

        //itemdate这个时间基础上在延迟100 addTimeInterval的这个方法呗注视了

    //localNotif.fireDate =[itemDate dateByAddingTimeInterval:100];

    localNotif.fireDate=itemDate;//激发消息推送的时间

    localNotif.timeZone = [NSTimeZone defaultTimeZone];//消息推送的区时,如果fireDate采用GTM标准时间,timeZone可以至nil 

// Notification details

    localNotif.alertBody = [eventText text];//消息提示的内容

// Set the action button

    localNotif.alertAction = @"View";

    //以上两条时必须的  要不就无法显示推送消息

    //是否需要其他的butten

   // localNotif.hasAction=YES;

        //一周循环一次

    localNotif.repeatInterval=kCFCalendarUnitWeekday;

//推送消息的提示声音,不过楼主我没有实现,没听到声音 在研究中

    localNotif.soundName = UILocalNotificationDefaultSoundName;

     //在推出程序时图表又上边会右一个消息未读数。

    localNotif.applicationIconBadgeNumber = 1;

  // Specify custom data for the notification

    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];

    //nsloacnoticationuserInfo是自带的字典属性,用来传递数据和标记的作用

    localNotif.userInfo = infoDict;

// Schedule the notification添加application中的推送列表,,没有这句化就无法调用tableview方法 

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

    //马上推送[[UIApplication sharedApplication] presentLocalNotificationNow:noti];

    [localNotif release];





在消息推送的时候会右提示筐 点击进入程序首先时调用了这个的方法。

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {

    //点击消息推送时候会调用这个方法。。

// Handle the notificaton when the app is running

NSLog(@"Recieved Notification %@",notif);

    UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:nil message:[notif alertBody] delegate:self cancelButtonTitle:nil otherButtonTitles:@"good", nil] autorelease];

    [alert show];

    if(notif.applicationIconBadgeNumber){

    app.applicationIconBadgeNumber=notif.applicationIconBadgeNumber-1;

}

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值