• 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

  • 相关阅读:
    友链
    OI日常
    P4451 [国家集训队]整数的lqp拆分 生成函数
    AT4831 [ABC155F] Perils in Parallel 生成树
    P4438 [HNOI/AHOI2018]道路 树DP
    CF383E Vowels 子集DP 容斥
    P5488 差分与前缀和 生成函数+多项式EXP
    CF115E Linear Kingdom Races 线段树优化DP
    CF49E Common ancestor 区间DP
    P5047 [Ynoi2019 模拟赛] Yuno loves sqrt technology II 莫队二次离线
  • 原文地址:https://www.cnblogs.com/qingzZ/p/10271846.html
Copyright © 2020-2023  润新知