修复点击推送打开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 = {
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)";

View File

@ -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) {