修复点击推送打开APP时,不执行推送跳转操作的问题

This commit is contained in:
Fin 2020-06-03 10:32:29 +08:00
parent ba9756dc6b
commit 0907fd8bb5
2 changed files with 85 additions and 85 deletions

View File

@ -602,12 +602,12 @@
buildSettings = { buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES; CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5U8LBRXG3A; DEVELOPMENT_TEAM = 5U8LBRXG3A;
INFOPLIST_FILE = NotificationContentExtension/Info.plist; INFOPLIST_FILE = NotificationContentExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0; IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; 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_BUNDLE_IDENTIFIER = me.fin.bark.NotificationContentExtension;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
@ -621,12 +621,12 @@
buildSettings = { buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES; CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5U8LBRXG3A; DEVELOPMENT_TEAM = 5U8LBRXG3A;
INFOPLIST_FILE = NotificationContentExtension/Info.plist; INFOPLIST_FILE = NotificationContentExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0; IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; 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_BUNDLE_IDENTIFIER = me.fin.bark.NotificationContentExtension;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
@ -756,12 +756,12 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Bark/Bark.entitlements; CODE_SIGN_ENTITLEMENTS = Bark/Bark.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5U8LBRXG3A; DEVELOPMENT_TEAM = 5U8LBRXG3A;
INFOPLIST_FILE = Bark/Info.plist; INFOPLIST_FILE = Bark/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0; IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 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_BUNDLE_IDENTIFIER = me.fin.bark;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
@ -777,12 +777,12 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Bark/Bark.entitlements; CODE_SIGN_ENTITLEMENTS = Bark/Bark.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5U8LBRXG3A; DEVELOPMENT_TEAM = 5U8LBRXG3A;
INFOPLIST_FILE = Bark/Info.plist; INFOPLIST_FILE = Bark/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0; IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 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_BUNDLE_IDENTIFIER = me.fin.bark;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
@ -797,12 +797,12 @@
CLANG_ENABLE_OBJC_WEAK = YES; CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_ENTITLEMENTS = NotificationServiceExtension/NotificationServiceExtension.entitlements; CODE_SIGN_ENTITLEMENTS = NotificationServiceExtension/NotificationServiceExtension.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5U8LBRXG3A; DEVELOPMENT_TEAM = 5U8LBRXG3A;
INFOPLIST_FILE = NotificationServiceExtension/Info.plist; INFOPLIST_FILE = NotificationServiceExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0; IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; 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_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES; MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark.NotificationServiceExtension; PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark.NotificationServiceExtension;
@ -820,12 +820,12 @@
CLANG_ENABLE_OBJC_WEAK = YES; CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_ENTITLEMENTS = NotificationServiceExtension/NotificationServiceExtension.entitlements; CODE_SIGN_ENTITLEMENTS = NotificationServiceExtension/NotificationServiceExtension.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5U8LBRXG3A; DEVELOPMENT_TEAM = 5U8LBRXG3A;
INFOPLIST_FILE = NotificationServiceExtension/Info.plist; INFOPLIST_FILE = NotificationServiceExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0; IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; 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; MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark.NotificationServiceExtension; PRODUCT_BUNDLE_IDENTIFIER = me.fin.bark.NotificationServiceExtension;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";

View File

@ -27,7 +27,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
self.window?.backgroundColor = Color.grey.lighten5 self.window?.backgroundColor = Color.grey.lighten5
self.window?.rootViewController = BarkSnackbarController(rootViewController: BarkNavigationController(rootViewController: HomeViewController())) self.window?.rootViewController = BarkSnackbarController(rootViewController: BarkNavigationController(rootViewController: HomeViewController()))
self.window?.makeKeyAndVisible() self.window?.makeKeyAndVisible()
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().setNotificationCategories([ UNUserNotificationCenter.current().setNotificationCategories([
UNNotificationCategory(identifier: "myNotificationCategory", actions: [ UNNotificationCategory(identifier: "myNotificationCategory", actions: [
UNNotificationAction(identifier: "copy", title: NSLocalizedString("Copy2"), options: UNNotificationActionOptions.foreground) UNNotificationAction(identifier: "copy", title: NSLocalizedString("Copy2"), options: UNNotificationActionOptions.foreground)
@ -37,7 +38,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
UNUserNotificationCenter.current().getNotificationSettings { (settings) in UNUserNotificationCenter.current().getNotificationSettings { (settings) in
dispatch_sync_safely_main_queue { dispatch_sync_safely_main_queue {
if settings.authorizationStatus == .authorized { if settings.authorizationStatus == .authorized {
UNUserNotificationCenter.current().delegate = self
Client.shared.registerForRemoteNotifications() Client.shared.registerForRemoteNotifications()
} }
} }
@ -99,78 +99,78 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
notificatonHandler(userInfo: response.notification.request.content.userInfo) notificatonHandler(userInfo: response.notification.request.content.userInfo)
} }
private func notificatonHandler(userInfo:[AnyHashable:Any]){ private func notificatonHandler(userInfo:[AnyHashable:Any]){
let navigationController = ((self.window?.rootViewController as? BarkSnackbarController)? let navigationController = ((self.window?.rootViewController as? BarkSnackbarController)?
.rootViewController as? BarkNavigationController) .rootViewController as? BarkNavigationController)
func presentController(){ func presentController(){
let alert = (userInfo["aps"] as? [String:Any])?["alert"] as? [String:Any] let alert = (userInfo["aps"] as? [String:Any])?["alert"] as? [String:Any]
let title = alert?["title"] as? String let title = alert?["title"] as? String
let body = alert?["body"] as? String let body = alert?["body"] as? String
let url:URL? = { let url:URL? = {
if let url = userInfo["url"] as? String { if let url = userInfo["url"] as? String {
return URL(string: url) return URL(string: url)
} }
return nil return nil
}() }()
//URL //URL
if let url = url { if let url = url {
if ["http","https"].contains(url.scheme?.lowercased() ?? ""){ if ["http","https"].contains(url.scheme?.lowercased() ?? ""){
navigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil) navigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil)
} }
else{ else{
UIApplication.shared.open(url, options: [:], completionHandler: nil) UIApplication.shared.open(url, options: [:], completionHandler: nil)
} }
return return
} }
let alertController = UIAlertController(title: title, message: body, preferredStyle: .alert) let alertController = UIAlertController(title: title, message: body, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "复制内容", style: .default, handler: { (_) in alertController.addAction(UIAlertAction(title: "复制内容", style: .default, handler: { (_) in
if let copy = userInfo["copy"] as? String { if let copy = userInfo["copy"] as? String {
UIPasteboard.general.string = copy UIPasteboard.general.string = copy
} }
else{ else{
UIPasteboard.general.string = body UIPasteboard.general.string = body
} }
})) }))
alertController.addAction(UIAlertAction(title: "更多操作", style: .default, handler: { (_) in alertController.addAction(UIAlertAction(title: "更多操作", style: .default, handler: { (_) in
var shareContent = "" var shareContent = ""
if let title = title { if let title = title {
shareContent += "\(title)\n" shareContent += "\(title)\n"
} }
if let body = body { if let body = body {
shareContent += "\(body)\n" shareContent += "\(body)\n"
} }
for (key,value) in userInfo { for (key,value) in userInfo {
if ["aps","title","body","url"].contains((key as? String) ?? "") { if ["aps","title","body","url"].contains((key as? String) ?? "") {
continue continue
} }
shareContent += "\(key): \(value) \n" shareContent += "\(key): \(value) \n"
} }
var items:[Any] = [] var items:[Any] = []
items.append(shareContent) items.append(shareContent)
if let url = url{ if let url = url{
items.append(url) items.append(url)
} }
let controller = UIApplication.shared.keyWindow?.rootViewController let controller = UIApplication.shared.keyWindow?.rootViewController
let activityController = UIActivityViewController(activityItems: items, let activityController = UIActivityViewController(activityItems: items,
applicationActivities: nil) applicationActivities: nil)
controller?.present(activityController, animated: true, completion: nil) controller?.present(activityController, animated: true, completion: nil)
})) }))
alertController.addAction(UIAlertAction(title: "取消", style: .cancel, handler: nil)) alertController.addAction(UIAlertAction(title: "取消", style: .cancel, handler: nil))
navigationController?.present(alertController, animated: true, completion: nil) navigationController?.present(alertController, animated: true, completion: nil)
} }
if let presentedController = navigationController?.presentedViewController { if let presentedController = navigationController?.presentedViewController {
presentedController.dismiss(animated: false) { presentedController.dismiss(animated: false) {
presentController() presentController()
} }
} }
else{ else{
presentController() presentController()
} }
} }
func applicationWillResignActive(_ application: UIApplication) { func applicationWillResignActive(_ application: UIApplication) {