AppDelegate.swift 39 KB

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