From 5f53de020aa42f5c206d875fea274097650f94ca Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Wed, 11 Nov 2020 14:24:01 -0800 Subject: [PATCH 1/8] add notification delegate --- .../Capacitor.xcodeproj/project.pbxproj | 9 +++- .../NotificationHandlerProtocol.swift | 6 +++ .../UserNotificationCenterDelegate.swift | 54 +++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 ios/Capacitor/Capacitor/NotificationHandlerProtocol.swift create mode 100644 ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift diff --git a/ios/Capacitor/Capacitor.xcodeproj/project.pbxproj b/ios/Capacitor/Capacitor.xcodeproj/project.pbxproj index e21e3f220a..ef788cb9ba 100644 --- a/ios/Capacitor/Capacitor.xcodeproj/project.pbxproj +++ b/ios/Capacitor/Capacitor.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 373A69C1255C9360000A6F44 /* NotificationHandlerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373A69C0255C9360000A6F44 /* NotificationHandlerProtocol.swift */; }; + 373A69F2255C95D0000A6F44 /* UserNotificationCenterDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373A69F1255C95D0000A6F44 /* UserNotificationCenterDelegate.swift */; }; 501CBAA71FC0A723009B0D4D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 501CBAA61FC0A723009B0D4D /* WebKit.framework */; }; 50503EE91FC08595003606DC /* Capacitor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50503EDF1FC08594003606DC /* Capacitor.framework */; }; 50503EEE1FC08595003606DC /* CapacitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50503EED1FC08595003606DC /* CapacitorTests.swift */; }; @@ -107,6 +109,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 373A69C0255C9360000A6F44 /* NotificationHandlerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationHandlerProtocol.swift; sourceTree = ""; }; + 373A69F1255C95D0000A6F44 /* UserNotificationCenterDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserNotificationCenterDelegate.swift; sourceTree = ""; }; 501CBAA61FC0A723009B0D4D /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 50503EDF1FC08594003606DC /* Capacitor.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Capacitor.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 50503EE81FC08595003606DC /* CapacitorTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CapacitorTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -276,7 +280,6 @@ 62959B082524DA7700A3D7F1 /* CAPLog.swift */, 62959AE72524DA7700A3D7F1 /* CAPFile.swift */, 62959B0B2524DA7700A3D7F1 /* CAPMessageHandlerWrapper.swift */, - 62959B022524DA7700A3D7F1 /* CAPUNUserNotificationCenterDelegate.swift */, 62959B0D2524DA7700A3D7F1 /* CAPAssetHandler.swift */, 62959B0E2524DA7700A3D7F1 /* TmpViewController.swift */, 62959B102524DA7700A3D7F1 /* DocLinks.swift */, @@ -287,6 +290,8 @@ 62959AFE2524DA7700A3D7F1 /* UIStatusBarManager+CAPHandleTapAction.m */, 62959B122524DA7700A3D7F1 /* Info.plist */, 62959B8225253A9500A3D7F1 /* Capacitor.modulemap */, + 373A69C0255C9360000A6F44 /* NotificationHandlerProtocol.swift */, + 373A69F1255C95D0000A6F44 /* UserNotificationCenterDelegate.swift */, ); path = Capacitor; sourceTree = ""; @@ -511,12 +516,14 @@ 62959B472524DA7800A3D7F1 /* CAPNotifications.swift in Sources */, 62959B312524DA7800A3D7F1 /* JS.swift in Sources */, 62959B292524DA7800A3D7F1 /* SplashScreen.swift in Sources */, + 373A69F2255C95D0000A6F44 /* UserNotificationCenterDelegate.swift in Sources */, 62959B1A2524DA7800A3D7F1 /* CAPPluginCall.swift in Sources */, 62959B302524DA7800A3D7F1 /* UIStatusBarManager+CAPHandleTapAction.m in Sources */, 62959B392524DA7800A3D7F1 /* CapacitorExtension.swift in Sources */, 62959B3D2524DA7800A3D7F1 /* CAPMessageHandlerWrapper.swift in Sources */, 62959B422524DA7800A3D7F1 /* DocLinks.swift in Sources */, 62959B172524DA7800A3D7F1 /* JSExport.swift in Sources */, + 373A69C1255C9360000A6F44 /* NotificationHandlerProtocol.swift in Sources */, 62959B3F2524DA7800A3D7F1 /* CAPAssetHandler.swift in Sources */, 62959B3C2524DA7800A3D7F1 /* CAPBridgeDelegate.swift in Sources */, 62959B2F2524DA7800A3D7F1 /* DefaultPlugins.m in Sources */, diff --git a/ios/Capacitor/Capacitor/NotificationHandlerProtocol.swift b/ios/Capacitor/Capacitor/NotificationHandlerProtocol.swift new file mode 100644 index 0000000000..2b559bd811 --- /dev/null +++ b/ios/Capacitor/Capacitor/NotificationHandlerProtocol.swift @@ -0,0 +1,6 @@ +import Foundation + +@objc(CAPNotificationHandlerProtocol) public protocol NotificationHandlerProtocol { + func willPresent(notification: UNNotification) -> UNNotificationPresentationOptions + func didReceive(response: UNNotificationResponse) +} diff --git a/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift b/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift new file mode 100644 index 0000000000..ad7f9039c5 --- /dev/null +++ b/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift @@ -0,0 +1,54 @@ +import Foundation + +@objc(CAPUNUserNotificationCenterDelegate) public class UserNotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate { + public override init() { + // TODO: make better + super.init() + let center = UNUserNotificationCenter.current() + if center.delegate == nil { + center.delegate = self + } + } + + public weak var pushNotificationHandler: NotificationHandlerProtocol? { + didSet { + if pushNotificationHandler != nil, oldValue != nil { + CAPLog.print("Push notification handler overriding previous instance: \(String(describing: type(of: oldValue)))") + } + } + } + + public weak var localNotificationHandler: NotificationHandlerProtocol? { + didSet { + if localNotificationHandler != nil, oldValue != nil { + CAPLog.print("Local notification handler overriding previous instance: \(String(describing: type(of: oldValue)))") + } + } + } + + public func userNotificationCenter(_ center: UNUserNotificationCenter, + willPresent notification: UNNotification, + withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { + let presentationOptions: UNNotificationPresentationOptions? + + if notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self) == true { + presentationOptions = pushNotificationHandler?.willPresent(notification: notification) + } else { + presentationOptions = localNotificationHandler?.willPresent(notification: notification) + } + + completionHandler(presentationOptions ?? []) + } + + public func userNotificationCenter(_ center: UNUserNotificationCenter, + didReceive response: UNNotificationResponse, + withCompletionHandler completionHandler: @escaping () -> Void) { + if response.notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self) == true { + pushNotificationHandler?.didReceive(response: response) + } else { + localNotificationHandler?.didReceive(response: response) + } + + completionHandler() + } +} From 28ac7ddfb06f4089e524246592989c4afd2db613 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Wed, 11 Nov 2020 14:54:34 -0800 Subject: [PATCH 2/8] expose notification delegate --- ios/Capacitor/Capacitor/CAPBridgeProtocol.swift | 1 + ios/Capacitor/Capacitor/CapacitorBridge.swift | 3 +++ 2 files changed, 4 insertions(+) diff --git a/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift b/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift index f90409eca1..09ad4925d8 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift @@ -6,6 +6,7 @@ import WebKit var viewController: UIViewController? { get } var config: CAPConfig { get } var webView: WKWebView? { get } + var userNotificationDelegate: UserNotificationCenterDelegate { get } var isSimEnvironment: Bool { get } var isDevEnvironment: Bool { get } @available(iOS 12.0, *) diff --git a/ios/Capacitor/Capacitor/CapacitorBridge.swift b/ios/Capacitor/Capacitor/CapacitorBridge.swift index c19bb2bc66..12f27af9ba 100644 --- a/ios/Capacitor/Capacitor/CapacitorBridge.swift +++ b/ios/Capacitor/Capacitor/CapacitorBridge.swift @@ -16,6 +16,8 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { return bridgeDelegate?.bridgedWebView } + private(set) var userNotificationDelegate: UserNotificationCenterDelegate + public var isSimEnvironment: Bool { #if targetEnvironment(simulator) return true @@ -171,6 +173,7 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { self.messageHandlerWrapper = messageHandlerWrapper self.config = config self.scheme = scheme + self.userNotificationDelegate = UserNotificationCenterDelegate() super.init() From 0a1a2cdbc56ae73ae7f18dcaa3a780481b140190 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Wed, 11 Nov 2020 14:57:21 -0800 Subject: [PATCH 3/8] remove redundant modifiers --- .../Capacitor/UserNotificationCenterDelegate.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift b/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift index ad7f9039c5..3fd22a5d8b 100644 --- a/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift +++ b/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift @@ -1,7 +1,7 @@ import Foundation @objc(CAPUNUserNotificationCenterDelegate) public class UserNotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate { - public override init() { + override init() { // TODO: make better super.init() let center = UNUserNotificationCenter.current() @@ -10,7 +10,7 @@ import Foundation } } - public weak var pushNotificationHandler: NotificationHandlerProtocol? { + weak var pushNotificationHandler: NotificationHandlerProtocol? { didSet { if pushNotificationHandler != nil, oldValue != nil { CAPLog.print("Push notification handler overriding previous instance: \(String(describing: type(of: oldValue)))") @@ -18,7 +18,7 @@ import Foundation } } - public weak var localNotificationHandler: NotificationHandlerProtocol? { + weak var localNotificationHandler: NotificationHandlerProtocol? { didSet { if localNotificationHandler != nil, oldValue != nil { CAPLog.print("Local notification handler overriding previous instance: \(String(describing: type(of: oldValue)))") From 445d0dd5bd8709c37988deef768af98ce7477b56 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Thu, 19 Nov 2020 16:10:50 -0800 Subject: [PATCH 4/8] these must be public, otherwise 'internal' --- ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift b/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift index 3fd22a5d8b..c19b87b91f 100644 --- a/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift +++ b/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift @@ -10,7 +10,7 @@ import Foundation } } - weak var pushNotificationHandler: NotificationHandlerProtocol? { + public weak var pushNotificationHandler: NotificationHandlerProtocol? { didSet { if pushNotificationHandler != nil, oldValue != nil { CAPLog.print("Push notification handler overriding previous instance: \(String(describing: type(of: oldValue)))") @@ -18,7 +18,7 @@ import Foundation } } - weak var localNotificationHandler: NotificationHandlerProtocol? { + public weak var localNotificationHandler: NotificationHandlerProtocol? { didSet { if localNotificationHandler != nil, oldValue != nil { CAPLog.print("Local notification handler overriding previous instance: \(String(describing: type(of: oldValue)))") From 58cade0f1db15b86e3b4ec7378de5ab771e2bf03 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 24 Nov 2020 17:23:36 -0800 Subject: [PATCH 5/8] configurable --- .../Capacitor/CAPInstanceConfiguration.h | 1 + .../Capacitor/CAPInstanceConfiguration.m | 1 + ios/Capacitor/Capacitor/CAPInstanceDescriptor.h | 1 + ios/Capacitor/Capacitor/CAPInstanceDescriptor.m | 1 + ios/Capacitor/Capacitor/CapacitorBridge.swift | 7 ++++++- .../UserNotificationCenterDelegate.swift | 17 ++++------------- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h index 2f7d3cd033..7e946177e8 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h +++ b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h @@ -17,6 +17,7 @@ NS_SWIFT_NAME(InstanceConfiguration) @property (nonatomic, readonly) BOOL enableLogging; @property (nonatomic, readonly) BOOL enableScrolling; @property (nonatomic, readonly) BOOL allowLinkPreviews; +@property (nonatomic, readonly) BOOL assignUserNotificationCenterDelegate; @property (nonatomic, readonly) BOOL cordovaDeployDisabled; @property (nonatomic, readonly) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior; @property (nonatomic, readonly, nonnull) NSURL *appLocation; diff --git a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m index ad8c7b5a2b..aa500661ce 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m +++ b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m @@ -15,6 +15,7 @@ - (instancetype)initWithDescriptor:(CAPInstanceDescriptor *)descriptor { _enableLogging = descriptor.enableLogging; _enableScrolling = descriptor.enableScrolling; _allowLinkPreviews = descriptor.allowLinkPreviews; + _assignUserNotificationCenterDelegate = descriptor.assignUserNotificationCenterDelegate; _contentInsetAdjustmentBehavior = descriptor.contentInsetAdjustmentBehavior; _appLocation = descriptor.appLocation; _pluginConfigurations = descriptor.pluginConfigurations; diff --git a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h index 48433a533d..30bd0bb896 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h +++ b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h @@ -34,6 +34,7 @@ NS_SWIFT_NAME(InstanceDescriptor) @property (nonatomic, assign) BOOL enableLogging; @property (nonatomic, assign) BOOL enableScrolling; @property (nonatomic, assign) BOOL allowLinkPreviews; +@property (nonatomic, assign) BOOL assignUserNotificationCenterDelegate; @property (nonatomic, assign) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior; @property (nonatomic, copy, nonnull) NSURL *appLocation; @property (nonatomic, copy, nonnull) CDVConfigParser *cordovaConfiguration; diff --git a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m index c4c0c08473..1ad0cf0895 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m +++ b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m @@ -38,6 +38,7 @@ - (void)_setDefaultsWithAppLocation:(NSURL*)location { _enableLogging = YES; _enableScrolling = YES; _allowLinkPreviews = YES; + _assignUserNotificationCenterDelegate = YES; _contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; _appLocation = location; _cordovaConfiguration = [[CDVConfigParser alloc] init]; diff --git a/ios/Capacitor/Capacitor/CapacitorBridge.swift b/ios/Capacitor/Capacitor/CapacitorBridge.swift index f8a76f86f2..ddd14f1f0a 100644 --- a/ios/Capacitor/Capacitor/CapacitorBridge.swift +++ b/ios/Capacitor/Capacitor/CapacitorBridge.swift @@ -16,7 +16,7 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { return bridgeDelegate?.bridgedWebView } - private(set) var userNotificationDelegate: UserNotificationCenterDelegate + private(set) weak var userNotificationDelegate: UserNotificationCenterDelegate public var isSimEnvironment: Bool { #if targetEnvironment(simulator) @@ -176,6 +176,11 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { self.cordovaParser = cordovaConfiguration self.userNotificationDelegate = UserNotificationCenterDelegate() + if configuration.assignUserNotificationCenterDelegate { + let center = UNUserNotificationCenter.current() + center.delegate = userNotificationDelegate + } + super.init() self.messageHandlerWrapper.bridge = self diff --git a/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift b/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift index c19b87b91f..98bd8f8ad7 100644 --- a/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift +++ b/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift @@ -1,15 +1,6 @@ import Foundation -@objc(CAPUNUserNotificationCenterDelegate) public class UserNotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate { - override init() { - // TODO: make better - super.init() - let center = UNUserNotificationCenter.current() - if center.delegate == nil { - center.delegate = self - } - } - +@objc(CAPUNUserNotificationCenterDelegate) public class UserNotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate { public weak var pushNotificationHandler: NotificationHandlerProtocol? { didSet { if pushNotificationHandler != nil, oldValue != nil { @@ -17,7 +8,7 @@ import Foundation } } } - + public weak var localNotificationHandler: NotificationHandlerProtocol? { didSet { if localNotificationHandler != nil, oldValue != nil { @@ -36,7 +27,7 @@ import Foundation } else { presentationOptions = localNotificationHandler?.willPresent(notification: notification) } - + completionHandler(presentationOptions ?? []) } @@ -48,7 +39,7 @@ import Foundation } else { localNotificationHandler?.didReceive(response: response) } - + completionHandler() } } From d083b6704c71e20d3209ad60e55f8bff9cde733c Mon Sep 17 00:00:00 2001 From: Dan Imhoff Date: Wed, 25 Nov 2020 09:39:28 -0800 Subject: [PATCH 6/8] Update ios/Capacitor/Capacitor/CapacitorBridge.swift Co-authored-by: Ian Keith --- ios/Capacitor/Capacitor/CapacitorBridge.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Capacitor/Capacitor/CapacitorBridge.swift b/ios/Capacitor/Capacitor/CapacitorBridge.swift index ddd14f1f0a..485cfeb208 100644 --- a/ios/Capacitor/Capacitor/CapacitorBridge.swift +++ b/ios/Capacitor/Capacitor/CapacitorBridge.swift @@ -16,7 +16,7 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { return bridgeDelegate?.bridgedWebView } - private(set) weak var userNotificationDelegate: UserNotificationCenterDelegate + public var userNotificationDelegate: UserNotificationCenterDelegate public var isSimEnvironment: Bool { #if targetEnvironment(simulator) From e7d99ba11cd91bf12a4fe82fb371067b57116151 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Wed, 25 Nov 2020 09:53:14 -0800 Subject: [PATCH 7/8] move delegate setup into property --- ios/Capacitor/Capacitor/CapacitorBridge.swift | 6 +----- .../UserNotificationCenterDelegate.swift | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ios/Capacitor/Capacitor/CapacitorBridge.swift b/ios/Capacitor/Capacitor/CapacitorBridge.swift index 485cfeb208..3ccd69e60b 100644 --- a/ios/Capacitor/Capacitor/CapacitorBridge.swift +++ b/ios/Capacitor/Capacitor/CapacitorBridge.swift @@ -175,11 +175,7 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { self.config = configuration self.cordovaParser = cordovaConfiguration self.userNotificationDelegate = UserNotificationCenterDelegate() - - if configuration.assignUserNotificationCenterDelegate { - let center = UNUserNotificationCenter.current() - center.delegate = userNotificationDelegate - } + self.userNotificationDelegate.handleNotifications = configuration.assignUserNotificationCenterDelegate super.init() diff --git a/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift b/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift index 98bd8f8ad7..627fda768a 100644 --- a/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift +++ b/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift @@ -1,6 +1,21 @@ import Foundation @objc(CAPUNUserNotificationCenterDelegate) public class UserNotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate { + var handleNotifications: Bool { + get { + return UNUserNotificationCenter.current().delegate === self + } + set { + let center = UNUserNotificationCenter.current() + + if newValue { + center.delegate = self + } else if center.delegate === self { + center.delegate = nil + } + } + } + public weak var pushNotificationHandler: NotificationHandlerProtocol? { didSet { if pushNotificationHandler != nil, oldValue != nil { From 0a25fff90b4a40ba625957a2c1ef274d6243cc23 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Wed, 25 Nov 2020 10:01:31 -0800 Subject: [PATCH 8/8] renames --- ios/Capacitor/Capacitor.xcodeproj/project.pbxproj | 8 ++++---- ios/Capacitor/Capacitor/CAPBridgeProtocol.swift | 2 +- ios/Capacitor/Capacitor/CAPInstanceConfiguration.h | 2 +- ios/Capacitor/Capacitor/CAPInstanceConfiguration.m | 2 +- ios/Capacitor/Capacitor/CAPInstanceDescriptor.h | 2 +- ios/Capacitor/Capacitor/CAPInstanceDescriptor.m | 2 +- ios/Capacitor/Capacitor/CapacitorBridge.swift | 6 +++--- ...ationCenterDelegate.swift => NotificationRouter.swift} | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) rename ios/Capacitor/Capacitor/{UserNotificationCenterDelegate.swift => NotificationRouter.swift} (93%) diff --git a/ios/Capacitor/Capacitor.xcodeproj/project.pbxproj b/ios/Capacitor/Capacitor.xcodeproj/project.pbxproj index fdf8f4a471..3c97539366 100644 --- a/ios/Capacitor/Capacitor.xcodeproj/project.pbxproj +++ b/ios/Capacitor/Capacitor.xcodeproj/project.pbxproj @@ -8,7 +8,7 @@ /* Begin PBXBuildFile section */ 373A69C1255C9360000A6F44 /* NotificationHandlerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373A69C0255C9360000A6F44 /* NotificationHandlerProtocol.swift */; }; - 373A69F2255C95D0000A6F44 /* UserNotificationCenterDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373A69F1255C95D0000A6F44 /* UserNotificationCenterDelegate.swift */; }; + 373A69F2255C95D0000A6F44 /* NotificationRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373A69F1255C95D0000A6F44 /* NotificationRouter.swift */; }; 501CBAA71FC0A723009B0D4D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 501CBAA61FC0A723009B0D4D /* WebKit.framework */; }; 50503EE91FC08595003606DC /* Capacitor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50503EDF1FC08594003606DC /* Capacitor.framework */; }; 50503EEE1FC08595003606DC /* CapacitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50503EED1FC08595003606DC /* CapacitorTests.swift */; }; @@ -125,7 +125,7 @@ /* Begin PBXFileReference section */ 373A69C0255C9360000A6F44 /* NotificationHandlerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationHandlerProtocol.swift; sourceTree = ""; }; - 373A69F1255C95D0000A6F44 /* UserNotificationCenterDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserNotificationCenterDelegate.swift; sourceTree = ""; }; + 373A69F1255C95D0000A6F44 /* NotificationRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationRouter.swift; sourceTree = ""; }; 501CBAA61FC0A723009B0D4D /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 50503EDF1FC08594003606DC /* Capacitor.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Capacitor.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 50503EE81FC08595003606DC /* CapacitorTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CapacitorTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -324,7 +324,7 @@ 62959B122524DA7700A3D7F1 /* Info.plist */, 62959B8225253A9500A3D7F1 /* Capacitor.modulemap */, 373A69C0255C9360000A6F44 /* NotificationHandlerProtocol.swift */, - 373A69F1255C95D0000A6F44 /* UserNotificationCenterDelegate.swift */, + 373A69F1255C95D0000A6F44 /* NotificationRouter.swift */, ); path = Capacitor; sourceTree = ""; @@ -563,7 +563,7 @@ 62959B472524DA7800A3D7F1 /* CAPNotifications.swift in Sources */, 62959B312524DA7800A3D7F1 /* JS.swift in Sources */, 62959B292524DA7800A3D7F1 /* SplashScreen.swift in Sources */, - 373A69F2255C95D0000A6F44 /* UserNotificationCenterDelegate.swift in Sources */, + 373A69F2255C95D0000A6F44 /* NotificationRouter.swift in Sources */, 62959B1A2524DA7800A3D7F1 /* CAPPluginCall.swift in Sources */, 62959B302524DA7800A3D7F1 /* UIStatusBarManager+CAPHandleTapAction.m in Sources */, 62959B392524DA7800A3D7F1 /* CapacitorExtension.swift in Sources */, diff --git a/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift b/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift index 546693979f..37680bd566 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeProtocol.swift @@ -6,7 +6,7 @@ import WebKit var viewController: UIViewController? { get } var config: InstanceConfiguration { get } var webView: WKWebView? { get } - var userNotificationDelegate: UserNotificationCenterDelegate { get } + var notificationRouter: NotificationRouter { get } var isSimEnvironment: Bool { get } var isDevEnvironment: Bool { get } @available(iOS 12.0, *) diff --git a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h index 7e946177e8..e292ff09a7 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h +++ b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h @@ -17,7 +17,7 @@ NS_SWIFT_NAME(InstanceConfiguration) @property (nonatomic, readonly) BOOL enableLogging; @property (nonatomic, readonly) BOOL enableScrolling; @property (nonatomic, readonly) BOOL allowLinkPreviews; -@property (nonatomic, readonly) BOOL assignUserNotificationCenterDelegate; +@property (nonatomic, readonly) BOOL handleApplicationNotifications; @property (nonatomic, readonly) BOOL cordovaDeployDisabled; @property (nonatomic, readonly) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior; @property (nonatomic, readonly, nonnull) NSURL *appLocation; diff --git a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m index aa500661ce..0acdef46f5 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m +++ b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m @@ -15,7 +15,7 @@ - (instancetype)initWithDescriptor:(CAPInstanceDescriptor *)descriptor { _enableLogging = descriptor.enableLogging; _enableScrolling = descriptor.enableScrolling; _allowLinkPreviews = descriptor.allowLinkPreviews; - _assignUserNotificationCenterDelegate = descriptor.assignUserNotificationCenterDelegate; + _handleApplicationNotifications = descriptor.handleApplicationNotifications; _contentInsetAdjustmentBehavior = descriptor.contentInsetAdjustmentBehavior; _appLocation = descriptor.appLocation; _pluginConfigurations = descriptor.pluginConfigurations; diff --git a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h index 30bd0bb896..0f7469e397 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h +++ b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h @@ -34,7 +34,7 @@ NS_SWIFT_NAME(InstanceDescriptor) @property (nonatomic, assign) BOOL enableLogging; @property (nonatomic, assign) BOOL enableScrolling; @property (nonatomic, assign) BOOL allowLinkPreviews; -@property (nonatomic, assign) BOOL assignUserNotificationCenterDelegate; +@property (nonatomic, assign) BOOL handleApplicationNotifications; @property (nonatomic, assign) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior; @property (nonatomic, copy, nonnull) NSURL *appLocation; @property (nonatomic, copy, nonnull) CDVConfigParser *cordovaConfiguration; diff --git a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m index 1ad0cf0895..66a7d93bed 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m +++ b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m @@ -38,7 +38,7 @@ - (void)_setDefaultsWithAppLocation:(NSURL*)location { _enableLogging = YES; _enableScrolling = YES; _allowLinkPreviews = YES; - _assignUserNotificationCenterDelegate = YES; + _handleApplicationNotifications = YES; _contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; _appLocation = location; _cordovaConfiguration = [[CDVConfigParser alloc] init]; diff --git a/ios/Capacitor/Capacitor/CapacitorBridge.swift b/ios/Capacitor/Capacitor/CapacitorBridge.swift index 3ccd69e60b..b926913260 100644 --- a/ios/Capacitor/Capacitor/CapacitorBridge.swift +++ b/ios/Capacitor/Capacitor/CapacitorBridge.swift @@ -16,7 +16,7 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { return bridgeDelegate?.bridgedWebView } - public var userNotificationDelegate: UserNotificationCenterDelegate + public var notificationRouter: NotificationRouter public var isSimEnvironment: Bool { #if targetEnvironment(simulator) @@ -174,8 +174,8 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol { self.messageHandlerWrapper = messageHandlerWrapper self.config = configuration self.cordovaParser = cordovaConfiguration - self.userNotificationDelegate = UserNotificationCenterDelegate() - self.userNotificationDelegate.handleNotifications = configuration.assignUserNotificationCenterDelegate + self.notificationRouter = NotificationRouter() + self.notificationRouter.handleApplicationNotifications = configuration.handleApplicationNotifications super.init() diff --git a/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift b/ios/Capacitor/Capacitor/NotificationRouter.swift similarity index 93% rename from ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift rename to ios/Capacitor/Capacitor/NotificationRouter.swift index 627fda768a..99fcbb2550 100644 --- a/ios/Capacitor/Capacitor/UserNotificationCenterDelegate.swift +++ b/ios/Capacitor/Capacitor/NotificationRouter.swift @@ -1,7 +1,7 @@ import Foundation -@objc(CAPUNUserNotificationCenterDelegate) public class UserNotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate { - var handleNotifications: Bool { +@objc(CAPNotificationRouter) public class NotificationRouter: NSObject, UNUserNotificationCenterDelegate { + var handleApplicationNotifications: Bool { get { return UNUserNotificationCenter.current().delegate === self }