Skip to content

Commit

Permalink
fix: differentiate every push event handler installed in app (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
levibostian authored Jun 26, 2024
1 parent ed072b5 commit 84d7259
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 27 deletions.
14 changes: 7 additions & 7 deletions Apps/APN/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
PODS:
- boost (1.76.0)
- customerio-reactnative (3.7.0):
- customerio-reactnative/nopush (= 3.7.0)
- customerio-reactnative (3.7.1):
- customerio-reactnative/nopush (= 3.7.1)
- CustomerIO/MessagingInApp (= 2.13.1)
- CustomerIO/Tracking (= 2.13.1)
- React-Core
- customerio-reactnative-richpush/apn (3.7.0):
- customerio-reactnative-richpush/apn (3.7.1):
- CustomerIO/MessagingPushAPN (= 2.13.1)
- customerio-reactnative/apn (3.7.0):
- customerio-reactnative/apn (3.7.1):
- CustomerIO/MessagingInApp (= 2.13.1)
- CustomerIO/MessagingPushAPN (= 2.13.1)
- CustomerIO/Tracking (= 2.13.1)
- React-Core
- customerio-reactnative/nopush (3.7.0):
- customerio-reactnative/nopush (3.7.1):
- CustomerIO/MessagingInApp (= 2.13.1)
- CustomerIO/MessagingPush (= 2.13.1)
- CustomerIO/Tracking (= 2.13.1)
Expand Down Expand Up @@ -684,8 +684,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
boost: 57d2868c099736d80fcd648bf211b4431e51a558
CustomerIO: d0f43c1bc2aac2da1a89d1f0bb859f9f10064289
customerio-reactnative: f67983a684fb22fb119234f6249af32e9a821c5c
customerio-reactnative-richpush: b91c1e9f190a0bd99d0254e561707cd58f075ed5
customerio-reactnative: e87b4c5fa21d2a512407c4ee8fdfa35f74c4f42c
customerio-reactnative-richpush: c74c1bcbfa5256c08e30e1e1e73a9fe1f01cc7c2
CustomerIOCommon: e5146548da6c21aa24ce31827f9e90a4aeee14d2
CustomerIOMessagingInApp: 4af224900f34d5ac0ca1cc4f70c2d165bd277912
CustomerIOMessagingPush: 0c0bb2fa4ef0a53c4356c3dad1227113372bab36
Expand Down
5 changes: 5 additions & 0 deletions Apps/FCM/ios/FCMSampleApp/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import <React/RCTLinkingManager.h>
#import <React/RCTBundleURLProvider.h>
#import <FirebaseCore.h>
#import "RNNotifications.h"

@implementation AppDelegate

Expand Down Expand Up @@ -34,6 +35,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}

[pnHandlerObj setupCustomerIOClickHandling];

[RNNotifications startMonitorNotifications];

return [super application:application didFinishLaunchingWithOptions:modifiedLaunchOptions];
}
Expand All @@ -52,6 +55,8 @@ - (NSURL *)getBundleURL {

- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
[pnHandlerObj didReceiveRegistrationToken:messaging fcmToken: fcmToken];

[RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:fcmToken];
}

// Deep links handling for app scheme links
Expand Down
12 changes: 10 additions & 2 deletions Apps/FCM/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# -------------
# This code only used internally for Customer.io testing
require 'open-uri'
IO.copy_stream(URI.open('https://raw.githubusercontent.com/customerio/customerio-ios/v2/scripts/cocoapods_override_sdk.rb'), "/tmp/override_cio_sdk.rb")
load "/tmp/override_cio_sdk.rb"
# end of internal Customer.io testing code
# -------------

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
'require.resolve(
Expand Down Expand Up @@ -40,7 +48,7 @@ target 'FCMSampleApp' do

pod 'customerio-reactnative/fcm', :path => '../node_modules/customerio-reactnative'
# install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: false, push_service: "fcm")
# install_non_production_ios_sdk_git_branch(branch_name: 'main', is_app_extension: false, push_service: "fcm")
# install_non_production_ios_sdk_git_branch(branch_name: 'levi/v2-multiple-push-handlers', is_app_extension: false, push_service: "fcm")

