zoukankan      html  css  js  c++  java
  • IOS开发-本地通知

     1 //    注册 发送通知的方法
     2 -(void)pushNotfation{
     3 
     4     
     5 //--------------初始化本地通知  alloc init 虽然是UI控件 但继承NSObject
     6     UILocalNotification *not = [[UILocalNotification alloc]init];
     7 //    设置本地通知启动的时间
     8     not.fireDate   = [NSDate dateWithTimeIntervalSinceNow:5];
     9 //    设置通知的标题
    10     not.alertTitle = @"开始工作了。。。";
    11 //    设置通知的内容
    12     not.alertBody  = @"起床做码农了,,,,hahhhhh";
    13 //    通过通知 传递 内容--传值
    14     not.userInfo   = @{@"key":@"Value"};
    15 //    设置App图标上面红点的 显示的数字
    16     not.applicationIconBadgeNumber = 1;
    17 //*******************************************************************
    18 //    设置重复发送通知的时间间隔
    19     /*
    20      NSCalendarUnitEra                = kCFCalendarUnitEra,一个世纪
    21      NSCalendarUnitYear               = kCFCalendarUnitYear, 一年
    22      NSCalendarUnitMonth              = kCFCalendarUnitMonth, 一个月
    23      NSCalendarUnitDay                = kCFCalendarUnitDay, 天
    24      NSCalendarUnitHour               = kCFCalendarUnitHour, 时
    25      NSCalendarUnitMinute             = kCFCalendarUnitMinute,分
    26      NSCalendarUnitSecond             = kCFCalendarUnitSecond,秒
    27      NSCalendarUnitWeekday            = kCFCalendarUnitWeekday, 一个礼拜
    28      NSCalendarUnitWeekdayOrdinal     = kCFCalendarUnitWeekdayOrdinal,
    29      */
    30 //    not.repeatCalendar = kCFCalendarUnitEra;
    31 //*******************************************************************
    32     
    33 //——----------------注册通知
    34 //******
    35     //        UIUserNotificationTypeNone
    36     //        UIUserNotificationTypeBadge
    37     //        UIUserNotificationTypeSound
    38     //        UIUserNotificationTypeAlert 振动
    39 //******
    40 //       respondsToSelector 方法是否可以响应
    41     if ([[UIApplication sharedApplication]respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    42 //        解决
    43         [[UIApplication sharedApplication]registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeAlert categories:nil]];
    44         
    45     }
    46 //    设置声音
    47     not.soundName = UILocalNotificationDefaultSoundName;
    48     
    49 //    发送通知
    50     [[UIApplication sharedApplication]scheduleLocalNotification:not];
    51  
    52 }
    53 
    54 
    55 
    56 //本地移除
    57 -(void)removeLocalPushNotification:(UIButton*)sender
    58 {
    59     NSLog(@"%s",__FUNCTION__);
    60     UIApplication* app=[UIApplication sharedApplication];
    61     //获取当前应用所有的通知
    62     NSArray* localNotifications=[app scheduledLocalNotifications];
    63     
    64     if (localNotifications) {
    65         
    66         for (UILocalNotification* notification in localNotifications) {
    67             
    68             NSDictionary* dic=notification.userInfo;
    69             
    70             if (dic) {
    71                 NSString* key=[dic objectForKey:@"key"];
    72                 if ([key isEqualToString:@"name"]) {
    73                     //取消推送 (指定一个取消)
    74                     [app cancelLocalNotification:notification];
    75                     
    76                     break;
    77                 }
    78             }
    79             
    80         }
    81     }
    82     //取消当前应用所有的推送
    83     //[app cancelAllLocalNotifications];
    84     
    85     
    86 }

    下一篇博客将会详细讲述--远程通知

  • 相关阅读:
    2008俱乐部高校行之中南民族大学
    [更新]MSDN中Webcast "WPF中的图形系统系列" 课程预告及反馈
    7月20日 武汉.NET俱乐部在线沙龙!
    2007武汉.NET俱乐部沙龙VS2008、WPF、Silverlight
    MSDN新年第一次WebCast总结
    [评]Microsoft Visual Web Developer 2008 Step by Step, Express Edition
    [老爸创作的歌词]我从瓦砾中站起
    [Expert MS IL Assembler]武汉.NET俱乐部在线沙龙与线下聚会
    2008开年大礼:《Application = Code + Markup》中文版面世
    2009武汉.NET俱乐部活动之黄冈站
  • 原文地址:https://www.cnblogs.com/chenhongios/p/4870273.html
Copyright © 2011-2022 走看看