• 本地推送通知小demo


    本地推送通知:

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
    //  在iOS8之后,Apple对用户隐私要求更加严格,所有很多东西都需要请求用户权限
        
        if ([UIDevice currentDevice].systemVersion.doubleValue >= 8.0) {
            
            /*
             
             UIUserNotificationTypeNone    = 0,      // 不展示通知
             UIUserNotificationTypeBadge   = 1 << 0, // 应用图标右上角的红色数字权限
             UIUserNotificationTypeSound   = 1 << 1, // 提示音的权限
             UIUserNotificationTypeAlert   = 1 << 2, // 弹窗或横幅的权限
             */
    //       权限类型
            UIUserNotificationType types = UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert;
    //      用户通知设置
            UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:types  categories:nil];
    //      注册用户设置,用户的请求窗口会弹出一次
            [[UIApplication sharedApplication] registerUserNotificationSettings:setting];
        }
        
        
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
    //  1.创建本地通知对象
        UILocalNotification *ln = [[UILocalNotification alloc] init];
        
    //  2.设置本地通知属性
    //************************************************************/
    //  什么时候发送这个本地通知
        ln.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
    //  设置通知的内容
        ln.alertBody = @"优衣库的试衣间,要约吗?";
    //  设置提示音,如果用户是静音,它自动会转为震动
        ln.soundName = UILocalNotificationDefaultSoundName;
    //  应用图标
        ln.applicationIconBadgeNumber = 10;
    //  当用用户点击通知时候,进入应用程序,要不要显示启动图标
        ln.alertLaunchImage = @"UILaunchImageFile";
    //************************************************************/
    //  不常用
    //  如果不设置这个属性,这个通知只发送一次,就会从应用的通知的调度移除
    //  一旦设置这个属性之后,那么系统就不会帮我们把通知移除了
    //  设置每隔一分钟发送一个通知
        ln.repeatInterval = NSCalendarUnitMinute;
    //  重复日历(阴历和阳历),通常不用设置这个属性
    //    ln.repeatCalendar = [NSCalendar autoupdatingCurrentCalendar];
    //  设置通知提示时区
        ln.timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
        
    //    NSArray *names = [NSTimeZone  knownTimeZoneNames];
    //    NSLog(@"%@",names);
        
    //  3.让应用调度这个本通知
    //  schedule 调度
        [[UIApplication sharedApplication] scheduleLocalNotification:ln];
        
        
    //  4.获取调度中的通知对象
        NSArray *lns  = [[UIApplication sharedApplication] scheduledLocalNotifications];
    //    NSLog(@"%@",lns);
        
    //  移除通知
    //  取消所有本地通知
    //    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    //  取消某个本地通知
    //    [[UIApplication sharedApplication] cancelLocalNotification:ln];
    }
    
    
    
    
    @end
  • 相关阅读:
    如何在IIS7/7.5上配置IISADMPWD
    运用DebugDiag诊断ASP.Net异常
    vuecli3修改项目启动端口
    彻底删除vscode及安装的插件和个人配置信息
    angular中的 input select 值绑定无效,以及多出一个空白选项问题
    简述MVC模式
    vuecli3 运行报错
    前端开发规范
    nodejs 下载最新版本
    小程序 自定义弹窗出现后存在滚动穿透问题
  • 原文地址:https://www.cnblogs.com/ZMiOS/p/5074288.html
Copyright © 2020-2023  润新知