post_install do |installer|
# https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
Expand All @@ -55,5 +63,5 @@ end
target 'NotificationServiceExtension' do
pod 'customerio-reactnative-richpush/fcm', :path => '../node_modules/customerio-reactnative'
# install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: true, push_service: "fcm")
# install_non_production_ios_sdk_git_branch(branch_name: 'main', is_app_extension: true, push_service: "fcm")
# install_non_production_ios_sdk_git_branch(branch_name: 'levi/v2-multiple-push-handlers', is_app_extension: true, push_service: "fcm")
end
30 changes: 18 additions & 12 deletions Apps/FCM/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
PODS:
- boost (1.83.0)
- customerio-reactnative (3.7.0):
- customerio-reactnative/nopush (= 3.7.0)
- customerio-reactnative (3.7.1):
- customerio-reactnative/nopush (= 3.7.1)
- CustomerIO/MessagingInApp (= 2.13.1)
- CustomerIO/Tracking (= 2.13.1)
- React-Core
- customerio-reactnative-richpush/fcm (3.7.0):
- customerio-reactnative-richpush/fcm (3.7.1):
- CustomerIO/MessagingPushFCM (= 2.13.1)
- customerio-reactnative/fcm (3.7.0):
- customerio-reactnative/fcm (3.7.1):
- CustomerIO/MessagingInApp (= 2.13.1)
- CustomerIO/MessagingPushFCM (= 2.13.1)
- CustomerIO/Tracking (= 2.13.1)
- React-Core
- customerio-reactnative/nopush (3.7.0):
- customerio-reactnative/nopush (3.7.1):
- CustomerIO/MessagingInApp (= 2.13.1)
- CustomerIO/MessagingPush (= 2.13.1)
- CustomerIO/Tracking (= 2.13.1)
Expand Down Expand Up @@ -55,9 +55,9 @@ PODS:
- GoogleUtilities/Logger (~> 7.12)
- FirebaseCoreExtension (10.20.0):
- FirebaseCore (~> 10.0)
- FirebaseCoreInternal (10.27.0):
- FirebaseCoreInternal (10.28.0):
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- FirebaseInstallations (10.27.0):
- FirebaseInstallations (10.28.0):
- FirebaseCore (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/UserDefaults (~> 7.8)
Expand Down Expand Up @@ -983,6 +983,8 @@ PODS:
- React-Mapbuffer (0.73.7):
- glog
- React-debug
- react-native-notifications (5.1.0):
- React-Core
- react-native-safe-area-context (4.9.0):
- React-Core
- React-nativeconfig (0.73.7)
Expand Down Expand Up @@ -1213,6 +1215,7 @@ DEPENDENCIES:
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector-modern`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
- react-native-notifications (from `../node_modules/react-native-notifications`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
Expand Down Expand Up @@ -1326,6 +1329,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/logger"
React-Mapbuffer:
:path: "../node_modules/react-native/ReactCommon"
react-native-notifications:
:path: "../node_modules/react-native-notifications"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
React-nativeconfig:
Expand Down Expand Up @@ -1390,8 +1395,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
CustomerIO: d0f43c1bc2aac2da1a89d1f0bb859f9f10064289
customerio-reactnative: f67983a684fb22fb119234f6249af32e9a821c5c
customerio-reactnative-richpush: b91c1e9f190a0bd99d0254e561707cd58f075ed5
customerio-reactnative: e87b4c5fa21d2a512407c4ee8fdfa35f74c4f42c
customerio-reactnative-richpush: c74c1bcbfa5256c08e30e1e1e73a9fe1f01cc7c2
CustomerIOCommon: e5146548da6c21aa24ce31827f9e90a4aeee14d2
CustomerIOMessagingInApp: 4af224900f34d5ac0ca1cc4f70c2d165bd277912
CustomerIOMessagingPush: 0c0bb2fa4ef0a53c4356c3dad1227113372bab36
Expand All @@ -1403,8 +1408,8 @@ SPEC CHECKSUMS:
Firebase: 10c8cb12fb7ad2ae0c09ffc86cd9c1ab392a0031
FirebaseCore: 28045c1560a2600d284b9c45a904fe322dc890b6
FirebaseCoreExtension: 0659f035b88c5a7a15a9763c48c2e6ca8c0a2977
FirebaseCoreInternal: 4b297a2d56063dbea2c1d0d04222d44a8d058862
FirebaseInstallations: 766dabca09fd94aef922538aaf144cc4a6fb6869
FirebaseCoreInternal: 58d07f1362fddeb0feb6a857d1d1d1c5e558e698
FirebaseInstallations: 60c1d3bc1beef809fd1ad1189a8057a040c59f2e
FirebaseMessaging: 06c414a21b122396a26847c523d5c370f8325df5
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
Expand Down Expand Up @@ -1435,6 +1440,7 @@ SPEC CHECKSUMS:
React-jsinspector: f356e49aa086380d3a4892708ca173ad31ac69c1
React-logger: 7b19bdfb254772a0332d6cd4d66eceb0678b6730
React-Mapbuffer: 6f392912435adb8fbf4c3eee0e79a0a0b4e4b717
react-native-notifications: 4601a5a8db4ced6ae7cfc43b44d35fe437ac50c4
react-native-safe-area-context: b97eb6f9e3b7f437806c2ce5983f479f8eb5de4b
React-nativeconfig: 754233aac2a769578f828093b672b399355582e6
React-NativeModulesApple: a03b2da2b8e127d5f5ee29c683e0deba7a9e1575
Expand Down Expand Up @@ -1467,6 +1473,6 @@ SPEC CHECKSUMS:
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: 47d399a73c0c0caa9ff824e5c657eae31215bfee

PODFILE CHECKSUM: 8d8557dd1ff4a93c00082d7891396db321197157
PODFILE CHECKSUM: 856c598ef31ca9704d7f356fc3128c0680cd0c97

COCOAPODS: 1.15.2
11 changes: 6 additions & 5 deletions Apps/FCM/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"react-native": "^0.73.6",
"react-native-device-info": "^10.8.0",
"react-native-gesture-handler": "^2.12.1",
"react-native-notifications": "^5.1.0",
"react-native-safe-area-context": "^4.7.1",
"react-native-screens": "^3.23.0",
"react-native-snackbar": "^2.6.2"
Expand All @@ -28,16 +29,16 @@
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.2.1",
"eslint": "^8.19.0",
"prettier": "^2.4.1",
"react-test-renderer": "18.2.0",
"@react-native/babel-preset": "0.73.21",
"@react-native/eslint-config": "0.73.2",
"@react-native/metro-config": "0.73.5",
"@react-native/typescript-config": "0.73.1",
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.2.1",
"eslint": "^8.19.0",
"prettier": "^2.4.1",
"react-test-renderer": "18.2.0",
"typescript": "5.0.4"
},
"engines": {
Expand Down
45 changes: 45 additions & 0 deletions Apps/FCM/src/screens/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { useUserStateContext } from '../state/userState';
import { generateRandomNumber } from '../utils/helpers';
import { navigateToScreen } from '../utils/navigation';
import Prompts from '../utils/prompts';
import { Notification, Notifications } from 'react-native-notifications';
import { CustomerIO } from 'customerio-reactnative';

const pushPermissionAlertTitle = 'Push Permission';

Expand Down Expand Up @@ -144,6 +146,15 @@ const Dashboard: React.FC<DashboardProps> = ({ navigation }) => {
handlePushPermissionCheck();
break;

case ActionItem.SHOW_LOCAL_PUSH:
// 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',
} as Notification);
break;

case ActionItem.SIGN_OUT:
await onUserStateChanged(undefined);
break;
Expand All @@ -156,6 +167,36 @@ const Dashboard: React.FC<DashboardProps> = ({ navigation }) => {
}
};

// 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(
`notification received in foreground: ${notification.title} : ${notification.body}`
);

CustomerIO.track('push should show app in foreground', {
push: notification.payload
});

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(
`notification opened: ${notification.payload}`
);

CustomerIO.track('push clicked', { push: notification.payload });

completion();
}
);

return (
<View style={styles.container}>
<View style={styles.topBar}>
Expand Down Expand Up @@ -227,6 +268,10 @@ const ActionItem: Record<string, ActionItemType> = {
text: 'Show Push Prompt',
contentDesc: 'Show Push Prompt Button',
},
SHOW_LOCAL_PUSH: {
text: 'Show Local Push',
contentDesc: 'Show Local Push Button',
},
SIGN_OUT: {
text: 'Log Out',
contentDesc: 'Log Out Button',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"react-native": "src/index",
"source": "src/index",
"expoVersion": "",
"cioNativeiOSSdkVersion": "= 2.13.1",
"cioNativeiOSSdkVersion": "= 2.13.2",
"files": [
"src",
"lib",
Expand Down

0 comments on commit 84d7259

Please sign in to comment.