• ios本地推送通知


    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        //1.创建通知
        UILocalNotification *localNotification = [UILocalNotification new];
        //2.设置属性
        //2.1触发的时间
        localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:3];
        //2.2发送的内容
        localNotification.alertBody =@"你好";
        
        //2.3声音
        localNotification.soundName = UILocalNotificationDefaultSoundName;
        
        //2.4应用图片的图片
        localNotification.applicationIconBadgeNumber = 5;
        
        
        //3.调度本地通知
        [[UIApplication sharedApplication
          ]scheduleLocalNotification:localNotification];
        
        
        //4.注册通知
        //从ios8以后才出现
        //ios开始增加了用户的隐私保护
        //很多的事项都要我们程序员写代码完成
        /*
         typedef NS_OPTIONS(NSUInteger, UIUserNotificationType) {
         UIUserNotificationTypeNone    = 0,      // the application may not present any UI upon a notification being received
         UIUserNotificationTypeBadge   = 1 << 0, // the application may badge its icon upon a notification being received
         UIUserNotificationTypeSound   = 1 << 1, // the application may play a sound upon a notification being received
         UIUserNotificationTypeAlert   = 1 << 2, // the application may display an alert upon a notification being received
         } NS_ENUM_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
         
    
         */
        UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeNone| UIUserNotificationTypeBadge categories:nil];
        
        //调度
        [[UIApplication sharedApplication]registerUserNotificationSettings:setting];
    }

     其他属性:

    删除通知

      //获取本地通知并且删除  删除所有的通知
        [[UIApplication sharedApplication]cancelAllLocalNotifications];
        
        //删除单个通知
        //先获所有通知通知  再删除单个的通知
        NSArray *notif = [[UIApplication sharedApplication]scheduledLocalNotifications];
        
        for (UILocalNotification *localNotification in notif)
        {
            if (localNotification.userInfo)
            {
                [[UIApplication sharedApplication]cancelLocalNotification:localNotification];
    
            }
        }
    }
  • 相关阅读:
    Linux.超级管理员root-密码破解
    Hibernate.基础篇《一》.Hibernate工具类.
    不同版本Hibernate.获取SessionFactory的方式
    Hibernate.编写xml文件无自动提示信息
    ubantu中安装TensorFlow遇到的问题
    Ubuntu中安装python3.6(转)
    Linux 用户管理
    虚拟机中Linux安装(转)
    红黑树(转)
    树的遍历方法(转)
  • 原文地址:https://www.cnblogs.com/huangfang1314/p/5652319.html
Copyright © 2020-2023  润新知