Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ fastlane/test_output

iOSInjectionProject/
Env.swift
.vscode/settings.json
13 changes: 10 additions & 3 deletions Apps/APN-UIKit/APN UIKit/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import CioMessagingPushAPN
import UIKit

@main
class AppDelegateWithCioIntegration: CioAppDelegateWrapper<AppDelegate> {}

class AppDelegate: UIResponder, UIApplicationDelegate {
var storage = DIGraphShared.shared.storage
var deepLinkHandler = DIGraphShared.shared.deepLinksHandlerUtil
Expand All @@ -28,6 +26,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

// Forward the APN device token to Customer.io SDK.
// Required: iOS delivers tokens only via UIApplicationDelegate — there is no SwiftUI or async API alternative.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
MessagingPushAPN.shared.registerDeviceToken(apnDeviceToken: deviceToken)
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
MessagingPushAPN.shared.deleteDeviceToken()
}

func initializeCioAndInAppListeners() {
// Set default setting if those don't exist
DIGraphShared.shared.settingsService.setDefaultSettings()
Expand Down Expand Up @@ -116,7 +124,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// // Function called when a push notification is clicked or swiped away.
// func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// // Track custom event with Customer.io.
// // NOT required for basic PN tap tracking - that is done automatically with `CioAppDelegateWrapper`.
// CustomerIO.shared.track(
// name: "custom push-clicked event",
// properties: ["push": response.notification.request.content.userInfo]
Expand Down
9 changes: 1 addition & 8 deletions Apps/CocoaPods-FCM/src/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import SwiftUI

@main
struct MainApp: App {
// Default option, without CIO integration
// @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

// Use this option if you don't have a need to extend `CioAppDelegateWrapper`
@UIApplicationDelegateAdaptor(CioAppDelegateWrapper<AppDelegate>.self) private var appDelegate

// Use this option if you need to extend `CioAppDelegateWrapper`: class AppDelegateWithCioIntegration: CioAppDelegateWrapper<AppDelegate> {}
// @UIApplicationDelegateAdaptor(AppDelegateWithCioIntegration.self) private var appDelegate
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

@StateObject var userManager: UserManager = .init()

Expand Down
60 changes: 39 additions & 21 deletions Apps/CocoaPods-FCM/src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ class AppDelegate: NSObject, UIApplicationDelegate {
Next line of code is used for testing how Firebase behaves when another object is set as the delegate for `UNUserNotificationCenter`.
This is not necessary for the Customer.io SDK to work.
*/
// let anotherPushEventHandler = AnotherPushEventHandler()
// let anotherPushEventHandler = AnotherPushEventHandler()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
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.

Expand All @@ -38,9 +41,12 @@ class AppDelegate: NSObject, UIApplicationDelegate {
.deepLinkCallback { (url: URL) in
// You can call any method to process this furhter,
// or redirect it to `application(_:continue:restorationHandler:)` for consistency, if you use deep-linking in Firebase
let openLinkInHostAppActivity = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb)
let openLinkInHostAppActivity = NSUserActivity(
activityType: NSUserActivityTypeBrowsingWeb)
openLinkInHostAppActivity.webpageURL = url
return self.application(UIApplication.shared, continue: openLinkInHostAppActivity, restorationHandler: { _ in })
return self.application(
UIApplication.shared, continue: openLinkInHostAppActivity,
restorationHandler: { _ in })
}
let logLevel = appSetSettings?.debugSdkMode
if logLevel == nil || logLevel == true {
Expand All @@ -57,7 +63,9 @@ class AppDelegate: NSObject, UIApplicationDelegate {

// Initialize messaging features after initializing Customer.io SDK
MessagingInApp
.initialize(withConfig: MessagingInAppConfigBuilder(siteId: siteId, region: .US).build())
.initialize(
withConfig: MessagingInAppConfigBuilder(siteId: siteId, region: .US).build()
)
.setEventListener(self)
MessagingPushFCM.initialize(
withConfig: MessagingPushConfigBuilder()
Expand All @@ -71,22 +79,23 @@ class AppDelegate: NSObject, UIApplicationDelegate {
Next line of code is used for testing how Firebase behaves when another object is set as the delegate for `UNUserNotificationCenter`.
This is not necessary for the Customer.io SDK to work.
*/
// UNUserNotificationCenter.current().delegate = anotherPushEventHandler
// 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.
Push notifications sent by Customer.io will be handled by the Customer.io SDK automatically, unless you disabled that feature.
Therefore, this line of code is not required if you only want to handle push notifications sent by Customer.io.
*/
// UNUserNotificationCenter.current().delegate = self
// UNUserNotificationCenter.current().delegate = self

return true
}

// IMPORTANT: If FCM is used with enabled swizzling (default state) it will not call this method in SwiftUI based apps.
// Use `deepLinkCallback` on SDKConfigBuilder, as that works in all scenarios.
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([any UIUserActivityRestoring]?) -> Void) -> Bool {
func application(
_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: @escaping ([any UIUserActivityRestoring]?) -> Void
) -> Bool {
guard let universalLinkUrl = userActivity.webpageURL else {
return false
}
Expand All @@ -108,7 +117,6 @@ class AppDelegate: NSObject, UIApplicationDelegate {
// // Function called when a push notification is clicked or swiped away.
// func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// // Track custom event with Customer.io.
// // NOT required for basic PN tap tracking - that is done automatically with `CioAppDelegateWrapper`.
// CustomerIO.shared.track(
// name: "custom push-clicked event",
// properties: ["push": response.notification.request.content.userInfo]
Expand All @@ -127,30 +135,40 @@ extension AppDelegate: InAppEventListener {
nonisolated func messageShown(message: InAppMessage) {
CustomerIO.shared.track(
name: "inapp shown",
properties: ["delivery-id": message.deliveryId ?? "(none)", "message-id": message.messageId]
properties: [
"delivery-id": message.deliveryId ?? "(none)", "message-id": message.messageId,
]
)
}

nonisolated func messageDismissed(message: InAppMessage) {
CustomerIO.shared.track(
name: "inapp dismissed",
properties: ["delivery-id": message.deliveryId ?? "(none)", "message-id": message.messageId]
properties: [
"delivery-id": message.deliveryId ?? "(none)", "message-id": message.messageId,
]
)
}

nonisolated func errorWithMessage(message: InAppMessage) {
CustomerIO.shared.track(
name: "inapp error",
properties: ["delivery-id": message.deliveryId ?? "(none)", "message-id": message.messageId]
properties: [
"delivery-id": message.deliveryId ?? "(none)", "message-id": message.messageId,
]
)
}

nonisolated func messageActionTaken(message: InAppMessage, actionValue: String, actionName: String) {
CustomerIO.shared.track(name: "inapp action", properties: [
"delivery-id": message.deliveryId ?? "(none)",
"message-id": message.messageId,
"action-value": actionValue,
"action-name": actionName
])
nonisolated func messageActionTaken(
message: InAppMessage, actionValue: String, actionName: String
) {
CustomerIO.shared.track(
name: "inapp action",
properties: [
"delivery-id": message.deliveryId ?? "(none)",
"message-id": message.messageId,
"action-value": actionValue,
"action-name": actionName,
])
}
}
4 changes: 0 additions & 4 deletions Apps/CocoaPods-FCM/test cocoapods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,10 @@
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-test cocoapods/Pods-test cocoapods-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-test cocoapods/Pods-test cocoapods-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-test cocoapods/Pods-test cocoapods-frameworks.sh\"\n";
Expand Down
Loading
Loading