• IOS 本地通知


    操作流程

     1.接收通知

     2.注册发送通知

    用途:提示时间,闹钟

    //接收本地通知(在Appdelegate里面实现)

    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{

    //接收到通知之后的操作

            UIAlertView *aler = [[UIAlertView alloc]initWithTitle:notification.alertTitle message:notification.alertBody delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];

        [aler show];

    }

     注册,发送通知的方法

    -(void)pushNotfation{

    //初始本地通知的方法

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

        not.fireDate =[NSDate dateWithTimeIntervalSinceNow:10];

    //    设置通知的标题

        not.alertTitle = @"时间到";

    //    设置通知的内容

        not.alertBody = @"起床敲代码";

    //    通过通知 传递 内容

        not.userInfo = @{@"key":@"value"};

    //    设置App图标上面红点显示的数字

        not.applicationIconBadgeNumber = 1;

    //    发送的间隔

        not.repeatInterval =kCFCalendarUnitMonth;

        /*

         NSCalendarUnitEra                = kCFCalendarUnitEra,一个世纪

         NSCalendarUnitYear               = kCFCalendarUnitYear, 一年

         NSCalendarUnitMonth              = kCFCalendarUnitMonth, 一个月

         NSCalendarUnitDay                = kCFCalendarUnitDay, 天

         NSCalendarUnitHour               = kCFCalendarUnitHour, 时

         NSCalendarUnitMinute             = kCFCalendarUnitMinute,分

         NSCalendarUnitSecond             = kCFCalendarUnitSecond,秒

         NSCalendarUnitWeekday            = kCFCalendarUnitWeekday, 一个礼拜

         NSCalendarUnitWeekdayOrdinal     = kCFCalendarUnitWeekdayOrdinal,

         */

    //    注册通知

        

        if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {     [[UIApplication sharedApplication]registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeAlert categories:nil]];

        

        

        }

        not.soundName= UILocalNotificationDefaultSoundName;

        //    发送通知

        

        [[UIApplication sharedApplication]scheduleLocalNotification:not];

        

    //    UIUserNotificationTypeBadge| 圆圈内提示的数字

    //    UIUserNotificationTypeSound| 通知提示的声音

    //    UIUserNotificationTypeNone|

    //    UIUserNotificationTypeAlert  振动

        

        

    }

  • 相关阅读:
    == 和equals方法
    ObjectInputStream 与ObjectOutputStream
    IOS基础:ObjectiveC 数组处理
    学习笔记:自定义方法的两种实现方式
    DatePicker 获取时间的时区问题
    IOS基础:tableview中cell
    IOS基础:窗口切换的几种方法
    IOS基础:ObjectiveC 字符串处理
    使用 Notifications
    学习笔记:Tab Bar 控件使用详解
  • 原文地址:https://www.cnblogs.com/popper123/p/4836661.html
Copyright © 2020-2023  润新知