{"id":1644,"date":"2021-02-04T21:09:55","date_gmt":"2021-02-04T13:09:55","guid":{"rendered":"http:\/\/123.57.164.21\/?p=1644"},"modified":"2021-02-04T21:09:55","modified_gmt":"2021-02-04T13:09:55","slug":"swift-usernotifications%e6%a1%86%e6%9e%b6%e4%bd%bf%e7%94%a8%e8%af%a6%e8%a7%a31%ef%bc%88%e5%9f%ba%e6%9c%ac%e4%bb%8b%e7%bb%8d%ef%bc%8c%e6%9d%83%e9%99%90%e7%9a%84%e7%94%b3%e8%af%b7%e4%b8%8e%e5%88%a4","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=1644","title":{"rendered":"Swift &#8211; UserNotifications\u6846\u67b6\u4f7f\u7528\u8be6\u89e31\uff08\u57fa\u672c\u4ecb\u7ecd\uff0c\u6743\u9650\u7684\u7533\u8bf7\u4e0e\u5224\u65ad\uff09"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"364\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-18-1024x364.png\" alt=\"\" class=\"wp-image-1648\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-18-1024x364.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-18-300x107.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-18-768x273.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-18-1536x547.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-18-830x295.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-18-230x82.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-18-350x125.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-18-480x171.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-18.png 1596w\" 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=\"498\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-19-1024x498.png\" alt=\"\" class=\"wp-image-1650\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-19-1024x498.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-19-300x146.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-19-768x373.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-19-1536x747.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-19-830x404.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-19-230x112.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-19-350x170.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-19-480x233.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-19.png 1592w\" 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=\"225\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-20-1024x225.png\" alt=\"\" class=\"wp-image-1652\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-20-1024x225.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-20-300x66.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-20-768x169.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-20-1536x337.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-20-830x182.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-20-230x51.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-20-350x77.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-20-480x105.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-20.png 1602w\" 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    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        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}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"448\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-24-1024x448.png\" alt=\"\" class=\"wp-image-1658\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-24-1024x448.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-24-300x131.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-24-768x336.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-24-1536x672.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-24-830x363.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-24-230x101.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-24-350x153.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-24-480x210.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-24.png 1550w\" 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=\"275\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-23-1024x275.png\" alt=\"\" class=\"wp-image-1657\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-23-1024x275.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-23-300x81.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-23-768x207.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-23-1536x413.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-23-830x223.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-23-230x62.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-23-350x94.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-23-480x129.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-23.png 1636w\" 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=\"541\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-25-1024x541.png\" alt=\"\" class=\"wp-image-1660\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-25-1024x541.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-25-300x159.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-25-768x406.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-25-1536x812.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-25-830x439.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-25-230x122.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-25-350x185.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-25-480x254.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-25.png 1616w\" 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().getNotificationSettings {\n    settings in\n    switch settings.authorizationStatus {\n    case .authorized:\n        return\n    case .notDetermined:\n        \/\/\u8bf7\u6c42\u6388\u6743\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    case .denied:\n        DispatchQueue.main.async(execute: { () -> Void in\n            let alertController = UIAlertController(title: \"\u6d88\u606f\u63a8\u9001\u5df2\u5173\u95ed\",\n                                        message: \"\u60f3\u8981\u53ca\u65f6\u83b7\u53d6\u6d88\u606f\u3002\u70b9\u51fb\u201c\u8bbe\u7f6e\u201d\uff0c\u5f00\u542f\u901a\u77e5\u3002\",\n                                        preferredStyle: .alert)\n             \n            let cancelAction = UIAlertAction(title:\"\u53d6\u6d88\", style: .cancel, handler:nil)\n             \n            let settingsAction = UIAlertAction(title:\"\u8bbe\u7f6e\", style: .default, handler: {\n                (action) -> Void in\n                let url = URL(string: UIApplicationOpenSettingsURLString)\n                if let url = url, UIApplication.shared.canOpenURL(url) {\n                    if #available(iOS 10, *) {\n                        UIApplication.shared.open(url, options: [:],\n                                                  completionHandler: {\n                                                    (success) in\n                        })\n                    } else {\n                        UIApplication.shared.openURL(url)\n                    }\n                }\n            })\n             \n            alertController.addAction(cancelAction)\n            alertController.addAction(settingsAction)\n             \n            self.present(alertController, animated: true, completion: nil)\n        })\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=\"83\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/02\/image-26-1024x83.png\" alt=\"\" class=\"wp-image-1661\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-26-1024x83.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-26-300x24.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-26-768x62.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-26-1536x125.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-26-830x67.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-26-230x19.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-26-350x28.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-26-480x39.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/02\/image-26.png 1602w\" 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().getNotificationSettings {\n    settings in\n    var message = \"\u662f\u5426\u5141\u8bb8\u901a\u77e5\uff1a\"\n    switch settings.authorizationStatus {\n    case .authorized:\n        message.append(\"\u5141\u8bb8\")\n    case .notDetermined:\n        message.append(\"\u672a\u786e\u5b9a\")\n    case .denied:\n        message.append(\"\u4e0d\u5141\u8bb8\")\n    }\n     \n    message.append(\"\\n\u58f0\u97f3\uff1a\")\n    switch settings.soundSetting{\n    case .enabled:\n        message.append(\"\u5f00\u542f\")\n    case .disabled:\n        message.append(\"\u5173\u95ed\")\n    case .notSupported:\n        message.append(\"\u4e0d\u652f\u6301\")\n    }\n     \n    message.append(\"\\n\u5e94\u7528\u56fe\u6807\u6807\u8bb0\uff1a\")\n    switch settings.badgeSetting{\n    case .enabled:\n        message.append(\"\u5f00\u542f\")\n    case .disabled:\n        message.append(\"\u5173\u95ed\")\n    case .notSupported:\n        message.append(\"\u4e0d\u652f\u6301\")\n    }\n     \n    message.append(\"\\n\u5728\u9501\u5b9a\u5c4f\u5e55\u4e0a\u663e\u793a\uff1a\")\n    switch settings.lockScreenSetting{\n    case .enabled:\n        message.append(\"\u5f00\u542f\")\n    case .disabled:\n        message.append(\"\u5173\u95ed\")\n    case .notSupported:\n        message.append(\"\u4e0d\u652f\u6301\")\n    }\n     \n    message.append(\"\\n\u5728\u5386\u53f2\u8bb0\u5f55\u4e2d\u663e\u793a\uff1a\")\n    switch settings.notificationCenterSetting{\n    case .enabled:\n        message.append(\"\u5f00\u542f\")\n    case .disabled:\n        message.append(\"\u5173\u95ed\")\n    case .notSupported:\n        message.append(\"\u4e0d\u652f\u6301\")\n    }\n     \n    message.append(\"\\n\u6a2a\u5e45\u663e\u793a\uff1a\")\n    switch settings.alertSetting{\n    case .enabled:\n        message.append(\"\u5f00\u542f\")\n    case .disabled:\n        message.append(\"\u5173\u95ed\")\n    case .notSupported:\n        message.append(\"\u4e0d\u652f\u6301\")\n    }\n     \n    message.append(\"\\n\u663e\u793a\u9884\u89c8\uff1a\")\n    switch settings.showPreviewsSetting{\n    case .always:\n        message.append(\"\u59cb\u7ec8\uff08\u9ed8\u8ba4\uff09\")\n    case .whenAuthenticated:\n        message.append(\"\u89e3\u9501\u65f6\")\n    case .never:\n        message.append(\"\u4ece\u4e0d\")\n    }\n     \n     \n    print(message)\n}<\/pre>\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\/1644"}],"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=1644"}],"version-history":[{"count":9,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1644\/revisions"}],"predecessor-version":[{"id":1662,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1644\/revisions\/1662"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}