Skip to content

Commit e5821d3

Browse files
authored
feat: support for custom scheme link with fcm (#507)
1 parent 0a95a66 commit e5821d3

File tree

5 files changed

+33
-36
lines changed

5 files changed

+33
-36
lines changed

example/ios/NotificationServiceExtension/NotificationService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class NotificationService: UNNotificationServiceExtension {
2020

2121
PushInitializer.initializeForExtension(
2222
withConfig: MessagingPushConfigBuilder(cdpApiKey: Env.CDP_API_KEY)
23+
.logLevel(.debug)
2324
.build()
2425
)
2526

example/ios/Podfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ installation_root = Pod::Config.instance.installation_root
3131
create_project_file_if_not_exists(installation_root, app_target_name)
3232
update_project_build_settings(installation_root, app_target_name, nse_target_name, push_provider)
3333

34-
3534
if push_provider == "fcm"
3635
linkage = "dynamic"
3736
else
@@ -71,6 +70,6 @@ target nse_target_name do
7170
# Ideally, installing non-production SDK to main target should be enough
7271
# We should not need to install non-production SDK to app extension separately
7372
pod "customerio-reactnative-richpush/#{push_provider}", :path => cio_package_path
74-
# install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: false, push_service: push_provider)
75-
# install_non_production_ios_sdk_git_branch(branch_name: 'BRANCH-NAME-HERE', is_app_extension: false, push_service: push_provider)
73+
# install_non_production_ios_sdk_local_path(local_path: '~/code/customerio-ios/', is_app_extension: true, push_service: push_provider)
74+
# install_non_production_ios_sdk_git_branch(branch_name: 'BRANCH-NAME-HERE', is_app_extension: true, push_service: push_provider)
7675
end

example/src/App.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,10 @@ import { Storage } from '@services';
88
import { appTheme } from '@utils';
99
import { CioConfig, CioPushPermissionStatus, CustomerIO, InAppMessageEvent, InAppMessageEventType } from 'customerio-reactnative';
1010
import FlashMessage from 'react-native-flash-message';
11-
import { AppEnvValues } from './env';
11+
import { getEnvForApp } from './env';
1212

1313
export default function App({ appName }: { appName: string }) {
14-
const env =
15-
AppEnvValues[appName.toLocaleLowerCase() as keyof typeof AppEnvValues] ??
16-
AppEnvValues['default'];
17-
if (!env) {
18-
console.error(
19-
`No default preset environment variables found nor environment variables for the app: ${appName}. The env.ts contains environment values for case-insenetive app names: ${Object.keys(
20-
AppEnvValues
21-
).join(', ')}`
22-
);
23-
}
14+
const env = getEnvForApp(appName);
2415
Storage.setEnv(env);
2516

2617
const [isLoading, setIsLoading] = useState(true);

example/src/env.ts.sample

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,35 @@ export type Env = {
33
SITE_ID: string;
44
};
55

6-
export const AppEnvValues = {
7-
'default': {
8-
API_KEY: '<API_KEY>',
6+
// Replace placeholders with Customer.io API keys
7+
const envConfigs = {
8+
primary: {
9+
API_KEY: '<CDP_API_KEY>',
910
SITE_ID: '<SITE_ID>',
1011
} satisfies Env,
11-
12-
/**
13-
* If you are switching between Firebase and APN frequently for development,
14-
* Comment out the Env struct above and uncomment the one below
15-
* which will allow you to set API for FCM and APN separately.
16-
*/
17-
/*
18-
'apn': {
19-
API_KEY: '<API_KEY>',
20-
SITE_ID: '<SITE_ID>',
21-
} satisfies Env,
22-
'fcm': {
23-
API_KEY: '<API_KEY>',
24-
SITE_ID: '<SITE_ID>',
25-
} satisfies Env,
26-
'android fcm': {
27-
API_KEY: '<API_KEY>',
12+
// Optional: for iOS FCM testing
13+
secondary: {
14+
API_KEY: '<CDP_API_KEY>',
2815
SITE_ID: '<SITE_ID>',
2916
} satisfies Env,
30-
*/
3117
};
18+
19+
// Maps app names from index.js to configs. Modify if you change app names.
20+
const appEnvMap: Record<string, Env> = {
21+
'React Native APN': envConfigs.primary,
22+
'React Native Android': envConfigs.primary,
23+
'React Native FCM': envConfigs.secondary,
24+
};
25+
26+
export function getEnvForApp(appName: string): Env {
27+
const env = appEnvMap[appName];
28+
29+
if (!env) {
30+
console.warn(
31+
`No environment config found for app: "${appName}". Using primary config as fallback. Available app names: ${Object.keys(appEnvMap).join(', ')}`
32+
);
33+
return envConfigs.primary;
34+
}
35+
36+
return env;
37+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"./package.json": "./package.json"
2121
},
22-
"cioNativeiOSSdkVersion": "= 3.11.0",
22+
"cioNativeiOSSdkVersion": "= 3.13.1",
2323
"files": [
2424
"src",
2525
"lib",

0 commit comments

Comments
 (0)