-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathwithPushNotifications.ts
More file actions
67 lines (56 loc) · 1.93 KB
/
Copy pathwithPushNotifications.ts
File metadata and controls
67 lines (56 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {
type ConfigPlugin,
withAppDelegate,
withInfoPlist,
} from '@expo/config-plugins';
import type { IntercomPluginProps } from './@types';
import {
findObjcFunctionCodeBlock,
insertContentsInsideObjcFunctionBlock,
} from '@expo/config-plugins/build/ios/codeMod';
import { withAndroidPushNotifications } from './withAndroidPushNotifications';
const appDelegate: ConfigPlugin<IntercomPluginProps> = (_config) =>
withAppDelegate(_config, (config) => {
const setDeviceTokenCode = '[IntercomModule setDeviceToken:deviceToken];';
let stringContents = config.modResults.contents;
const didRegisterBlock = findObjcFunctionCodeBlock(
stringContents,
'application didRegisterForRemoteNotificationsWithDeviceToken:'
);
if (!didRegisterBlock?.code.includes(setDeviceTokenCode)) {
stringContents = insertContentsInsideObjcFunctionBlock(
stringContents,
'application didRegisterForRemoteNotificationsWithDeviceToken:',
setDeviceTokenCode,
{ position: 'tailBeforeLastReturn' }
);
}
config.modResults.contents = stringContents;
return config;
});
const infoPlist: ConfigPlugin<IntercomPluginProps> = (_config) => {
const newConfig = withInfoPlist(_config, (config) => {
const keys = { remoteNotification: 'remote-notification' };
if (!config.modResults.UIBackgroundModes) {
config.modResults.UIBackgroundModes = [];
}
if (
config.modResults.UIBackgroundModes?.indexOf(keys.remoteNotification) ===
-1
) {
config.modResults.UIBackgroundModes?.push(keys.remoteNotification);
}
return config;
});
return newConfig;
};
export const withIntercomPushNotification: ConfigPlugin<IntercomPluginProps> = (
config,
props
) => {
let newConfig = config;
newConfig = appDelegate(newConfig, props);
newConfig = infoPlist(newConfig, props);
newConfig = withAndroidPushNotifications(newConfig, props);
return newConfig;
};