AppDelegate.swift 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. //
  2. // AppDelegate.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2022/9/23.
  6. //
  7. import Cocoa
  8. import UserNotifications
  9. @main
  10. class AppDelegate: NSObject, NSApplicationDelegate, iRateDelegate{
  11. func applicationWillFinishLaunching(_ notification: Notification) {
  12. #if VERSION_FREE
  13. #if VERSION_DMG
  14. CPDFConvertKit.setLicenseKey("O/Gy6kRnVkPniZrtkbxVR1TE40NTE5pBLNTKURABKTzsIIbuxTL/T5Heoq7dR8rnIucE+QnyQFm7qD1M8FYPSLa7rFNhYndz6r/tOJ/zprEPTIOC/Nw4EX6spV9KH48rd1SHQTNhzbLFaNJvDgu2/ejACIaxDQphAukW2sq99tdKa8c5i0ZVoXbf6/8I2Z3Od3majxVC1KDcp/GFYQBaZ76754mYrYfmjEUPZ7S8iUjyFIQsowcxzlliSKY7wSyLw4M0H9PYB5U9haTiQ64gBLYRmw0VtvUwqO4H/hQ9LGi6X8lGqylnDe1XlN5rXwEMSiDCAhvbmLCRDsRibJkkHmu0lH1oY17eVN2TRW5amzqhpkGcUFF17VJJZII5FrASG54RG2l/P/4nIMUZUpkQWzt+ywu1ETx64wnEWVCLqsbdRblIYesSaSBLC+ue5qj5IaZ5NrlUIullyFVfqhe0wgJTOAqc3sItd6982pDUUOfO1vBwf9Gih2qz4tARI2xVuzABfsMzje7wUE0bm1cpFckwV66yFU3arnx3YKFgKb3I+cfej7P32Ul15YgJWcFJ73lHjkMG6INyw1EEf1rPimDxLz3UnfnLfC0R03ceOgzTYO9/asHtjQN6JLAJ6RPMQGvvr0we4wc3psyfAnokxsRHkgtxfepvazk4kx4MMiYLkEkH3o/9D3jycmgmtJNNDOYy9ariKo6bXDBPENEd2iIDr6sby+Jm3qii6n3/VWRZQv/eghUvrDc0/BlUHjx8TSsbRmzsSDkeM/v3k1jSCw==")
  15. #else
  16. CPDFConvertKit.setLicenseKey("6zZWsJZxS0gKqledWY3Wo8AC+0IQ0EU1u9Wp7IVHvMsHpPe/0IPk9aNAbMUZwpTHMicme3hvjORzGJYnpBvb3/Z82a1GikkQmNZd+v5w339rXeJw+v0hhIv5Q4btZUOscw80t3c1bXxpLq3B6fv6psGJP0+FMyQOerBP6u4YYan9tCSe6rawjumJYCQMT5YNHtN/72HTYtc9HAcQzdMudePhw3hYY3747Z6Sq7DCCqgbK+BnM11gxblULiTgFkYLZsuBudusbqrM7WktIkcfpLfh15Y+TZ04iXpI9LWkgKoeYZ1VAJMTcrfwCs63g/8nUiZ59kpdetHbzONEIhsi+Wu0lH1oY17eVN2TRW5amzrZsD0yy20WxEXrssgDJq7xPzi1sOZ56C+jdE/8p9tNUW4KYJ5GoqCVh5w0Ajkc3xRqWrpmJXUollqL+u9K6VDPqy3tmvVGdknJxHlX4q+ufAQa+Tb3qlEJwp14dhrbJERqUs5Gygc6W5Fk18+uJ6IjwvilMe8T8+t3vLDZPlOgVg4lqZaxlBn/t+RvkJ/76CDO1/Byfqmig2vE4qETJmxV+pK4Lftqjsxibe087g3EFlaO/7ZpewBkqMhR1sG/D/3Jjsevjbb32Ut+5f8JWMFL7gFHikJx6PJwxlEEfVHP/dqNkFfBJKTqjjZoj9LNxxkOngdfNDsnWigFkZUSivLNCXAJ+a4C/mHaaRf95ad20LA0NahljpcTQ7x8TR8fuAHZkFK4DnFK+ST8zSP17/yW3x9ACHU6arojAbZ0IAz2pZRRuYYl9YB07NckfhpuE2qQAu+IaHm32opV2P/l/7HZUt7hsw7wAHIKJqnBs4cNag==")
  17. #endif
  18. #else
  19. CPDFConvertKit.setLicenseKey("6zZWsJZxS0gKqledWY3Wo8AC+0IQ0EU1u9Wp7IVHvMsHpPe/0IPk9aNAbMUZwpTHMicme3hvjORzGJYnpBvb3/Z82a1GikkQmNZd+v5w339rXeJw+v0hhIv5Q4btZUOscw80t3c1bXxpLq3B6fv6psGJP0+FMyQOerBP6u4YYan9tCSe6rawjumJYCQMT5YNHtN/72HTYtc9HAcQzdMudePhw3hYY3747Z6Sq7DCCqgbK+BnM11gxblULiTgFkYLZsuBudusbqrM7WktIkcfpLfh15Y+TZ04iXpI9LWkgKoeYZ1VAJMTcrfwCs63g/8nUiZ59kpdetHbzONEIhsi+Wu0lH1oY17eVN2TRW5amzrZsD0yy20WxEXrssgDJq7xPzi1sOZ56C+jdE/8p9tNUW4KYJ5GoqCVh5w0Ajkc3xRqWrpmJXUollqL+u9K6VDPqy3tmvVGdknJxHlX4q+ufAQa+Tb3qlEJwp14dhrbJERqUs5Gygc6W5Fk18+uJ6IjwvilMe8T8+t3vLDZPlOgVg4lqZaxlBn/t+RvkJ/76CDO1/Byfqmig2vE4qETJmxV+pK4Lftqjsxibe087g3EFlaO/7ZpewBkqMhR1sG/D/3Jjsevjbb32Ut+5f8JWMFL7gFHikJx6PJwxlEEfVHP/dqNkFfBJKTqjjZoj9LNxxkOngdfNDsnWigFkZUSivLNCXAJ+a4C/mHaaRf95ad20LA0NahljpcTQ7x8TR8fuAHZkFK4DnFK+ST8zSP17/yW3x9ACHU6arojAbZ0IAz2pZRRuYYl9YB07NckfhpuE2qQAu+IaHm32opV2P/l/7HZUt7hsw7wAHIKJqnBs4cNag==")
  20. #endif
  21. CPDFKit.verify(withKey: "O/Gy6kRnVkPniZrtkbxVR1TE40NTE5pBLNTKURABKTzsIIbuxTL/T5Heoq7dR8rnIucE+QnyQFm7qD1M8FYPSLa7rFNhYndz6r/tOJ/zprEPTIOC/Nw4EX6spV9KH48rd1SHQTNhzbLFaNJvDgu2/ejACIaxDQphAukW2sq99tdKa8c5i0ZVoXbf6/8I2Z3Od3majxVC1KDcp/GFYQBaZ76754mYrYfmjEUPZ7S8iUjyFIQsowcxzlliSKY7wSyLw4M0H9PYB5U9haTiQ64gBLYRmw0VtvUwqO4H/hQ9LGi6X8lGqylnDe1XlN5rXwEMSiDCAhvbmLCRDsRibJkkHmu0lH1oY17eVN2TRW5amzqhpkGcUFF17VJJZII5FrASG54RG2l/P/4nIMUZUpkQWzt+ywu1ETx64wnEWVCLqsbdRblIYesSaSBLC+ue5qj5IaZ5NrlUIullyFVfqhe0wgJTOAqc3sItd6982pDUUOfO1vBwf9Gih2qz4tARI2xVuzABfsMzje7wUE0bm1cpFckwV66yFU3arnx3YKFgKb3I+cfej7P32Ul15YgJWcFJ73lHjkMG6INyw1EEf1rPimDxLz3UnfnLfC0R03ceOgzTYO9/asHtjQN6JLAJ6RPMQGvvr0we4wc3psyfAnokxsRHkgtxfepvazk4kx4MMiYLkEkH3o/9D3jycmgmtJNNDOYy9ariKo6bXDBPENEd2iIDr6sby+Jm3qii6n3/VWRZQv/eghUvrDc0/BlUHjx8TSsbRmzsSDkeM/v3k1jSCw==")
  22. ComPDFUIConfig.initializeUIConfig()
  23. KMDesignToken.shared.parserExcel(withPath: "")
  24. }
  25. func applicationDidFinishLaunching(_ aNotification: Notification) {
  26. // Insert code here to initialize your application
  27. //通知
  28. UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
  29. if granted {
  30. KMPrint("User authorized notifications")
  31. } else {
  32. KMPrint("User denied notifications")
  33. }
  34. }
  35. /**本地推送测试
  36. UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
  37. if granted {
  38. // 创建本地推送通知
  39. let content = UNMutableNotificationContent()
  40. content.title = "Test Notification"
  41. content.body = "This is a test notification!"
  42. // 触发条件,例如延迟 5 秒触发
  43. let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
  44. // 创建通知请求
  45. let request = UNNotificationRequest(identifier: "LocalNotification", content: content, trigger: trigger)
  46. // 添加通知请求到用户通知中心
  47. UNUserNotificationCenter.current().add(request) { error in
  48. if let error = error {
  49. print("Error adding notification request: \(error)")
  50. } else {
  51. print("Local notification scheduled")
  52. }
  53. }
  54. } else {
  55. print("User denied notifications")
  56. }
  57. }
  58. **/
  59. DispatchQueue.main.async {
  60. NSApplication.shared.registerForRemoteNotifications()
  61. }
  62. #if VERSION_DMG
  63. let updater = SUUpdater.shared()
  64. updater?.delegate = self
  65. updater?.automaticallyChecksForUpdates = true
  66. #else
  67. #endif
  68. //Firebase RemoteConfig
  69. #if VERSION_FREE
  70. KMKdanRemoteConfig.remoteConfig.fetch { _status, error in
  71. }
  72. #endif
  73. let versionString = MainBundle.infoDictionary?[kCFBundleVersionKey as String] as? String ?? ""
  74. let lastVersionString = KMDataManager.ud_string(forKey: SKLastVersionLaunchedKey)
  75. if lastVersionString == nil || SKVersionNumber.compareVersionString(lastVersionString, toVersionString: versionString) == .orderedAscending {
  76. let sud = UserDefaults.standard
  77. if versionString.isEmpty == false {
  78. sud.set(versionString, forKey: SKLastVersionLaunchedKey)
  79. }
  80. // [sud setBool:NO forKey:@"kShowRecentGuideKey"];
  81. // [sud removeObjectForKey:@"kToolbarTipIsShow"];
  82. // [sud removeObjectForKey:@"kShowNoPermissionAlertKey"];
  83. // [sud removeObjectForKey:@"KMTabbingHintShowFlag"];
  84. // [sud removeObjectForKey:@"KMConverthHaveOpenConvertDetails"];
  85. sud.synchronize()
  86. }
  87. UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions" : true])
  88. NSApp.servicesProvider = self
  89. KMKdanRemoteConfig.remoteConfig.fetchWithRemoteConfigCompletionHandler { status, error in
  90. }
  91. KMStatusBar.system()
  92. // MARK: 广告数据初始化
  93. var appName: KMAdvertisementAppNameType = .PDFReaderProMac
  94. #if VERSION_FREE
  95. #if VERSION_DMG
  96. appName = .PDFReaderProMacDMG
  97. #else
  98. #endif
  99. #else
  100. appName = .PDFReaderProMacPro
  101. #endif
  102. KMAdvertisementManager.manager.initConfig(appName: appName,
  103. subscribeType: .unknow,
  104. platform: .Mac)
  105. // 测试模式,默认false
  106. KMAdvertisementManager.manager.debug = true
  107. NSApp.appearance = NSAppearance.current
  108. KMAnalytics.configure()
  109. //第一次开启app
  110. let info = UserDefaults.standard.value(forKey: "kFirstOpenAppCount")
  111. var count = 0
  112. if info != nil {
  113. count = info as? Int ?? 0
  114. }
  115. count += 1
  116. UserDefaults.standard.set(count, forKey: "kFirstOpenAppCount")
  117. UserDefaults.standard.synchronize()
  118. self.initMainMenu()
  119. /// pro
  120. // [DBClientsManager setupWithAppKeyDesktop:@"amipzwtlg9lrwyl"];
  121. DBClientsManager.setup(withAppKeyDesktop: "jxjlqfm1cfp2mjj")
  122. reopenDocument(forPaths: [])
  123. KMPreference.shared.initDataForAppLaunch()
  124. self.initiRateData()
  125. let appleEventManager = NSAppleEventManager.shared()
  126. appleEventManager.setEventHandler(self,
  127. andSelector: #selector(handleGetURLEvent(_:withReplyEvent:)),
  128. forEventClass: AEEventClass(kInternetEventClass),
  129. andEventID: AEEventID(kAEGetURL))
  130. DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
  131. #if VERSION_DMG
  132. VerificationManager.default()
  133. KMDMGProductsManager.shareInstance.getProductDatas()
  134. #else
  135. self.initiVersionData()
  136. IAPProductsManager.default().initIAP()
  137. #endif
  138. //AI相关
  139. AIInfoManager.default()
  140. NotificationCenter.default.addObserver(self, selector: #selector(AIDeviceStatusChangeNotification), name: NSNotification.Name(rawValue: "kDeviceAIStatusChangeNotification"), object: nil)
  141. for string in ["Ubuntu-Bold","Ubuntu-Medium"] {
  142. let fontURL = Bundle.main.url(forResource: string, withExtension: "ttf")
  143. var error: Unmanaged<CFError>?
  144. if !CTFontManagerRegisterFontsForURL(fontURL! as CFURL, .process, &error) {
  145. print("Failed to register font!")
  146. } else {
  147. print("Font registered successfully!")
  148. }
  149. }
  150. let appMenu = NSApp.mainMenu?.item(at: 0)?.submenu
  151. for item in appMenu!.items {
  152. if item.action == #selector(aiToolsAction) {
  153. if let tManager = VerificationManager.default() {
  154. let status = tManager.status
  155. if status == ActivityStatusNone {
  156. item.isHidden = true
  157. }
  158. }
  159. }
  160. }
  161. NotificationCenter.default.addObserver(self, selector: #selector(deviceActivateStatusChangeNotification), name: NSNotification.Name(rawValue: "kDeviceActivateNotification"), object: nil)
  162. self.initAccountRights()
  163. }
  164. func initAccountRights() {
  165. if let token = KMDataManager.ud_string(forKey: kAccountTokenKey), token.isEmpty == false {
  166. let header = ["Token" : token]
  167. KMHTTP.OEM_POST(urlString: kURLAPI_oemGetPermissions, parameter: nil, headers: header) { success, dataModel, err in
  168. if success == false { // App 启动 Token 过期 退出登陆 & 解除设备绑定,需用户重新登陆再绑定
  169. KMDataManager.ud_set("", forKey: kAccountTokenKey)
  170. AccountManager.manager.saveRights(model: nil)
  171. NotificationCenter.default.post(name: .loginStatusChanged, object: nil)
  172. VerificationManager.default().unactivateDeviceWithcomplention { status, infoDict, err in
  173. VerificationManager.default().verification {status1 , infoDict1, err1 in
  174. }
  175. }
  176. return
  177. }
  178. let model = AccountRightModel(dict: dataModel?.data as? [String : Any] ?? [:])
  179. AccountManager.manager.saveRights(model: model)
  180. NotificationCenter.default.post(name: .loginStatusChanged, object: nil)
  181. if let data = model.memberInfo?.email, data.isEmpty == false {
  182. self.activateDevice(email: data)
  183. }
  184. }
  185. }
  186. }
  187. func activateDevice(email: String) {
  188. // if IAPProductsManager.default().isAvailableAllFunction() {
  189. // return
  190. // }
  191. VerificationManager.default().activateDevice(withInfo: ["email" : email]) { status, info, err in
  192. VerificationManager.default().verification { status, info, err in
  193. }
  194. }
  195. }
  196. func initiRateData() {
  197. iRate.sharedInstance().delegate = self
  198. #if VERSION_FREE
  199. iRate.sharedInstance().appStoreID = 919472673
  200. #else
  201. iRate.sharedInstance().appStoreID = 825459243
  202. #endif
  203. iRate.sharedInstance().onlyPromptIfLatestVersion = false
  204. iRate.sharedInstance().onlyPromptIfMainWindowIsAvailable = true
  205. }
  206. //MARK: iRateDelegate
  207. func iRateUserDidDeclineToRateApp() {
  208. KMVerificationWindowController.verificationFeedback()
  209. }
  210. func iRateShouldPromptForRating() -> Bool {
  211. let notShow: Bool = UserDefaults.standard.bool(forKey: "kUserHaveClickRateUsKey")
  212. if !notShow {
  213. UserDefaults.standard.setValue(true, forKey: "kUserHaveClickRateUsKey")
  214. UserDefaults.standard.synchronize()
  215. NotificationCenter.default.post(name: Notification.Name(rawValue: "kUserHaveClickRateUsNotification"), object: self)
  216. }
  217. return false
  218. }
  219. @objc func handleGetURLEvent(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
  220. if let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue,
  221. let url = URL(string: urlString) {
  222. // 在这里处理收到的 URL Scheme
  223. KMPrint("Received URL Scheme: \(url.scheme ?? "")")
  224. KMPrint("Path: \(url.path)")
  225. if NSApp.mainWindow == nil {
  226. let bundleIdentifier: String = Bundle.main.bundleIdentifier ?? ""
  227. launchApp(bundleIdentifier: bundleIdentifier)
  228. }
  229. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  230. #if VERSION_DMG
  231. // 执行相应的操作
  232. if url.scheme == "subscriptiondmgschemes" {
  233. if urlString.contains("open=expired") {
  234. KMPrint("刷新用户信息")
  235. if !KMLightMemberManager.manager.isLogin() && NSApp.mainWindow != nil {
  236. _ = KMLoginWindowController.show(window: NSApp.mainWindow!)
  237. } else {
  238. if NSApp.mainWindow != nil && KMLightMemberManager.manager.isLogin() {
  239. _ = KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  240. }
  241. }
  242. } else if urlString.contains("open=success") {
  243. if !KMLightMemberManager.manager.isLogin() && NSApp.mainWindow != nil {
  244. _ = KMLoginWindowController.show(window: NSApp.mainWindow!)
  245. } else {
  246. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  247. if isSuccess {
  248. } else {
  249. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  250. }
  251. }
  252. }
  253. }
  254. }
  255. #endif
  256. #if VERSION_FREE
  257. // 执行相应的操作
  258. if url.scheme == "subscriptionSchemes" {
  259. //刷新用户信息
  260. KMRequestServerManager.manager.getUserInfo { success, data, error, isLocal in
  261. }
  262. if url.path == "/open" {
  263. // 执行打开操作
  264. } else if url.path == "/close" {
  265. // 执行关闭操作
  266. }
  267. }
  268. #endif
  269. }
  270. }
  271. }
  272. func launchApp(bundleIdentifier: String) {
  273. let workspace = NSWorkspace.shared
  274. // Launch the application with the specified bundle identifier
  275. if let appURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleIdentifier) {
  276. do {
  277. try workspace.launchApplication(at: appURL, options: .default, configuration: [:])
  278. } catch {
  279. print("Error launching the application: \(error)")
  280. }
  281. } else {
  282. print("Application with bundle identifier '\(bundleIdentifier)' not found.")
  283. }
  284. }
  285. func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  286. let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
  287. print("Device token:", token)
  288. }
  289. func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
  290. }
  291. func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
  292. if !flag {
  293. let browser: KMBrowser = KMBrowser.init()
  294. browser.windowController = KMBrowserWindowController.init(browser: browser)
  295. browser.addHomeTabContents()
  296. browser.windowController.showWindow(self)
  297. }
  298. return flag
  299. }
  300. @IBAction func closeDocument(_ sender: Any) {
  301. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  302. guard let windowControler = NSApp.mainWindow?.windowController else {
  303. return
  304. }
  305. windowControler.window?.performClose(nil)
  306. return
  307. }
  308. let windowControler = NSApp.mainWindow?.windowController as? KMBrowserWindowController
  309. if let data = windowControler?.browser, data.tabCount() >= 2 { // 有两个以上的标签
  310. if data.activeTabIndex() == 0 { // 主页不允许关闭,暂时处理为无反应
  311. return
  312. }
  313. }
  314. if let browser = windowControler?.browser {
  315. if browser.tabCount() == 1 {
  316. windowControler?.window?.close()
  317. } else {
  318. if let _ = windowControler?.window?.attachedSheet {
  319. NSSound.beep()
  320. return
  321. }
  322. browser.closeTab()
  323. }
  324. } else {
  325. windowControler?.window?.close()
  326. }
  327. }
  328. func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
  329. if (KMPreferenceManager.shared.openLastUnclosedDocumentWhenAppStart == false) {
  330. return false
  331. }
  332. let filepaths = KMPreferenceManager.shared.lastOpenFilepaths
  333. if (filepaths == nil || filepaths!.count == 0) {
  334. return false
  335. }
  336. DispatchQueue.main.async {
  337. for filepath in filepaths! {
  338. NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: filepath), display: true) { _, _, _ in
  339. }
  340. }
  341. }
  342. return false
  343. }
  344. func applicationWillTerminate(_ aNotification: Notification) {
  345. if (NSDocumentController.shared.documents.count > 0) {
  346. var filepaths: [String] = []
  347. for document in NSDocumentController.shared.documents {
  348. // KMPrint(document.fileURL as Any)
  349. if (document.fileURL?.path != nil) {
  350. filepaths.append((document.fileURL?.path)!)
  351. }
  352. }
  353. KMPreferenceManager.shared.lastOpenFilepaths = filepaths
  354. } else {
  355. KMPreferenceManager.shared.lastOpenFilepaths = nil
  356. }
  357. }
  358. func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
  359. return true
  360. }
  361. // MARK: private
  362. func reopenDocument(forPaths paths: [String]) -> Void {
  363. let browser = KMBrowser.init() as KMBrowser
  364. browser.windowController = KMBrowserWindowController.init(browser: browser)
  365. browser.addHomeTabContents()
  366. browser.windowController.showWindow(self)
  367. }
  368. @objc private func _themeChanged(_ sender: Notification) {
  369. let isDarkModel = KMAdvertisementConfig.isDarkModel()
  370. if isDarkModel {
  371. NSApp.appearance = .init(named: .darkAqua)
  372. } else {
  373. NSApp.appearance = .init(named: .aqua)
  374. }
  375. // if let data = NSApp.appearance?.name, data == .darkAqua {
  376. // NSApp.appearance = .init(named: .aqua)
  377. // } else {
  378. // NSApp.appearance = .init(named: .darkAqua)
  379. // }
  380. NotificationCenter.default.post(name: Notification.Name(rawValue: "kEffectiveAppearance"), object: nil)
  381. }
  382. @objc func AIDeviceStatusChangeNotification() {
  383. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  384. self.refreshAIMenuItemInfo()
  385. }
  386. }
  387. @objc func deviceActivateStatusChangeNotification() {
  388. let appMenu = NSApp.mainMenu?.item(at: 0)?.submenu
  389. for item in appMenu!.items {
  390. if item.action == #selector(aiToolsAction) {
  391. if let tManager = VerificationManager.default() {
  392. let status = tManager.status
  393. if status == ActivityStatusNone {
  394. item.isHidden = true
  395. }
  396. }
  397. }
  398. }
  399. }
  400. func refreshAIMenuItemInfo() -> Void {
  401. let appMenu = NSApp.mainMenu?.item(at: 0)?.submenu
  402. for item in appMenu!.items {
  403. if item.action == #selector(aiToolsAction) {
  404. item.isHidden = true
  405. }
  406. }
  407. }
  408. //MARK: - iVersion
  409. func initiVersionData() -> Void{
  410. #if VERSION_DMG
  411. #else
  412. let tVersion = iVersion.sharedInstance()
  413. tVersion?.applicationBundleID = Bundle.main.bundleIdentifier
  414. var tStr = "New Update Available"
  415. tVersion?.updateAvailableTitle = (tVersion?.localizedString(forKey: tStr, withDefault: tStr) ?? "") + "\n"
  416. tVersion?.versionLabelFormat = ""
  417. tVersion?.groupNotesByVersion = true
  418. tVersion?.showOnFirstLaunch = false
  419. tVersion?.checkPeriod = 2
  420. tVersion?.remindPeriod = 5
  421. let infoDictionary = Bundle .main.infoDictionary!
  422. var appName: String = infoDictionary["CFBundleDisplayName"] as! String
  423. if appName.count < 1 {
  424. appName = infoDictionary["CFBundleName"] as! String
  425. }
  426. tStr = "The new version of %@ is available now. Go update for new features.";
  427. tStr = (tVersion?.localizedString(forKey: tStr, withDefault: tStr))!
  428. tStr = String(format: tStr, appName)
  429. tVersion?.inThisVersionTitle = tStr
  430. tStr = "UPDATE NOW";
  431. tVersion!.downloadButtonLabel = tVersion?.localizedString(forKey: tStr, withDefault: tStr)
  432. tStr = "LATER";
  433. tVersion!.remindButtonLabel = tVersion?.localizedString(forKey: tStr, withDefault: tStr)
  434. tVersion!.ignoreButtonLabel = ""
  435. #endif
  436. }
  437. // MARK: - Menu
  438. func initMainMenu() {
  439. // 处理菜单栏多语
  440. let mainMenu = NSApp.mainMenu
  441. if (mainMenu == nil) {
  442. return
  443. }
  444. for menu in mainMenu!.items {
  445. let subMenu = menu.submenu
  446. for item in subMenu!.items {
  447. item.title = NSLocalizedString(item.title, comment: "")
  448. let itemSubMenu = item.submenu
  449. if (itemSubMenu == nil) {
  450. continue
  451. }
  452. for item in itemSubMenu!.items {
  453. item.title = NSLocalizedString(item.title, comment: "")
  454. let itemSubMenu = item.submenu
  455. if (itemSubMenu == nil) {
  456. continue
  457. }
  458. for item in itemSubMenu!.items {
  459. item.title = NSLocalizedString(item.title, comment: "")
  460. }
  461. }
  462. }
  463. }
  464. let PDFOfficeMenu = mainMenu?.item(at: 0)?.submenu
  465. #if VERSION_DMG
  466. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Check for Updates", comment: ""), action: #selector(checkForUpdates), target: self, at: 3)
  467. // _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Enter License", comment: ""), action: #selector(enterLicense), target: self, at: 4)
  468. // if ([VerificationManager manager].needUpgradeLicense == NO) {
  469. if VerificationManager.default().needUpgradeLicense {
  470. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("PDF to Office Pack", comment: ""), action: #selector(pdftoOfficeMenuItemAction), target: self, at: 5)
  471. }
  472. let accountRefreshItem = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Account Refresh", comment: ""), action: #selector(accountRefreshAction), target: self, at: 8)
  473. accountRefreshItem?.tag = kKMMainMenuAccountRefreshItemTag
  474. #endif
  475. #if !VERSION_DMG
  476. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Restore Previous Purchase", comment: ""), action: #selector(restoreSubscriptions), target: self, at: 1)
  477. #endif
  478. if let items = PDFOfficeMenu?.items {
  479. for menu in items {
  480. let ranges = menu.title.ranges(of: "PDFull")
  481. if let _range = ranges.range.first {
  482. menu.title.replaceSubrange(_range, with: KMTools.getAppName())
  483. }
  484. }
  485. }
  486. let fileMenu = mainMenu?.item(at: 1)?.submenu
  487. var shareItem: NSMenuItem?
  488. if let item = fileMenu?.item(withTitle: NSLocalizedString("Save Archive…", comment: "")) {
  489. shareItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  490. fileMenu?.insertItem(shareItem!, at: item.index)
  491. fileMenu?.insertItem(.separator(), at: item.index)
  492. } else {
  493. shareItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  494. fileMenu?.insertItem(shareItem!, at: (fileMenu?.items.count)!-1)
  495. }
  496. shareItem?.submenu = NSSharingServicePicker.menu(forSharingItems: [""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
  497. let deviceCameraMenuItem = NSMenuItem(title: NSLocalizedString("Import From Camera", comment: ""), action: #selector(deviceCameraMenuItemAciton), target: self)
  498. let deviceScannerMenuItem = NSMenuItem(title: NSLocalizedString("Import From Scanner", comment: ""), action: #selector(deviceScannerMenuItemAciton), target: self)
  499. fileMenu?.insertItem(deviceCameraMenuItem, at: (fileMenu?.items.count)!-1)
  500. fileMenu?.insertItem(deviceScannerMenuItem, at: (fileMenu?.items.count)!-1)
  501. fileMenu?.insertItem(.separator(), at: (fileMenu?.items.count)!-1)
  502. }
  503. @objc func sharePageItemAction(sender: NSMenuItem) {
  504. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  505. return
  506. }
  507. let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
  508. let model = windowControler.browser?.tabStripModel
  509. if let cnt = model?.count(), cnt <= 0 {
  510. return
  511. }
  512. if let data = model?.activeTabContents()?.isHome, data {
  513. return
  514. }
  515. let document: KMMainDocument = model?.activeTabContents() as! KMMainDocument
  516. if let data = document.mainViewController?.saveWatermarkFlag, !data {
  517. let represent : NSSharingService = sender.representedObject as! NSSharingService
  518. represent.perform(withItems: [document.fileURL as Any])
  519. return
  520. }
  521. let represent : NSSharingService = sender.representedObject as! NSSharingService
  522. represent.perform(withItems: [document.fileURL as Any])
  523. }
  524. @objc func deviceCameraMenuItemAciton(sender: NSMenuItem) {
  525. KMPrint("deviceCameraMenuItemAciton")
  526. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kDeviceCameraMenuItemNotification"), object: nil)
  527. }
  528. @objc func deviceScannerMenuItemAciton(sender: NSMenuItem) {
  529. KMPrint("deviceScannerMenuItemAciton")
  530. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kDeviceScannerMenuItemNotification"), object: nil)
  531. }
  532. // MARK: PDF Reader Pro Menu
  533. @IBAction func openPreferenceWindow(_ sender: Any) {
  534. KMPreferenceController.shared.showWindow(self)
  535. }
  536. @objc @IBAction func manageAcctounMenuAction(_ sender: Any) {
  537. if KMLightMemberManager.manager.isLogin() {
  538. _ = KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  539. }
  540. }
  541. @IBAction func loginMenuItemAction(_ sender: Any) {
  542. // Login & Logout
  543. if KMLightMemberManager.manager.isLogin() {
  544. } else {
  545. _ = KMLoginWindowController.show(window: NSApp.mainWindow!)
  546. }
  547. }
  548. @IBAction func logoutMenuItemAction(_ sender: Any) {
  549. // Login & Logout
  550. if KMLightMemberManager.manager.isLogin() {
  551. KMRequestServerManager.manager.logout { success, result in
  552. if success {
  553. KMPrint("登出成功")
  554. }
  555. }
  556. }
  557. }
  558. @IBAction func restoreMenuItemAction(_ sender: Any) {
  559. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  560. if isSuccess {
  561. } else {
  562. if error != .restoreSuccess {
  563. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  564. }
  565. }
  566. }
  567. }
  568. @objc func accountRefreshAction() {
  569. KMLightMemberManager.manager.updateNetworkingUserInfo { isDidLogout in
  570. }
  571. }
  572. @objc func showAccount() {
  573. }
  574. @objc func resumePurchase() {
  575. }
  576. // MARK: help Menu
  577. @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
  578. KMTools.openQuickStartStudy()
  579. }
  580. @IBAction func menuItemAction_onlineHelp(_ sender: NSMenuItem) -> Void {
  581. KMTools.openFAQWebsite()
  582. }
  583. @IBAction func menuItemAction_freePDFTemplate(_ sender: NSMenuItem) -> Void {
  584. KMTools.openFreePDFTemplatesWebsite()
  585. }
  586. @IBAction func menuItemAction_payEmail(_ sender: NSMenuItem) -> Void {
  587. KMEmailSubWindowController().showWindow(nil)
  588. }
  589. @IBAction func menuItemAction_feekback(_ sender: NSMenuItem) -> Void {
  590. KMTools.proposeNewFeature()
  591. }
  592. @objc func restoreSubscriptions(_ sender: NSMenuItem) {
  593. #if VERSION_FREE
  594. KMPrint("restoreSubscriptions ...")
  595. let compareWindowVC: KMPurchaseCompareWindowController = KMPurchaseCompareWindowController.sharedInstance() as! KMPurchaseCompareWindowController
  596. compareWindowVC.showWindowRestore(nil)
  597. #else
  598. var vc: KMToolCompareWindowController? = nil
  599. vc = KMToolCompareWindowController.toolCompare(toolType: .Convert, selectNum: 0)
  600. vc!.showWindowRestore(sender: (Any).self)
  601. #endif
  602. }
  603. // MARK:- DMG
  604. @objc func checkForUpdates(_ sender: NSMenuItem) {
  605. #if VERSION_DMG
  606. SUUpdater.shared().checkForUpdates(sender)
  607. #endif
  608. }
  609. @objc func enterLicense(_ sender: NSMenuItem) {
  610. #if VERSION_DMG
  611. if let tManager = VerificationManager.default() {
  612. let status = tManager.status
  613. if status == ActivityStatusVerifExpire {
  614. // let vc = KMVerificationWindowController.verification(with: .activateExpired)
  615. // vc?.showWindow(nil)
  616. } else if status == ActivityStatusVerification {
  617. // let vc = KMVerificationWindowController.verification(with: .info)
  618. // vc?.showWindow(nil)
  619. } else {
  620. // let vc = KMVerificationWindowController.verification(with: .activate)
  621. // vc?.showWindow(nil)
  622. }
  623. }
  624. #endif
  625. }
  626. @objc func pdftoOfficeMenuItemAction(_ sender: NSMenuItem) {
  627. #if VERSION_DMG
  628. var url = URL(string: "https://www.anyrecover.com/buy-pdf-editor-reader-converter")
  629. if SKInspectPublicTool.currentisLanguageHans() {
  630. url = URL(string: "https://www.anyrecover.com/buy-pdf-editor-reader-converter")
  631. }
  632. let tWorkSpace = NSWorkspace.shared
  633. if tWorkSpace.open(url!) == false {
  634. tWorkSpace.open(url!)
  635. }
  636. #endif
  637. // var url = URL(string: Store_Link + "?product_code=product_2")
  638. // let tWorkSpace = NSWorkspace.shared
  639. // if tWorkSpace.open(url!) == false {
  640. // tWorkSpace.open(url!)
  641. // }
  642. // let embeddedWC = KMPurchaseEmbeddedWindowController.currentFirstTrialWC("com.brother.pdfreaderpro.mac.product_2")
  643. // embeddedWC.showWindow(nil)
  644. // embeddedWC.window?.center()
  645. }
  646. @IBAction func volumeDiscount(_ sender: NSMenuItem) {
  647. var tStrHttpUrl = "https://www.pdfreaderpro.com/vpp-purchase-program"
  648. #if VERSION_DMG
  649. tStrHttpUrl = APPMain_Link + "/vpp-purchase-program?utm_source=pdfdmg&utm_campaign=menubar_vpp"
  650. #else
  651. tStrHttpUrl = APPMain_Link + "/vpp-purchase-program?utm_source=pdfmacstore&utm_campaign=menubar_vpp"
  652. #endif
  653. guard let url = URL(string: tStrHttpUrl) else {
  654. NSSound.beep()
  655. return
  656. }
  657. let tWorkSpace = NSWorkspace.shared
  658. if tWorkSpace.open(url) == false {
  659. tWorkSpace.open(url)
  660. }
  661. }
  662. @IBAction func crossPlatformAction(_ sender: NSMenuItem) {
  663. var tStrHttpUrl = CrossPlatform_Link
  664. guard let url = URL(string: tStrHttpUrl) else {
  665. return
  666. }
  667. let tWorkSpace = NSWorkspace.shared
  668. if tWorkSpace.open(url) == false {
  669. tWorkSpace.open(url)
  670. }
  671. #if VERSION_DMG
  672. FMTrackEventManager.defaultManager.trackEvent(event: "Menubar", withProperties: ["Menubar_Btn" : "Menubar_Btn_Help_CrossPlatform"])
  673. #endif
  674. }
  675. @IBAction func EducationDiscountAction(_ sender: NSMenuItem) {
  676. let tStrHttpUrl = Store_Edu_Link
  677. guard let url = URL(string: tStrHttpUrl) else {
  678. return
  679. }
  680. let tWorkSpace = NSWorkspace.shared
  681. if tWorkSpace.open(url) == false {
  682. tWorkSpace.open(url)
  683. }
  684. #if VERSION_DMG
  685. FMTrackEventManager.defaultManager.trackEvent(event: "Menubar", withProperties: ["Menubar_Btn" : "Menubar_Btn_Help_EduDiscount"])
  686. #endif
  687. }
  688. @IBAction func aiToolsAction(_ sender: NSMenuItem) {
  689. #if VERSION_DMG
  690. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  691. #else
  692. AIPurchaseWindowController.currentWC().showWindow(nil)
  693. #endif
  694. }
  695. @IBAction func orderFrontLineInspector(_ sender: Any?) {
  696. if let win = KMLineInspector.shared.window {
  697. if win.isVisible {
  698. win.orderOut(sender)
  699. } else {
  700. win.orderFront(sender)
  701. }
  702. }
  703. }
  704. @IBAction func showDownloads(_ sender: NSMenuItem) -> Void {
  705. KMPrint("showDownloads ...")
  706. }
  707. @IBAction func showWelcomeWindow(_ sender: NSMenuItem) -> Void {
  708. self.reopenDocument(forPaths: [])
  709. }
  710. @IBAction func newsletter(_ sender: NSMenuItem) -> Void {
  711. KMEmailSubWindowController().showWindow(nil)
  712. }
  713. @IBAction func feedback(_ sender: NSMenuItem) -> Void {
  714. KMTools.feekback()
  715. }
  716. @IBAction func reportBug(_ sender: NSMenuItem) -> Void {
  717. KMTools.reportBug()
  718. }
  719. @IBAction func reportGeneralQuestions(_ sender: NSMenuItem) -> Void {
  720. KMTools.reportGeneralQuestions()
  721. }
  722. }
  723. extension AppDelegate : NSMenuDelegate,NSMenuItemValidation {
  724. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  725. let action = menuItem.action
  726. if action == #selector(manageAcctounMenuAction) {
  727. self.updateLoginMenuItem()
  728. return KMLightMemberManager.manager.isLogin()
  729. }
  730. if action == #selector(loginMenuItemAction) {
  731. self.updateLoginMenuItem()
  732. return !KMLightMemberManager.manager.isLogin()
  733. }
  734. if action == #selector(logoutMenuItemAction) {
  735. self.updateLoginMenuItem()
  736. return KMLightMemberManager.manager.isLogin()
  737. }
  738. if (action == #selector(sharePageItemAction)) {
  739. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  740. return false
  741. }
  742. let isHome = _windowC.browser?.activeTabContents()?.isHome ?? false
  743. return !isHome
  744. }
  745. if action == #selector(closeDocument) {
  746. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  747. if NSApp.mainWindow?.windowController != nil {
  748. return true
  749. }
  750. return false
  751. }
  752. let isNewTab = _windowC.browser?.activeTabContents()?.isNewTab ?? false
  753. if isNewTab {
  754. return true
  755. }
  756. // let isHome = _windowC.browser?.activeTabContents()?.isHome ?? false
  757. // return !isHome
  758. }
  759. return true
  760. }
  761. func updateLoginMenuItem() {
  762. let firstItem = NSApp.mainMenu?.item(at: 0)?.submenu
  763. if firstItem != nil {
  764. let item1 = firstItem?.item(withTag: 11)
  765. let item2 = firstItem?.item(withTag: 12)
  766. let item3 = firstItem?.item(withTag: 13)
  767. let item4 = firstItem?.item(withTag: 14)
  768. // let item5 = firstItem?.item(withTag: 15)
  769. let item6 = firstItem?.item(withTag: kKMMainMenuAccountRefreshItemTag)
  770. // if KMLightMemberManager.manager.isLogin() {
  771. // item1?.title = KMLightMemberManager.manager.info.email
  772. // item1?.isHidden = false
  773. // item2?.isHidden = true
  774. // item3?.isHidden = false
  775. // item4?.isHidden = false
  776. //// item5?.isHidden = false
  777. // item6?.isHidden = false
  778. // } else {
  779. // item1?.isHidden = true
  780. // item2?.isHidden = false
  781. // item3?.isHidden = true
  782. // item4?.isHidden = true
  783. //// item5?.isHidden = true
  784. // item6?.isHidden = true
  785. // }
  786. item1?.isHidden = true
  787. item2?.isHidden = true
  788. item3?.isHidden = true
  789. item4?.isHidden = true
  790. // item5?.isHidden = true
  791. item6?.isHidden = true
  792. }
  793. }
  794. @objc func clickOutline(menuItem: NSMenuItem) {
  795. KMPrint("更新菜单栏")
  796. }
  797. func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool {
  798. return true
  799. }
  800. }
  801. #if VERSION_DMG
  802. extension AppDelegate : SUUpdaterDelegate {
  803. func updaterWillRelaunchApplication(_ updater: SUUpdater) {
  804. }
  805. func feedURLString(for updater: SUUpdater) -> String? {
  806. var hostURL = "https://static.anyrecover.com/download/"
  807. //#if DEBUG
  808. // hostURL = "http://test-pdf-pro.kdan.cn:3021/downloads/"
  809. //#else
  810. // hostURL = "https://www.pdfreaderpro.com/downloads/"
  811. //#endif
  812. return hostURL+NSLocalizedString("pdfull-mac-update.xml", comment: "")
  813. }
  814. func updaterShouldPromptForPermissionToCheck(forUpdates updater: SUUpdater) -> Bool {
  815. return false
  816. }
  817. func upgradeAPP(with updater: SUUpdater) {
  818. let string = "macappstore://apps.apple.com/app/id825459243?mt=12"
  819. let url: URL = URL(string: string)!
  820. NSWorkspace.shared.open(url)
  821. }
  822. func upgradeButtonString(for updater: SUUpdater) -> String {
  823. return NSLocalizedString("PDFull", comment: "")
  824. }
  825. }
  826. #endif
  827. extension AppDelegate {
  828. // MARK: - Services Support
  829. func openDocumentFromURLOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  830. var error: NSError?
  831. if let document = NSDocumentController.shared.openDocumentWithURLFromPasteboard(pboard, showNotes: false, outError: &error) {
  832. // Document opened successfully
  833. } else if let error = error {
  834. errorString = error.localizedDescription
  835. }
  836. }
  837. func openDocumentFromDataOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  838. var error: NSError?
  839. if let document = NSDocumentController.shared.openDocumentWithImageFromPasteboard(pboard, error: &error) {
  840. // Document opened successfully
  841. } else if let error = error {
  842. errorString = error.localizedDescription
  843. }
  844. }
  845. func openNotesDocumentFromURLOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  846. var error: NSError?
  847. if let document = NSDocumentController.shared.openDocumentWithURLFromPasteboard(pboard, showNotes: true, outError: &error) {
  848. // Document opened successfully
  849. } else if let error = error {
  850. errorString = error.localizedDescription
  851. }
  852. }
  853. }
  854. extension AppDelegate: UNUserNotificationCenterDelegate {
  855. func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  856. // 处理用户点击推送通知的操作
  857. completionHandler()
  858. }
  859. }