zoukankan      html  css  js  c++  java
  • swift

    1. 

    AppDelegate  注册

    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow?
    
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            regisigerNotification()
            return true
        }
    
        //注册本地通知
        private func regisigerNotification(){
    //        let type : [UIUserNotificationType] = [.alert, .badge, .sound]
            if #available(iOS 8.0, *) {
                let uns = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
                UIApplication.shared.registerUserNotificationSettings(uns)
            }
        }
    
    }
    

      

    2. VC 使用

    class ViewController: UIViewController {
    
        @IBAction func sendNotification(_ sender: Any) {
            
            /// 创建
            let localNotification = UILocalNotification()
            //设置标题
            localNotification.alertBody = "通知来了"
            
            //几秒之后执行
            localNotification.fireDate = Date(timeIntervalSinceNow: 2)
            
            //立即发送
    //        UIApplication.shared.presentLocalNotificationNow(localNotification)
            
            //发送:按照设置的执行时间发送
            UIApplication.shared.scheduleLocalNotification(localNotification)
        }
        
        //取消
        @IBAction func cancleNotification(_ sender: Any) {
            UIApplication.shared.cancelAllLocalNotifications()
        }
        
        //查看
        @IBAction func viewNotification(_ sender: Any) {
        print(UIApplication.shared.scheduledLocalNotifications)
        }
    
    }
    

      

    也可以查看 :

    https://www.cnblogs.com/Free-Thinker/p/7120211.html

  • 相关阅读:
    BAT脚本批量调用Sql执行文件 (SqlServer 数据库)
    树莓派系统刻录到首次登陆等问题
    数据库视图的使用
    MQ配置安装
    PLSQL集合类型
    PLSQL-包函数存储过程
    Oracle 字段拆分替换在合并成一条
    ORACLE-EXP和IMP方法介绍
    javascript几个月前的时间
    返回顶部实现方式
  • 原文地址:https://www.cnblogs.com/qingzZ/p/10271846.html
Copyright © 2011-2022 走看看