From 0907fd8bb5938bbadc7a3b27857a7c6398e213c7 Mon Sep 17 00:00:00 2001 From: Fin Date: Wed, 3 Jun 2020 10:32:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=82=B9=E5=87=BB=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E6=89=93=E5=BC=80APP=E6=97=B6=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=8E=A8=E9=80=81=E8=B7=B3=E8=BD=AC=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bark.xcodeproj/project.pbxproj | 24 +++--- Bark/AppDelegate.swift | 146 ++++++++++++++++----------------- 2 files changed, 85 insertions(+), 85 deletions(-) diff --git a/Bark.xcodeproj/project.pbxproj b/Bark.xcodeproj/project.pbxproj index 8a4403b..15027c6 100644 --- a/Bark.xcodeproj/project.pbxproj +++ b/Bark.xcodeproj/project.pbxproj @@ -602,12 +602,12 @@ buildSettings = { CLANG_ENABLE_OBJC_WEAK = YES; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 5U8LBRXG3A; INFOPLIST_FILE = NotificationContentExtension/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.0.8; + MARKETING_VERSION = 1.0.9; PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark.NotificationContentExtension; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -621,12 +621,12 @@ buildSettings = { CLANG_ENABLE_OBJC_WEAK = YES; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 5U8LBRXG3A; INFOPLIST_FILE = NotificationContentExtension/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.0.8; + MARKETING_VERSION = 1.0.9; PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark.NotificationContentExtension; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -756,12 +756,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Bark/Bark.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 5U8LBRXG3A; INFOPLIST_FILE = Bark/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 1.0.8; + MARKETING_VERSION = 1.0.9; PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -777,12 +777,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Bark/Bark.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 5U8LBRXG3A; INFOPLIST_FILE = Bark/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 1.0.8; + MARKETING_VERSION = 1.0.9; PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -797,12 +797,12 @@ CLANG_ENABLE_OBJC_WEAK = YES; CODE_SIGN_ENTITLEMENTS = NotificationServiceExtension/NotificationServiceExtension.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 5U8LBRXG3A; INFOPLIST_FILE = NotificationServiceExtension/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.0.8; + MARKETING_VERSION = 1.0.9; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark.NotificationServiceExtension; @@ -820,12 +820,12 @@ CLANG_ENABLE_OBJC_WEAK = YES; CODE_SIGN_ENTITLEMENTS = NotificationServiceExtension/NotificationServiceExtension.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 5U8LBRXG3A; INFOPLIST_FILE = NotificationServiceExtension/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.0.8; + MARKETING_VERSION = 1.0.9; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark.NotificationServiceExtension; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Bark/AppDelegate.swift b/Bark/AppDelegate.swift index 7ad0285..828b770 100644 --- a/Bark/AppDelegate.swift +++ b/Bark/AppDelegate.swift @@ -27,7 +27,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD self.window?.backgroundColor = Color.grey.lighten5 self.window?.rootViewController = BarkSnackbarController(rootViewController: BarkNavigationController(rootViewController: HomeViewController())) self.window?.makeKeyAndVisible() - + + UNUserNotificationCenter.current().delegate = self UNUserNotificationCenter.current().setNotificationCategories([ UNNotificationCategory(identifier: "myNotificationCategory", actions: [ UNNotificationAction(identifier: "copy", title: NSLocalizedString("Copy2"), options: UNNotificationActionOptions.foreground) @@ -37,7 +38,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD UNUserNotificationCenter.current().getNotificationSettings { (settings) in dispatch_sync_safely_main_queue { if settings.authorizationStatus == .authorized { - UNUserNotificationCenter.current().delegate = self Client.shared.registerForRemoteNotifications() } } @@ -99,78 +99,78 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD notificatonHandler(userInfo: response.notification.request.content.userInfo) } private func notificatonHandler(userInfo:[AnyHashable:Any]){ - + let navigationController = ((self.window?.rootViewController as? BarkSnackbarController)? - .rootViewController as? BarkNavigationController) - func presentController(){ - let alert = (userInfo["aps"] as? [String:Any])?["alert"] as? [String:Any] - let title = alert?["title"] as? String - let body = alert?["body"] as? String - let url:URL? = { - if let url = userInfo["url"] as? String { - return URL(string: url) - } - return nil - }() - - //URL 直接打开 - if let url = url { - if ["http","https"].contains(url.scheme?.lowercased() ?? ""){ - navigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil) - } - else{ - UIApplication.shared.open(url, options: [:], completionHandler: nil) - } - return - } - - - let alertController = UIAlertController(title: title, message: body, preferredStyle: .alert) - alertController.addAction(UIAlertAction(title: "复制内容", style: .default, handler: { (_) in - if let copy = userInfo["copy"] as? String { - UIPasteboard.general.string = copy - } - else{ - UIPasteboard.general.string = body - } - })) - alertController.addAction(UIAlertAction(title: "更多操作", style: .default, handler: { (_) in - var shareContent = "" - if let title = title { - shareContent += "\(title)\n" - } - if let body = body { - shareContent += "\(body)\n" - } - for (key,value) in userInfo { - if ["aps","title","body","url"].contains((key as? String) ?? "") { - continue - } - shareContent += "\(key): \(value) \n" - } - var items:[Any] = [] - items.append(shareContent) - if let url = url{ - items.append(url) - } - let controller = UIApplication.shared.keyWindow?.rootViewController - let activityController = UIActivityViewController(activityItems: items, - applicationActivities: nil) - controller?.present(activityController, animated: true, completion: nil) - })) - alertController.addAction(UIAlertAction(title: "取消", style: .cancel, handler: nil)) - - navigationController?.present(alertController, animated: true, completion: nil) - } - - if let presentedController = navigationController?.presentedViewController { - presentedController.dismiss(animated: false) { - presentController() - } - } - else{ - presentController() - } + .rootViewController as? BarkNavigationController) + func presentController(){ + let alert = (userInfo["aps"] as? [String:Any])?["alert"] as? [String:Any] + let title = alert?["title"] as? String + let body = alert?["body"] as? String + let url:URL? = { + if let url = userInfo["url"] as? String { + return URL(string: url) + } + return nil + }() + + //URL 直接打开 + if let url = url { + if ["http","https"].contains(url.scheme?.lowercased() ?? ""){ + navigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil) + } + else{ + UIApplication.shared.open(url, options: [:], completionHandler: nil) + } + return + } + + + let alertController = UIAlertController(title: title, message: body, preferredStyle: .alert) + alertController.addAction(UIAlertAction(title: "复制内容", style: .default, handler: { (_) in + if let copy = userInfo["copy"] as? String { + UIPasteboard.general.string = copy + } + else{ + UIPasteboard.general.string = body + } + })) + alertController.addAction(UIAlertAction(title: "更多操作", style: .default, handler: { (_) in + var shareContent = "" + if let title = title { + shareContent += "\(title)\n" + } + if let body = body { + shareContent += "\(body)\n" + } + for (key,value) in userInfo { + if ["aps","title","body","url"].contains((key as? String) ?? "") { + continue + } + shareContent += "\(key): \(value) \n" + } + var items:[Any] = [] + items.append(shareContent) + if let url = url{ + items.append(url) + } + let controller = UIApplication.shared.keyWindow?.rootViewController + let activityController = UIActivityViewController(activityItems: items, + applicationActivities: nil) + controller?.present(activityController, animated: true, completion: nil) + })) + alertController.addAction(UIAlertAction(title: "取消", style: .cancel, handler: nil)) + + navigationController?.present(alertController, animated: true, completion: nil) + } + + if let presentedController = navigationController?.presentedViewController { + presentedController.dismiss(animated: false) { + presentController() + } + } + else{ + presentController() + } } func applicationWillResignActive(_ application: UIApplication) {