{"id":1695,"date":"2021-02-04T22:17:01","date_gmt":"2021-02-04T14:17:01","guid":{"rendered":"http:\/\/123.57.164.21\/?p=1695"},"modified":"2021-02-04T22:17:01","modified_gmt":"2021-02-04T14:17:01","slug":"swift-usernotifications%e6%a1%86%e6%9e%b6%e4%bd%bf%e7%94%a8%e8%af%a6%e8%a7%a34%ef%bc%88%e9%80%9a%e7%9f%a5%e7%9a%84%e5%a4%84%e7%90%86%e3%80%81%e5%9b%9e%e8%b0%83%e3%80%81%e5%ba%94%e7%94%a8%e5%86%85","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=1695","title":{"rendered":"Swift &#8211; UserNotifications\u6846\u67b6\u4f7f\u7528\u8be6\u89e34\uff08\u901a\u77e5\u7684\u5904\u7406\u3001\u56de\u8c03\u3001\u5e94\u7528\u5185\u5c55\u793a\uff09"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"264\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-48-1024x264.png\" alt=\"\" class=\"wp-image-1696\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-48-1024x264.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-48-300x77.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-48-768x198.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-48-1536x396.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-48-830x214.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-48-230x59.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-48-350x90.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-48-480x124.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-48.png 1628w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">UNUserNotificationCenter.current().getPendingNotificationRequests { (requests) in\n    \/\/\u904d\u5386\u6240\u6709\u672a\u63a8\u9001\u7684request\n    for request in requests {\n        print(request)\n    }\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"334\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-49-1024x334.png\" alt=\"\" class=\"wp-image-1697\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-49-1024x334.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-49-300x98.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-49-768x250.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-49-1536x500.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-49-830x270.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-49-230x75.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-49-350x114.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-49-480x156.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-49.png 1572w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"58\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-50-1024x58.png\" alt=\"\" class=\"wp-image-1698\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-50-1024x58.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-50-300x17.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-50-768x44.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-50-1536x87.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-50-830x47.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-50-230x13.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-50-350x20.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-50-480x27.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-50.png 1548w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">UNUserNotificationCenter.current().getDeliveredNotifications { (notifications) in\n    \/\/\u904d\u5386\u6240\u6709\u5df2\u63a8\u9001\u7684\u901a\u77e5\n    for notification in notifications {\n        print(notification)\n    }\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"146\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-52-1024x146.png\" alt=\"\" class=\"wp-image-1700\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-52-1024x146.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-52-300x43.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-52-768x110.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-52-1536x219.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-52-830x118.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-52-230x33.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-52-350x50.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-52-480x68.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-52.png 1598w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\u4f7f\u7528\u540c\u6837\u7684\u8bf7\u6c42\u6807\u8bc6\u7b26\u6765\u8bbe\u7f6e\u4e00\u4e2a\u65b0\u7684\u901a\u77e5\nlet requestIdentifier = \"com.hangge.testNotification\"\nlet request = UNNotificationRequest(identifier: requestIdentifier,\n                                    content: content, trigger: trigger)\n \n\/\/\u5c06\u901a\u77e5\u8bf7\u6c42\u6dfb\u52a0\u5230\u53d1\u9001\u4e2d\u5fc3\nUNUserNotificationCenter.current().add(request) { error in\n    if error == nil {\n        print(\"Time Interval Notification scheduled: \\(requestIdentifier)\")\n    }\n}<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"89\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-53-1024x89.png\" alt=\"\" class=\"wp-image-1701\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-53-1024x89.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-53-300x26.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-53-768x67.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-53-1536x134.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-53-830x72.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-53-230x20.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-53-350x30.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-53-480x42.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-53.png 1562w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\u6839\u636eidentifier\u6765\u53d6\u6d88\u6307\u5b9a\u901a\u77e5\nlet identifier = \"com.hangge.testNotification\"\nUNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [identifier])\n \n\/\/\u53d6\u6d88\u5168\u90e8\u672a\u53d1\u9001\u901a\u77e5\nUNUserNotificationCenter.current().removeAllPendingNotificationRequests()<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"41\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-54-1024x41.png\" alt=\"\" class=\"wp-image-1702\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-54-1024x41.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-54-300x12.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-54-768x31.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-54-1536x62.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-54-830x33.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-54-230x9.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-54-350x14.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-54-480x19.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-54.png 1588w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\u6839\u636eidentifier\u6765\u5220\u9664\u6307\u5b9a\u901a\u77e5\nlet identifier = \"com.hangge.testNotification\"\nUNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [identifier])\n \n\/\/\u5220\u9664\u5168\u90e8\u5df2\u53d1\u9001\u901a\u77e5\nUNUserNotificationCenter.current().removeAllDeliveredNotifications()\n<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-55-1024x140.png\" alt=\"\" class=\"wp-image-1703\" width=\"516\" height=\"70\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-55-1024x140.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-55-300x41.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-55-768x105.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-55-830x114.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-55-230x32.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-55-350x48.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-55-480x66.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-55.png 1504w\" sizes=\"(max-width: 516px) 100vw, 516px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"257\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-56-1024x257.png\" alt=\"\" class=\"wp-image-1705\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-56-1024x257.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-56-300x75.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-56-768x192.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-56-1536x385.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-56-830x208.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-56-230x58.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-56-350x88.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-56-480x120.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-56.png 1684w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import UIKit\nimport UserNotifications\n \n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n     \n    var window: UIWindow?\n     \n    let notificationHandler = NotificationHandler()\n     \n    func application(_ application: UIApplication, didFinishLaunchingWithOptions\n        launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {\n        \/\/\u8bf7\u6c42\u901a\u77e5\u6743\u9650\n        UNUserNotificationCenter.current()\n            .requestAuthorization(options: [.alert, .sound, .badge]) {\n                (accepted, error) in\n                if !accepted {\n                    print(\"\u7528\u6237\u4e0d\u5141\u8bb8\u6d88\u606f\u901a\u77e5\u3002\")\n                }\n        }\n         \n        \/\/\u8bbe\u7f6e\u901a\u77e5\u4ee3\u7406\n        UNUserNotificationCenter.current().delegate = notificationHandler\n         \n        return true\n    }\n     \n    func applicationWillResignActive(_ application: UIApplication) {\n    }\n     \n    func applicationDidEnterBackground(_ application: UIApplication) {\n    }\n     \n    func applicationWillEnterForeground(_ application: UIApplication) {\n    }\n     \n    func applicationDidBecomeActive(_ application: UIApplication) {\n    }\n     \n    func applicationWillTerminate(_ application: UIApplication) {\n    }\n}\n \nclass NotificationHandler: NSObject, UNUserNotificationCenterDelegate {\n    \/\/\u5728\u5e94\u7528\u5185\u5c55\u793a\u901a\u77e5\n    func userNotificationCenter(_ center: UNUserNotificationCenter,\n                                willPresent notification: UNNotification,\n                                withCompletionHandler completionHandler:\n        @escaping (UNNotificationPresentationOptions) -> Void) {\n        completionHandler([.alert, .sound])\n         \n        \/\/ \u5982\u679c\u4e0d\u60f3\u663e\u793a\u67d0\u4e2a\u901a\u77e5\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528\u7a7a options \u8c03\u7528 completionHandler:\n        \/\/ completionHandler([])\n    }\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"357\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-57-1024x357.png\" alt=\"\" class=\"wp-image-1707\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-57-1024x357.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-57-300x105.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-57-768x268.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-57-1536x536.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-57-830x290.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-57-230x80.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-57-350x122.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-57-480x168.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-57.png 1690w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"291\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-58-1024x291.png\" alt=\"\" class=\"wp-image-1709\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-58-1024x291.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-58-300x85.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-58-768x218.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-58-1536x437.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-58-830x236.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-58-230x65.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-58-350x100.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-58-480x136.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-58.png 1660w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import UIKit\nimport UserNotifications\n \nclass ViewController: UIViewController {\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u8bbe\u7f6e\u63a8\u9001\u5185\u5bb9\n        let content = UNMutableNotificationContent()\n        content.title = \"hangge.com\"\n        content.body = \"\u505a\u6700\u597d\u7684\u5f00\u53d1\u8005\u77e5\u8bc6\u5e73\u53f0\"\n        content.userInfo = [\"userName\": \"hangge\", \"articleId\": 10086]\n         \n        \/\/\u8bbe\u7f6e\u901a\u77e5\u89e6\u53d1\u5668\n        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 30, repeats: false)\n         \n        \/\/\u8bbe\u7f6e\u8bf7\u6c42\u6807\u8bc6\u7b26\n        let requestIdentifier = \"com.hangge.testNotification\"\n         \n        \/\/\u8bbe\u7f6e\u4e00\u4e2a\u901a\u77e5\u8bf7\u6c42\n        let request = UNNotificationRequest(identifier: requestIdentifier,\n                                            content: content, trigger: trigger)\n         \n        \/\/\u5c06\u901a\u77e5\u8bf7\u6c42\u6dfb\u52a0\u5230\u53d1\u9001\u4e2d\u5fc3\n        UNUserNotificationCenter.current().add(request) { error in\n            if error == nil {\n                print(\"Time Interval Notification scheduled: \\(requestIdentifier)\")\n            }\n        }\n    }\n     \n    override func didReceiveMemoryWarning() {\n        super.didReceiveMemoryWarning()\n    }\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"82\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-59-1024x82.png\" alt=\"\" class=\"wp-image-1710\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-59-1024x82.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-59-300x24.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-59-768x62.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-59-1536x124.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-59-830x67.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-59-230x19.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-59-350x28.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-59-480x39.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-59.png 1664w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import UIKit\nimport UserNotifications\n \n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n     \n    var window: UIWindow?\n     \n    let notificationHandler = NotificationHandler()\n     \n    func application(_ application: UIApplication, didFinishLaunchingWithOptions\n        launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {\n        \/\/\u8bf7\u6c42\u901a\u77e5\u6743\u9650\n        UNUserNotificationCenter.current()\n            .requestAuthorization(options: [.alert, .sound, .badge]) {\n                (accepted, error) in\n                if !accepted {\n                    print(\"\u7528\u6237\u4e0d\u5141\u8bb8\u6d88\u606f\u901a\u77e5\u3002\")\n                }\n        }\n         \n        \/\/\u8bbe\u7f6e\u901a\u77e5\u4ee3\u7406\n        UNUserNotificationCenter.current().delegate = notificationHandler\n         \n        return true\n    }\n     \n    func applicationWillResignActive(_ application: UIApplication) {\n    }\n     \n    func applicationDidEnterBackground(_ application: UIApplication) {\n    }\n     \n    func applicationWillEnterForeground(_ application: UIApplication) {\n    }\n     \n    func applicationDidBecomeActive(_ application: UIApplication) {\n    }\n     \n    func applicationWillTerminate(_ application: UIApplication) {\n    }\n}\n \nclass NotificationHandler: NSObject, UNUserNotificationCenterDelegate {\n    \/\/\u5bf9\u901a\u77e5\u8fdb\u884c\u54cd\u5e94\uff08\u7528\u6237\u4e0e\u901a\u77e5\u8fdb\u884c\u4ea4\u4e92\u65f6\u88ab\u8c03\u7528\uff09\n    func userNotificationCenter(_ center: UNUserNotificationCenter,\n                                didReceive response: UNNotificationResponse,\n                                withCompletionHandler completionHandler:\n        @escaping () -> Void) {\n        print(response.notification.request.content.title)\n        print(response.notification.request.content.body)\n        \/\/\u83b7\u53d6\u901a\u77e5\u9644\u52a0\u6570\u636e\n        let userInfo = response.notification.request.content.userInfo\n        print(userInfo)\n        \/\/\u5b8c\u6210\u4e86\u5de5\u4f5c\n        completionHandler()\n    }\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"473\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-60-1024x473.png\" alt=\"\" class=\"wp-image-1712\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-60-1024x473.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-60-300x139.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-60-768x355.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-60-1536x710.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-60-830x384.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-60-230x106.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-60-350x162.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-60-480x222.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-60.png 1584w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1695"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1695"}],"version-history":[{"count":5,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1695\/revisions"}],"predecessor-version":[{"id":1713,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1695\/revisions\/1713"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}