diff --git a/Apps/CocoaPods-FCM/src/AnotherPushEventHandler.swift b/Apps/CocoaPods-FCM/src/AnotherPushEventHandler.swift new file mode 100644 index 000000000..9b73df556 --- /dev/null +++ b/Apps/CocoaPods-FCM/src/AnotherPushEventHandler.swift @@ -0,0 +1,29 @@ +import CioDataPipelines +import Foundation +import UIKit + +class AnotherPushEventHandler: NSObject, UNUserNotificationCenterDelegate { + func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { + CustomerIO.shared.track( + name: "push clicked", + properties: [ + "push": response.notification.request.content.userInfo, + "handler": "3rdPartyPushEventHandler" + ] + ) + + completionHandler() + } + + func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { + CustomerIO.shared.track( + name: "push should show app in foreground", + properties: [ + "push": notification.request.content.userInfo, + "handler": "3rdPartyPushEventHandler" + ] + ) + + completionHandler([.banner, .badge, .sound]) + } +} diff --git a/Apps/CocoaPods-FCM/src/AppDelegate.swift b/Apps/CocoaPods-FCM/src/AppDelegate.swift index 02228db1a..55707450f 100644 --- a/Apps/CocoaPods-FCM/src/AppDelegate.swift +++ b/Apps/CocoaPods-FCM/src/AppDelegate.swift @@ -8,6 +8,8 @@ import SampleAppsCommon import UIKit class AppDelegate: NSObject, UIApplicationDelegate { + let anotherPushEventHandler = AnotherPushEventHandler() + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { // Follow setup guide for setting up FCM push: https://firebase.google.com/docs/cloud-messaging/ios/client // The FCM SDK provides a device token to the app that you then send to the Customer.io SDK. @@ -50,6 +52,15 @@ class AppDelegate: NSObject, UIApplicationDelegate { // Manually get FCM device token. Then, we will forward to the Customer.io SDK. Messaging.messaging().delegate = self + /* + Next line of code for internal testing purposes only. + + When the host app receives a push notification event such as a push being clicked, the Customer.io SDK forwards these events to all `UNUserNotificationCenterDelegate` instances (including 3rd party SDKs and the host iOS app). + + In order to test that the SDK is able to handle 2+ other push event handlers installed in the app, we install a push event handler class and install the AppDelegate. We expect that when a push event happens in the app, all of the push event handlers are called. + */ + UNUserNotificationCenter.current().delegate = anotherPushEventHandler + /** Registers the `AppDelegate` class to handle when a push notification gets clicked. This line of code is optional and only required if you have custom code that needs to run when a push notification gets clicked on. diff --git a/Apps/CocoaPods-FCM/test cocoapods.xcodeproj/project.pbxproj b/Apps/CocoaPods-FCM/test cocoapods.xcodeproj/project.pbxproj index 54ac48a2c..740d28fa0 100644 --- a/Apps/CocoaPods-FCM/test cocoapods.xcodeproj/project.pbxproj +++ b/Apps/CocoaPods-FCM/test cocoapods.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ F7714AAB2A5C8C1F00C5C952 /* Toast.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7714AAA2A5C8C1F00C5C952 /* Toast.swift */; }; F7714AAD2A5C8F6400C5C952 /* SwiftUITimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7714AAC2A5C8F6400C5C952 /* SwiftUITimer.swift */; }; F78793A6291D5D7B00115DB8 /* CioMessagingPushFCM.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F78793A5291D5D7B00115DB8 /* CioMessagingPushFCM.framework */; }; + F78B1ED62C2B399400D0C80A /* AnotherPushEventHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78B1ED52C2B399400D0C80A /* AnotherPushEventHandler.swift */; }; F78E3D772A05588E00641391 /* ColorExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78E3D762A05588E00641391 /* ColorExtensions.swift */; }; F78E3D792A058B5000641391 /* SettingsButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78E3D782A058B5000641391 /* SettingsButton.swift */; }; F7BAFCBA2919586400DFAC6E /* CioMessagingPushFCM.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7BAFCB92919586400DFAC6E /* CioMessagingPushFCM.framework */; }; @@ -102,6 +103,7 @@ F7714AAC2A5C8F6400C5C952 /* SwiftUITimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUITimer.swift; sourceTree = ""; }; F78793A5291D5D7B00115DB8 /* CioMessagingPushFCM.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = CioMessagingPushFCM.framework; sourceTree = BUILT_PRODUCTS_DIR; }; F78793A9291D5D8100115DB8 /* CioTracking.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = CioTracking.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + F78B1ED52C2B399400D0C80A /* AnotherPushEventHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnotherPushEventHandler.swift; sourceTree = ""; }; F78E3D762A05588E00641391 /* ColorExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorExtensions.swift; sourceTree = ""; }; F78E3D782A058B5000641391 /* SettingsButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsButton.swift; sourceTree = ""; }; F7BAFCB92919586400DFAC6E /* CioMessagingPushFCM.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = CioMessagingPushFCM.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -261,6 +263,7 @@ F731346C2919570700CD43D9 /* test_cocoapods.entitlements */, F73134692919570700CD43D9 /* Preview Content */, F7BAFCC029195AB700DFAC6E /* AppDelegate.swift */, + F78B1ED52C2B399400D0C80A /* AnotherPushEventHandler.swift */, ); path = src; sourceTree = ""; @@ -469,6 +472,7 @@ F73134642919570600CD43D9 /* App.swift in Sources */, F759C74D2A3CB9D3000DD9E8 /* LabeledTextField.swift in Sources */, F759C74B2A3CB8A9000DD9E8 /* CustomAttributeView.swift in Sources */, + F78B1ED62C2B399400D0C80A /* AnotherPushEventHandler.swift in Sources */, F7029EC329F2B12900411BCC /* ViewExtensions.swift in Sources */, F78E3D792A058B5000641391 /* SettingsButton.swift in Sources */, F7029ECC29F2C0C300411BCC /* LoginView.swift in Sources */,