From c166257d140efff72bb6a910e2c6c425f2012d74 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Mon, 11 Dec 2023 11:36:19 -0600 Subject: [PATCH 1/8] add react-native-notifications lib to apn sample app --- Apps/APN/App.js | 21 +++++++++ Apps/APN/ios/AppDelegate.mm | 9 ++++ Apps/APN/ios/Podfile.lock | 76 +++++++++++++++++-------------- Apps/APN/package.json | 1 + Apps/APN/src/screens/Dashboard.js | 13 ++++++ 5 files changed, 85 insertions(+), 35 deletions(-) diff --git a/Apps/APN/App.js b/Apps/APN/App.js index 9c9fa6a7..a523f34f 100644 --- a/Apps/APN/App.js +++ b/Apps/APN/App.js @@ -12,6 +12,8 @@ import StorageService from './src/services/StorageService'; import { CustomerIoSdkContext } from './src/state/customerIoSdkState'; import { UserStateContext } from './src/state/userState'; import { GestureHandlerRootView } from 'react-native-gesture-handler'; +import {Notifications} from 'react-native-notifications'; +import { CustomerIO } from 'customerio-reactnative'; export default function App() { const [loading, setLoading] = useState(true); @@ -43,6 +45,25 @@ export default function App() { updateUserState, ]); + // Setup react-native-notifications + useEffect(() => { + Notifications.registerRemoteNotifications(); + + Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion) => { + console.log(`Non-Customer.io notification received in foreground: ${notification.title} : ${notification.body}`); + + completion({alert: true, sound: true, badge: true}); + }); + + Notifications.events().registerNotificationOpened((notification: Notification, completion) => { + console.log(`Non-Customer.io notification opened: ${notification.payload}`); + + CustomerIO.track("push clicked", {"push": notification.payload}) + + completion(); + }); + }); + const updateCustomerIoSdkState = useCallback( (config) => { setCustomerIoSdk({ diff --git a/Apps/APN/ios/AppDelegate.mm b/Apps/APN/ios/AppDelegate.mm index f654d00b..606382f9 100644 --- a/Apps/APN/ios/AppDelegate.mm +++ b/Apps/APN/ios/AppDelegate.mm @@ -8,6 +8,7 @@ #import #import #import +#import "RNNotifications.h" #if RCT_NEW_ARCH_ENABLED #import @@ -78,6 +79,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [pnHandlerObj setupCustomerIOClickHandling:self]; + [RNNotifications startMonitorNotifications]; + return YES; } @@ -156,6 +159,8 @@ - (void)application:(UIApplication *)application didRegisterForRemoteNotificatio { // Register device to receive push notifications with device token [pnHandlerObj application:application deviceToken:deviceToken]; + + [RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. You must call the completion handler after handling the remote notification. @@ -163,12 +168,16 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; + + [RNNotifications didReceiveBackgroundNotification:userInfo withCompletionHandler:completionHandler]; } // Required for the registrationError event. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [pnHandlerObj application:application error:error]; + + [RNNotifications didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for localNotification event diff --git a/Apps/APN/ios/Podfile.lock b/Apps/APN/ios/Podfile.lock index ef801bda..b52b038e 100644 --- a/Apps/APN/ios/Podfile.lock +++ b/Apps/APN/ios/Podfile.lock @@ -2,38 +2,38 @@ PODS: - boost (1.76.0) - customerio-reactnative (3.2.0): - customerio-reactnative/nopush (= 3.2.0) - - CustomerIO/MessagingInApp (= 2.8.4) - - CustomerIO/Tracking (= 2.8.4) + - CustomerIO/MessagingInApp (= 2.8.5) + - CustomerIO/Tracking (= 2.8.5) - React-Core - customerio-reactnative-richpush/apn (3.2.0): - - CustomerIO/MessagingPushAPN (= 2.8.4) + - CustomerIO/MessagingPushAPN (= 2.8.5) - customerio-reactnative/apn (3.2.0): - - CustomerIO/MessagingInApp (= 2.8.4) - - CustomerIO/MessagingPushAPN (= 2.8.4) - - CustomerIO/Tracking (= 2.8.4) + - CustomerIO/MessagingInApp (= 2.8.5) + - CustomerIO/MessagingPushAPN (= 2.8.5) + - CustomerIO/Tracking (= 2.8.5) - React-Core - customerio-reactnative/nopush (3.2.0): - - CustomerIO/MessagingInApp (= 2.8.4) - - CustomerIO/MessagingPush (= 2.8.4) - - CustomerIO/Tracking (= 2.8.4) + - CustomerIO/MessagingInApp (= 2.8.5) + - CustomerIO/MessagingPush (= 2.8.5) + - CustomerIO/Tracking (= 2.8.5) - React-Core - - CustomerIO/MessagingInApp (2.8.4): - - CustomerIOMessagingInApp (= 2.8.4) - - CustomerIO/MessagingPush (2.8.4): - - CustomerIOMessagingPush (= 2.8.4) - - CustomerIO/MessagingPushAPN (2.8.4): - - CustomerIOMessagingPushAPN (= 2.8.4) - - CustomerIO/Tracking (2.8.4): - - CustomerIOTracking (= 2.8.4) - - CustomerIOCommon (2.8.4) - - CustomerIOMessagingInApp (2.8.4): - - CustomerIOTracking (= 2.8.4) - - CustomerIOMessagingPush (2.8.4): - - CustomerIOTracking (= 2.8.4) - - CustomerIOMessagingPushAPN (2.8.4): - - CustomerIOMessagingPush (= 2.8.4) - - CustomerIOTracking (2.8.4): - - CustomerIOCommon (= 2.8.4) + - CustomerIO/MessagingInApp (2.8.5): + - CustomerIOMessagingInApp (= 2.8.5) + - CustomerIO/MessagingPush (2.8.5): + - CustomerIOMessagingPush (= 2.8.5) + - CustomerIO/MessagingPushAPN (2.8.5): + - CustomerIOMessagingPushAPN (= 2.8.5) + - CustomerIO/Tracking (2.8.5): + - CustomerIOTracking (= 2.8.5) + - CustomerIOCommon (2.8.5) + - CustomerIOMessagingInApp (2.8.5): + - CustomerIOTracking (= 2.8.5) + - CustomerIOMessagingPush (2.8.5): + - CustomerIOTracking (= 2.8.5) + - CustomerIOMessagingPushAPN (2.8.5): + - CustomerIOMessagingPush (= 2.8.5) + - CustomerIOTracking (2.8.5): + - CustomerIOCommon (= 2.8.5) - DoubleConversion (1.1.6) - FBLazyVector (0.72.4) - FBReactNativeSpec (0.72.4): @@ -349,6 +349,8 @@ PODS: - React-jsinspector (0.72.4) - React-logger (0.72.4): - glog + - react-native-notifications (5.1.0): + - React-Core - react-native-safe-area-context (4.7.1): - React-Core - React-NativeModulesApple (0.72.4): @@ -532,6 +534,7 @@ DEPENDENCIES: - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) - React-logger (from `../node_modules/react-native/ReactCommon/logger`) + - react-native-notifications (from `../node_modules/react-native-notifications`) - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) - React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`) - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) @@ -620,6 +623,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/jsinspector" React-logger: :path: "../node_modules/react-native/ReactCommon/logger" + react-native-notifications: + :path: "../node_modules/react-native-notifications" react-native-safe-area-context: :path: "../node_modules/react-native-safe-area-context" React-NativeModulesApple: @@ -677,14 +682,14 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: boost: 57d2868c099736d80fcd648bf211b4431e51a558 - CustomerIO: 4a04f63c9951bced3f2160397e811451cba0de36 - customerio-reactnative: 57a15506e537c89802847b819442ab4426de68eb - customerio-reactnative-richpush: 3866204a12a94ce8eaa6630ab39f069dea970b36 - CustomerIOCommon: 65752b4280cd24edf8091eba59cae04347999fe1 - CustomerIOMessagingInApp: ce4944ec4c9d1dd0d30ea7a0c6aee7137609d7e3 - CustomerIOMessagingPush: 6a21e2bd5bb4a6b483671e7703dc011a4deb8178 - CustomerIOMessagingPushAPN: 93e371ee9e5208497320bec6325e715db0a8b3ab - CustomerIOTracking: 5eab210defdf8950e0708713f7d95b35b779e056 + CustomerIO: c77cdb5e9746a0fffa0c1dc4fcd9d099909a4959 + customerio-reactnative: f708dbb24c377d3497652c4dedd438e83c67f832 + customerio-reactnative-richpush: a27490b92747ccf45b70e62a63747aa696d420b6 + CustomerIOCommon: 57d842ef82f1acee1c2108055fc7061bfdd71fc0 + CustomerIOMessagingInApp: 52a7b20a8bb24706d0035835cf7a00381d9771bd + CustomerIOMessagingPush: 7715a657c64a3a7bff402fab94474edf7edd24eb + CustomerIOMessagingPushAPN: 82b7ed41eecfadb6919f447e5c9b1546c3a68ed5 + CustomerIOTracking: 67e62dc3643ee1cf1f719f85290351549a18e56e DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 FBLazyVector: 5d4a3b7f411219a45a6d952f77d2c0a6c9989da5 FBReactNativeSpec: 3fc2d478e1c4b08276f9dd9128f80ec6d5d85c1f @@ -707,6 +712,7 @@ SPEC CHECKSUMS: React-jsiexecutor: c7f826e40fa9cab5d37cab6130b1af237332b594 React-jsinspector: aaed4cf551c4a1c98092436518c2d267b13a673f React-logger: da1ebe05ae06eb6db4b162202faeafac4b435e77 + react-native-notifications: 4601a5a8db4ced6ae7cfc43b44d35fe437ac50c4 react-native-safe-area-context: 9697629f7b2cda43cf52169bb7e0767d330648c2 React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f React-perflogger: 496a1a3dc6737f964107cb3ddae7f9e265ddda58 @@ -738,4 +744,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: dd15e298a538ff617275f2a8acfe9f2e3d78fbbf -COCOAPODS: 1.12.1 +COCOAPODS: 1.14.3 diff --git a/Apps/APN/package.json b/Apps/APN/package.json index 90e809de..c7956810 100644 --- a/Apps/APN/package.json +++ b/Apps/APN/package.json @@ -29,6 +29,7 @@ "react-native": "0.72.4", "react-native-device-info": "^10.7.0", "react-native-gesture-handler": "^2.12.1", + "react-native-notifications": "^5.1.0", "react-native-reanimated": "3.2.0", "react-native-safe-area-context": "^4.2.5", "react-native-screens": "~3.24.0", diff --git a/Apps/APN/src/screens/Dashboard.js b/Apps/APN/src/screens/Dashboard.js index c73b521e..1793dfd0 100644 --- a/Apps/APN/src/screens/Dashboard.js +++ b/Apps/APN/src/screens/Dashboard.js @@ -23,6 +23,7 @@ import { useUserStateContext } from '../state/userState'; import { generateRandomNumber } from '../utils/helpers'; import { navigateToScreen } from '../utils/navigation'; import Prompts from '../utils/prompts'; +import {Notifications} from 'react-native-notifications'; const pushPermissionAlertTitle = 'Push Permission'; @@ -138,6 +139,13 @@ const Dashboard = ({ navigation }) => { handlePushPermissionCheck(); break; + case ActionItem.SHOW_LOCAL_PUSH: + let localNotification = Notifications.postLocalNotification({ + body: "Try clicking on me. The SDK that sent this should also be able to handle it.", + title: "Local push not sent by Customer.io" + }); + break; + case ActionItem.SIGN_OUT: onUserStateChanged(null); break; @@ -218,6 +226,11 @@ const ActionItem = { contentDesc: 'Show Push Prompt Button', targetScreen: null, }, + SHOW_LOCAL_PUSH: { + text: 'Show Local Push', + contentDesc: 'Show Local Push Button', + targetScreen: null, + } SIGN_OUT: { text: 'Log Out', contentDesc: 'Log Out Button', From 0881ad630e9e5a0c8dfbebb77bbd57aa36107bbb Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Mon, 11 Dec 2023 14:17:47 -0600 Subject: [PATCH 2/8] got cio sdk working alongside 3rd party sdk --- Apps/APN/App.js | 22 +----------------- Apps/APN/ios/AppDelegate.mm | 18 +-------------- .../ios/MyAppPushNotificationsHandler.swift | 21 +++-------------- Apps/APN/ios/Podfile | 4 ++-- Apps/APN/src/screens/Dashboard.js | 23 ++++++++++++++++++- 5 files changed, 29 insertions(+), 59 deletions(-) diff --git a/Apps/APN/App.js b/Apps/APN/App.js index a523f34f..77c72608 100644 --- a/Apps/APN/App.js +++ b/Apps/APN/App.js @@ -12,7 +12,6 @@ import StorageService from './src/services/StorageService'; import { CustomerIoSdkContext } from './src/state/customerIoSdkState'; import { UserStateContext } from './src/state/userState'; import { GestureHandlerRootView } from 'react-native-gesture-handler'; -import {Notifications} from 'react-native-notifications'; import { CustomerIO } from 'customerio-reactnative'; export default function App() { @@ -32,7 +31,7 @@ export default function App() { }; prepare(); - const inAppEventListener = registerInAppEventListener(); + const inAppEventListener = registerInAppEventListener(); // Remove listeners once unmounted return () => { @@ -45,25 +44,6 @@ export default function App() { updateUserState, ]); - // Setup react-native-notifications - useEffect(() => { - Notifications.registerRemoteNotifications(); - - Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion) => { - console.log(`Non-Customer.io notification received in foreground: ${notification.title} : ${notification.body}`); - - completion({alert: true, sound: true, badge: true}); - }); - - Notifications.events().registerNotificationOpened((notification: Notification, completion) => { - console.log(`Non-Customer.io notification opened: ${notification.payload}`); - - CustomerIO.track("push clicked", {"push": notification.payload}) - - completion(); - }); - }); - const updateCustomerIoSdkState = useCallback( (config) => { setCustomerIoSdk({ diff --git a/Apps/APN/ios/AppDelegate.mm b/Apps/APN/ios/AppDelegate.mm index 606382f9..e21459d2 100644 --- a/Apps/APN/ios/AppDelegate.mm +++ b/Apps/APN/ios/AppDelegate.mm @@ -77,7 +77,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; - [pnHandlerObj setupCustomerIOClickHandling:self]; + [pnHandlerObj setupCustomerIOClickHandling]; [RNNotifications startMonitorNotifications]; @@ -180,22 +180,6 @@ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotif [RNNotifications didFailToRegisterForRemoteNotificationsWithError:error]; } -// Required for localNotification event -- (void)userNotificationCenter:(UNUserNotificationCenter *)center -didReceiveNotificationResponse:(UNNotificationResponse *)response - withCompletionHandler:(void (^)(void))completionHandler -{ - [pnHandlerObj userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; - - [RNCPushNotificationIOS didReceiveNotificationResponse:response]; -} - -//Called when a notification is delivered to a foreground app. --(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler -{ - completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner | UNNotificationPresentationOptionBadge); -} - // Deep linking - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url diff --git a/Apps/APN/ios/MyAppPushNotificationsHandler.swift b/Apps/APN/ios/MyAppPushNotificationsHandler.swift index d61d56d9..abcc2df3 100644 --- a/Apps/APN/ios/MyAppPushNotificationsHandler.swift +++ b/Apps/APN/ios/MyAppPushNotificationsHandler.swift @@ -1,6 +1,5 @@ import Foundation import CioMessagingPushAPN -import UserNotifications import CioTracking @objc @@ -8,8 +7,8 @@ public class MyAppPushNotificationsHandler : NSObject { public override init() {} - @objc(setupCustomerIOClickHandling:) - public func setupCustomerIOClickHandling(withNotificationDelegate notificationDelegate: UNUserNotificationCenterDelegate) { + @objc(setupCustomerIOClickHandling) + public func setupCustomerIOClickHandling() { // This line of code is required in order for the Customer.io SDK to handle push notification click events. // We are working on removing this requirement in a future release. // Remember to modify the siteId and apiKey with your own values. @@ -17,9 +16,7 @@ public class MyAppPushNotificationsHandler : NSObject { config.autoTrackDeviceAttributes = true config.logLevel = .debug } - - let center = UNUserNotificationCenter.current() - center.delegate = notificationDelegate + MessagingPushAPN.initialize(configOptions: nil) } @objc(application:deviceToken:) @@ -31,16 +28,4 @@ public class MyAppPushNotificationsHandler : NSObject { public func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { MessagingPush.shared.application(application, didFailToRegisterForRemoteNotificationsWithError: error) } - - @objc(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:) - public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { - let handled = MessagingPush.shared.userNotificationCenter(center, didReceive: response, - withCompletionHandler: completionHandler) - - // If the Customer.io SDK does not handle the push, it's up to you to handle it and call the - // completion handler. If the SDK did handle it, it called the completion handler for you. - if !handled { - completionHandler() - } - } } diff --git a/Apps/APN/ios/Podfile b/Apps/APN/ios/Podfile index 8c765940..79834ff4 100644 --- a/Apps/APN/ios/Podfile +++ b/Apps/APN/ios/Podfile @@ -18,7 +18,7 @@ target 'SampleApp' do flags = get_default_flags() pod 'customerio-reactnative/apn', :path => '../node_modules/customerio-reactnative' - # install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: false, push_service: "apn") + install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: false, push_service: "apn") # install_non_production_ios_sdk_git_branch(branch_name: 'main', is_app_extension: false, push_service: "apn") use_react_native!( @@ -49,6 +49,6 @@ end target 'NotificationServiceExtension' do pod 'customerio-reactnative-richpush/apn', :path => '../node_modules/customerio-reactnative' - # install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: true, push_service: "apn") + install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: true, push_service: "apn") # install_non_production_ios_sdk_git_branch(branch_name: 'main', is_app_extension: true, push_service: "apn") end diff --git a/Apps/APN/src/screens/Dashboard.js b/Apps/APN/src/screens/Dashboard.js index 1793dfd0..ab005bbb 100644 --- a/Apps/APN/src/screens/Dashboard.js +++ b/Apps/APN/src/screens/Dashboard.js @@ -24,6 +24,7 @@ import { generateRandomNumber } from '../utils/helpers'; import { navigateToScreen } from '../utils/navigation'; import Prompts from '../utils/prompts'; import {Notifications} from 'react-native-notifications'; +import { CustomerIO } from 'customerio-reactnative'; const pushPermissionAlertTitle = 'Push Permission'; @@ -140,6 +141,7 @@ const Dashboard = ({ navigation }) => { break; case ActionItem.SHOW_LOCAL_PUSH: + console.log('Sending local push'); let localNotification = Notifications.postLocalNotification({ body: "Try clicking on me. The SDK that sent this should also be able to handle it.", title: "Local push not sent by Customer.io" @@ -158,6 +160,25 @@ const Dashboard = ({ navigation }) => { } }; + // Setup react-native-notifications + Notifications.registerRemoteNotifications(); + + Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion) => { + console.log(`Non-Customer.io notification received in foreground: ${notification.title} : ${notification.body}`); + + completion({alert: true, sound: true, badge: true}); + }); + + Notifications.events().registerNotificationOpened((notification: Notification, completion) => { + console.log(`Non-Customer.io notification opened: ${notification.payload}`); + + CustomerIO.track("push clicked", {"push": notification.payload}) + + completion(); + }); + + console.log('Setup react-native-notifications'); + return ( @@ -230,7 +251,7 @@ const ActionItem = { text: 'Show Local Push', contentDesc: 'Show Local Push Button', targetScreen: null, - } + }, SIGN_OUT: { text: 'Log Out', contentDesc: 'Log Out Button', From d6e42ce49af47d96cf5a01bd09744a1075a8a023 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Mon, 11 Dec 2023 14:20:27 -0600 Subject: [PATCH 3/8] Discard changes to Apps/APN/App.js --- Apps/APN/App.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Apps/APN/App.js b/Apps/APN/App.js index 77c72608..9c9fa6a7 100644 --- a/Apps/APN/App.js +++ b/Apps/APN/App.js @@ -12,7 +12,6 @@ import StorageService from './src/services/StorageService'; import { CustomerIoSdkContext } from './src/state/customerIoSdkState'; import { UserStateContext } from './src/state/userState'; import { GestureHandlerRootView } from 'react-native-gesture-handler'; -import { CustomerIO } from 'customerio-reactnative'; export default function App() { const [loading, setLoading] = useState(true); @@ -31,7 +30,7 @@ export default function App() { }; prepare(); - const inAppEventListener = registerInAppEventListener(); + const inAppEventListener = registerInAppEventListener(); // Remove listeners once unmounted return () => { From b77103327fbde937c82e63f86d9c946db4d2c430 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Mon, 11 Dec 2023 14:21:29 -0600 Subject: [PATCH 4/8] Discard changes to Apps/APN/ios/Podfile --- Apps/APN/ios/Podfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Apps/APN/ios/Podfile b/Apps/APN/ios/Podfile index 79834ff4..8c765940 100644 --- a/Apps/APN/ios/Podfile +++ b/Apps/APN/ios/Podfile @@ -18,7 +18,7 @@ target 'SampleApp' do flags = get_default_flags() pod 'customerio-reactnative/apn', :path => '../node_modules/customerio-reactnative' - install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: false, push_service: "apn") + # install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: false, push_service: "apn") # install_non_production_ios_sdk_git_branch(branch_name: 'main', is_app_extension: false, push_service: "apn") use_react_native!( @@ -49,6 +49,6 @@ end target 'NotificationServiceExtension' do pod 'customerio-reactnative-richpush/apn', :path => '../node_modules/customerio-reactnative' - install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: true, push_service: "apn") + # install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: true, push_service: "apn") # install_non_production_ios_sdk_git_branch(branch_name: 'main', is_app_extension: true, push_service: "apn") end From d20539285c90838477dfbdeb8653f576e12124db Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Mon, 11 Dec 2023 14:21:34 -0600 Subject: [PATCH 5/8] Discard changes to Apps/APN/ios/Podfile.lock --- Apps/APN/ios/Podfile.lock | 76 ++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/Apps/APN/ios/Podfile.lock b/Apps/APN/ios/Podfile.lock index b52b038e..ef801bda 100644 --- a/Apps/APN/ios/Podfile.lock +++ b/Apps/APN/ios/Podfile.lock @@ -2,38 +2,38 @@ PODS: - boost (1.76.0) - customerio-reactnative (3.2.0): - customerio-reactnative/nopush (= 3.2.0) - - CustomerIO/MessagingInApp (= 2.8.5) - - CustomerIO/Tracking (= 2.8.5) + - CustomerIO/MessagingInApp (= 2.8.4) + - CustomerIO/Tracking (= 2.8.4) - React-Core - customerio-reactnative-richpush/apn (3.2.0): - - CustomerIO/MessagingPushAPN (= 2.8.5) + - CustomerIO/MessagingPushAPN (= 2.8.4) - customerio-reactnative/apn (3.2.0): - - CustomerIO/MessagingInApp (= 2.8.5) - - CustomerIO/MessagingPushAPN (= 2.8.5) - - CustomerIO/Tracking (= 2.8.5) + - CustomerIO/MessagingInApp (= 2.8.4) + - CustomerIO/MessagingPushAPN (= 2.8.4) + - CustomerIO/Tracking (= 2.8.4) - React-Core - customerio-reactnative/nopush (3.2.0): - - CustomerIO/MessagingInApp (= 2.8.5) - - CustomerIO/MessagingPush (= 2.8.5) - - CustomerIO/Tracking (= 2.8.5) + - CustomerIO/MessagingInApp (= 2.8.4) + - CustomerIO/MessagingPush (= 2.8.4) + - CustomerIO/Tracking (= 2.8.4) - React-Core - - CustomerIO/MessagingInApp (2.8.5): - - CustomerIOMessagingInApp (= 2.8.5) - - CustomerIO/MessagingPush (2.8.5): - - CustomerIOMessagingPush (= 2.8.5) - - CustomerIO/MessagingPushAPN (2.8.5): - - CustomerIOMessagingPushAPN (= 2.8.5) - - CustomerIO/Tracking (2.8.5): - - CustomerIOTracking (= 2.8.5) - - CustomerIOCommon (2.8.5) - - CustomerIOMessagingInApp (2.8.5): - - CustomerIOTracking (= 2.8.5) - - CustomerIOMessagingPush (2.8.5): - - CustomerIOTracking (= 2.8.5) - - CustomerIOMessagingPushAPN (2.8.5): - - CustomerIOMessagingPush (= 2.8.5) - - CustomerIOTracking (2.8.5): - - CustomerIOCommon (= 2.8.5) + - CustomerIO/MessagingInApp (2.8.4): + - CustomerIOMessagingInApp (= 2.8.4) + - CustomerIO/MessagingPush (2.8.4): + - CustomerIOMessagingPush (= 2.8.4) + - CustomerIO/MessagingPushAPN (2.8.4): + - CustomerIOMessagingPushAPN (= 2.8.4) + - CustomerIO/Tracking (2.8.4): + - CustomerIOTracking (= 2.8.4) + - CustomerIOCommon (2.8.4) + - CustomerIOMessagingInApp (2.8.4): + - CustomerIOTracking (= 2.8.4) + - CustomerIOMessagingPush (2.8.4): + - CustomerIOTracking (= 2.8.4) + - CustomerIOMessagingPushAPN (2.8.4): + - CustomerIOMessagingPush (= 2.8.4) + - CustomerIOTracking (2.8.4): + - CustomerIOCommon (= 2.8.4) - DoubleConversion (1.1.6) - FBLazyVector (0.72.4) - FBReactNativeSpec (0.72.4): @@ -349,8 +349,6 @@ PODS: - React-jsinspector (0.72.4) - React-logger (0.72.4): - glog - - react-native-notifications (5.1.0): - - React-Core - react-native-safe-area-context (4.7.1): - React-Core - React-NativeModulesApple (0.72.4): @@ -534,7 +532,6 @@ DEPENDENCIES: - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) - React-logger (from `../node_modules/react-native/ReactCommon/logger`) - - react-native-notifications (from `../node_modules/react-native-notifications`) - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) - React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`) - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) @@ -623,8 +620,6 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/jsinspector" React-logger: :path: "../node_modules/react-native/ReactCommon/logger" - react-native-notifications: - :path: "../node_modules/react-native-notifications" react-native-safe-area-context: :path: "../node_modules/react-native-safe-area-context" React-NativeModulesApple: @@ -682,14 +677,14 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: boost: 57d2868c099736d80fcd648bf211b4431e51a558 - CustomerIO: c77cdb5e9746a0fffa0c1dc4fcd9d099909a4959 - customerio-reactnative: f708dbb24c377d3497652c4dedd438e83c67f832 - customerio-reactnative-richpush: a27490b92747ccf45b70e62a63747aa696d420b6 - CustomerIOCommon: 57d842ef82f1acee1c2108055fc7061bfdd71fc0 - CustomerIOMessagingInApp: 52a7b20a8bb24706d0035835cf7a00381d9771bd - CustomerIOMessagingPush: 7715a657c64a3a7bff402fab94474edf7edd24eb - CustomerIOMessagingPushAPN: 82b7ed41eecfadb6919f447e5c9b1546c3a68ed5 - CustomerIOTracking: 67e62dc3643ee1cf1f719f85290351549a18e56e + CustomerIO: 4a04f63c9951bced3f2160397e811451cba0de36 + customerio-reactnative: 57a15506e537c89802847b819442ab4426de68eb + customerio-reactnative-richpush: 3866204a12a94ce8eaa6630ab39f069dea970b36 + CustomerIOCommon: 65752b4280cd24edf8091eba59cae04347999fe1 + CustomerIOMessagingInApp: ce4944ec4c9d1dd0d30ea7a0c6aee7137609d7e3 + CustomerIOMessagingPush: 6a21e2bd5bb4a6b483671e7703dc011a4deb8178 + CustomerIOMessagingPushAPN: 93e371ee9e5208497320bec6325e715db0a8b3ab + CustomerIOTracking: 5eab210defdf8950e0708713f7d95b35b779e056 DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 FBLazyVector: 5d4a3b7f411219a45a6d952f77d2c0a6c9989da5 FBReactNativeSpec: 3fc2d478e1c4b08276f9dd9128f80ec6d5d85c1f @@ -712,7 +707,6 @@ SPEC CHECKSUMS: React-jsiexecutor: c7f826e40fa9cab5d37cab6130b1af237332b594 React-jsinspector: aaed4cf551c4a1c98092436518c2d267b13a673f React-logger: da1ebe05ae06eb6db4b162202faeafac4b435e77 - react-native-notifications: 4601a5a8db4ced6ae7cfc43b44d35fe437ac50c4 react-native-safe-area-context: 9697629f7b2cda43cf52169bb7e0767d330648c2 React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f React-perflogger: 496a1a3dc6737f964107cb3ddae7f9e265ddda58 @@ -744,4 +738,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: dd15e298a538ff617275f2a8acfe9f2e3d78fbbf -COCOAPODS: 1.14.3 +COCOAPODS: 1.12.1 From 80a709455399929e5fd95077b141e7b052515333 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Mon, 11 Dec 2023 14:26:14 -0600 Subject: [PATCH 6/8] add comments --- Apps/APN/App.js | 2 +- Apps/APN/src/screens/Dashboard.js | 52 ++++++++++++++++++------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Apps/APN/App.js b/Apps/APN/App.js index 77c72608..889ab7b7 100644 --- a/Apps/APN/App.js +++ b/Apps/APN/App.js @@ -31,7 +31,7 @@ export default function App() { }; prepare(); - const inAppEventListener = registerInAppEventListener(); + const inAppEventListener = registerInAppEventListener(); // Remove listeners once unmounted return () => { diff --git a/Apps/APN/src/screens/Dashboard.js b/Apps/APN/src/screens/Dashboard.js index ab005bbb..15308c24 100644 --- a/Apps/APN/src/screens/Dashboard.js +++ b/Apps/APN/src/screens/Dashboard.js @@ -23,7 +23,7 @@ import { useUserStateContext } from '../state/userState'; import { generateRandomNumber } from '../utils/helpers'; import { navigateToScreen } from '../utils/navigation'; import Prompts from '../utils/prompts'; -import {Notifications} from 'react-native-notifications'; +import { Notifications } from 'react-native-notifications'; import { CustomerIO } from 'customerio-reactnative'; const pushPermissionAlertTitle = 'Push Permission'; @@ -141,12 +141,13 @@ const Dashboard = ({ navigation }) => { break; case ActionItem.SHOW_LOCAL_PUSH: - console.log('Sending local push'); - let localNotification = Notifications.postLocalNotification({ - body: "Try clicking on me. The SDK that sent this should also be able to handle it.", - title: "Local push not sent by Customer.io" + // How we are able to test behavior of pushes sent by other SDKs, not CIO. + // Have 3rd party SDK create a push. We expect the SDK is able to handle this push that it owns. + Notifications.postLocalNotification({ + body: 'Try clicking on me. The SDK that sent this should also be able to handle it.', + title: 'Local push not sent by Customer.io', }); - break; + break; case ActionItem.SIGN_OUT: onUserStateChanged(null); @@ -160,24 +161,31 @@ const Dashboard = ({ navigation }) => { } }; - // Setup react-native-notifications - Notifications.registerRemoteNotifications(); - - Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion) => { - console.log(`Non-Customer.io notification received in foreground: ${notification.title} : ${notification.body}`); - - completion({alert: true, sound: true, badge: true}); - }); - - Notifications.events().registerNotificationOpened((notification: Notification, completion) => { - console.log(`Non-Customer.io notification opened: ${notification.payload}`); - - CustomerIO.track("push clicked", {"push": notification.payload}) + // Setup 3rd party SDK, react-native-notifications + // We install this SDK into sample app to make sure the CIO SDK behaves as expected when there is another SDK installed that handles push notifications. + // + // Important to test that 3rd party SDK is able to decide if a push is shown or not while app is in foreground for non-CIO sent pushes. + Notifications.events().registerNotificationReceivedForeground( + (notification: Notification, completion) => { + console.log( + `Non-Customer.io notification received in foreground: ${notification.title} : ${notification.body}` + ); + + completion({ alert: true, sound: true, badge: true }); + } + ); + // Important to test that 3rd party SDK is able to receive a callback when a push notification is clicked for non-CIO sent pushes. + Notifications.events().registerNotificationOpened( + (notification: Notification, completion) => { + console.log( + `Non-Customer.io notification opened: ${notification.payload}` + ); - completion(); - }); + CustomerIO.track('push clicked', { push: notification.payload }); - console.log('Setup react-native-notifications'); + completion(); + } + ); return ( From 86395203db39b447bae7529f2533f1f07457ae72 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Thu, 4 Jan 2024 11:40:51 -0600 Subject: [PATCH 7/8] added note to push handler --- Apps/APN/ios/MyAppPushNotificationsHandler.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Apps/APN/ios/MyAppPushNotificationsHandler.swift b/Apps/APN/ios/MyAppPushNotificationsHandler.swift index abcc2df3..acd4bd8e 100644 --- a/Apps/APN/ios/MyAppPushNotificationsHandler.swift +++ b/Apps/APN/ios/MyAppPushNotificationsHandler.swift @@ -2,6 +2,13 @@ import Foundation import CioMessagingPushAPN import CioTracking +/** + * This file was created based on the Customer.io React Native SDK documentation for setting up push notifications in your app. + * + * See the documentation to learn how to add this file to your app: + * https://customer.io/docs/sdk/react-native/push-notifications/push/#integrate-push-capabilities-in-your-app + */ + @objc public class MyAppPushNotificationsHandler : NSObject { From 11087d551900a1301f4cfe7d14387b37a7f75d1a Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Mon, 12 Feb 2024 14:11:31 -0600 Subject: [PATCH 8/8] update pod lock file to point to latest native ios prod version --- Apps/APN/ios/Podfile.lock | 86 +++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/Apps/APN/ios/Podfile.lock b/Apps/APN/ios/Podfile.lock index ef801bda..a5becb33 100644 --- a/Apps/APN/ios/Podfile.lock +++ b/Apps/APN/ios/Podfile.lock @@ -1,39 +1,39 @@ PODS: - boost (1.76.0) - - customerio-reactnative (3.2.0): - - customerio-reactnative/nopush (= 3.2.0) - - CustomerIO/MessagingInApp (= 2.8.4) - - CustomerIO/Tracking (= 2.8.4) + - customerio-reactnative (3.4.0): + - customerio-reactnative/nopush (= 3.4.0) + - CustomerIO/MessagingInApp (= 2.11.0) + - CustomerIO/Tracking (= 2.11.0) - React-Core - - customerio-reactnative-richpush/apn (3.2.0): - - CustomerIO/MessagingPushAPN (= 2.8.4) - - customerio-reactnative/apn (3.2.0): - - CustomerIO/MessagingInApp (= 2.8.4) - - CustomerIO/MessagingPushAPN (= 2.8.4) - - CustomerIO/Tracking (= 2.8.4) + - customerio-reactnative-richpush/apn (3.4.0): + - CustomerIO/MessagingPushAPN (= 2.11.0) + - customerio-reactnative/apn (3.4.0): + - CustomerIO/MessagingInApp (= 2.11.0) + - CustomerIO/MessagingPushAPN (= 2.11.0) + - CustomerIO/Tracking (= 2.11.0) - React-Core - - customerio-reactnative/nopush (3.2.0): - - CustomerIO/MessagingInApp (= 2.8.4) - - CustomerIO/MessagingPush (= 2.8.4) - - CustomerIO/Tracking (= 2.8.4) + - customerio-reactnative/nopush (3.4.0): + - CustomerIO/MessagingInApp (= 2.11.0) + - CustomerIO/MessagingPush (= 2.11.0) + - CustomerIO/Tracking (= 2.11.0) - React-Core - - CustomerIO/MessagingInApp (2.8.4): - - CustomerIOMessagingInApp (= 2.8.4) - - CustomerIO/MessagingPush (2.8.4): - - CustomerIOMessagingPush (= 2.8.4) - - CustomerIO/MessagingPushAPN (2.8.4): - - CustomerIOMessagingPushAPN (= 2.8.4) - - CustomerIO/Tracking (2.8.4): - - CustomerIOTracking (= 2.8.4) - - CustomerIOCommon (2.8.4) - - CustomerIOMessagingInApp (2.8.4): - - CustomerIOTracking (= 2.8.4) - - CustomerIOMessagingPush (2.8.4): - - CustomerIOTracking (= 2.8.4) - - CustomerIOMessagingPushAPN (2.8.4): - - CustomerIOMessagingPush (= 2.8.4) - - CustomerIOTracking (2.8.4): - - CustomerIOCommon (= 2.8.4) + - CustomerIO/MessagingInApp (2.11.0): + - CustomerIOMessagingInApp (= 2.11.0) + - CustomerIO/MessagingPush (2.11.0): + - CustomerIOMessagingPush (= 2.11.0) + - CustomerIO/MessagingPushAPN (2.11.0): + - CustomerIOMessagingPushAPN (= 2.11.0) + - CustomerIO/Tracking (2.11.0): + - CustomerIOTracking (= 2.11.0) + - CustomerIOCommon (2.11.0) + - CustomerIOMessagingInApp (2.11.0): + - CustomerIOTracking (= 2.11.0) + - CustomerIOMessagingPush (2.11.0): + - CustomerIOTracking (= 2.11.0) + - CustomerIOMessagingPushAPN (2.11.0): + - CustomerIOMessagingPush (= 2.11.0) + - CustomerIOTracking (2.11.0): + - CustomerIOCommon (= 2.11.0) - DoubleConversion (1.1.6) - FBLazyVector (0.72.4) - FBReactNativeSpec (0.72.4): @@ -349,6 +349,8 @@ PODS: - React-jsinspector (0.72.4) - React-logger (0.72.4): - glog + - react-native-notifications (5.1.0): + - React-Core - react-native-safe-area-context (4.7.1): - React-Core - React-NativeModulesApple (0.72.4): @@ -532,6 +534,7 @@ DEPENDENCIES: - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) - React-logger (from `../node_modules/react-native/ReactCommon/logger`) + - react-native-notifications (from `../node_modules/react-native-notifications`) - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) - React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`) - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) @@ -620,6 +623,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/jsinspector" React-logger: :path: "../node_modules/react-native/ReactCommon/logger" + react-native-notifications: + :path: "../node_modules/react-native-notifications" react-native-safe-area-context: :path: "../node_modules/react-native-safe-area-context" React-NativeModulesApple: @@ -677,14 +682,14 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: boost: 57d2868c099736d80fcd648bf211b4431e51a558 - CustomerIO: 4a04f63c9951bced3f2160397e811451cba0de36 - customerio-reactnative: 57a15506e537c89802847b819442ab4426de68eb - customerio-reactnative-richpush: 3866204a12a94ce8eaa6630ab39f069dea970b36 - CustomerIOCommon: 65752b4280cd24edf8091eba59cae04347999fe1 - CustomerIOMessagingInApp: ce4944ec4c9d1dd0d30ea7a0c6aee7137609d7e3 - CustomerIOMessagingPush: 6a21e2bd5bb4a6b483671e7703dc011a4deb8178 - CustomerIOMessagingPushAPN: 93e371ee9e5208497320bec6325e715db0a8b3ab - CustomerIOTracking: 5eab210defdf8950e0708713f7d95b35b779e056 + CustomerIO: 157786b8d83f792f73fea0455389445e80e8f582 + customerio-reactnative: 84e011604b93bf59f3d52e70e8444f0d0f8add12 + customerio-reactnative-richpush: f875b19d8f750810946e3705ef2a435690ae61ff + CustomerIOCommon: 2f1537b82af71a058b502885ef2604506af15bb4 + CustomerIOMessagingInApp: a78f32bc57d6baea2be4c7c7491bf733fb7e0596 + CustomerIOMessagingPush: c13903c4256d6d236d3b6bd29b77672b3908e788 + CustomerIOMessagingPushAPN: 13b08111e6901630017dc66871ead3d44d1b2f80 + CustomerIOTracking: 51dd017df4796203242032b6ffafbc8a9a740fb2 DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 FBLazyVector: 5d4a3b7f411219a45a6d952f77d2c0a6c9989da5 FBReactNativeSpec: 3fc2d478e1c4b08276f9dd9128f80ec6d5d85c1f @@ -707,6 +712,7 @@ SPEC CHECKSUMS: React-jsiexecutor: c7f826e40fa9cab5d37cab6130b1af237332b594 React-jsinspector: aaed4cf551c4a1c98092436518c2d267b13a673f React-logger: da1ebe05ae06eb6db4b162202faeafac4b435e77 + react-native-notifications: 4601a5a8db4ced6ae7cfc43b44d35fe437ac50c4 react-native-safe-area-context: 9697629f7b2cda43cf52169bb7e0767d330648c2 React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f React-perflogger: 496a1a3dc6737f964107cb3ddae7f9e265ddda58 @@ -738,4 +744,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: dd15e298a538ff617275f2a8acfe9f2e3d78fbbf -COCOAPODS: 1.12.1 +COCOAPODS: 1.14.3