onesignal-expo-plugin 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -36
- package/build/onesignal/withOneSignalAndroid.js +9 -15
- package/build/onesignal/withOneSignalIos.js +81 -47
- package/build/support/FileManager.js +22 -8
- package/build/support/NseUpdaterManager.js +8 -1
- package/build/support/eas/getEasManagedCredentialsConfigExtra.js +17 -17
- package/build/support/helpers.js +11 -7
- package/build/support/iosConstants.js +9 -5
- package/build/support/updatePodfile.js +3 -4
- package/build/types/types.js +9 -8
- package/package.json +19 -13
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -18
- package/.github/ISSUE_TEMPLATE/ask-question.yml +0 -50
- package/.github/ISSUE_TEMPLATE/bug-report.yml +0 -71
- package/.github/ISSUE_TEMPLATE/general-feedback.yml +0 -27
- package/.github/os_probot_metadata.js +0 -58
- package/.github/pull_request_template.md +0 -46
- package/.github/release-drafter.yml +0 -27
- package/.github/set_response_times.js +0 -47
- package/.github/workflows/Zapier.yml +0 -34
- package/.github/workflows/release-drafter.yml +0 -42
- package/.github/workflows/set_response_time.yml +0 -32
- package/CHANGELOG.md +0 -83
- package/EAS.md +0 -21
- package/IOS_CREDENTIALS_EAS.md +0 -170
- package/onesignal/withOneSignal.ts +0 -28
- package/onesignal/withOneSignalAndroid.ts +0 -147
- package/onesignal/withOneSignalIos.ts +0 -235
- package/support/FileManager.ts +0 -42
- package/support/NseUpdaterManager.ts +0 -40
- package/support/OneSignalLog.ts +0 -9
- package/support/eas/getEasManagedCredentialsConfigExtra.ts +0 -33
- package/support/helpers.ts +0 -41
- package/support/iosConstants.ts +0 -25
- package/support/serviceExtensionFiles/NotificationService.h +0 -8
- package/support/serviceExtensionFiles/NotificationService.m +0 -29
- package/support/serviceExtensionFiles/OneSignalNotificationServiceExtension-Info.plist +0 -31
- package/support/serviceExtensionFiles/OneSignalNotificationServiceExtension.entitlements +0 -10
- package/support/updatePodfile.ts +0 -19
- package/tsconfig.json +0 -16
- package/types/types.ts +0 -58
package/README.md
CHANGED
|
@@ -16,44 +16,40 @@
|
|
|
16
16
|
|
|
17
17
|
> The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
- 🏠 [Homepage](https://github.com/OneSignal/onesignal-expo-plugin#readme)
|
|
20
|
+
- 🖤 [npm](https://www.npmjs.com/package/onesignal-expo-plugin)
|
|
21
21
|
|
|
22
22
|
## Overview
|
|
23
|
+
|
|
23
24
|
This plugin is an [Expo Config Plugin](https://docs.expo.dev/guides/config-plugins/). It extends the Expo config to allow customizing the prebuild phase of managed workflow builds (no need to eject to a bare workflow). For the purposes of OneSignal integration, the plugin facilitates automatically generating/configuring the necessary native code files needed to get the [OneSignal React-Native SDK](https://github.com/OneSignal/react-native-onesignal) to work. You can think of adding a plugin as adding custom native code.
|
|
24
25
|
|
|
25
26
|
## Supported environments:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
|
|
28
|
+
- [The Expo run commands](https://docs.expo.dev/workflow/customizing/) (`expo run:[android|ios]`)
|
|
29
|
+
- [Custom clients](https://blog.expo.dev/introducing-custom-development-clients-5a2c79a9ddf8)
|
|
30
|
+
- [EAS Build](https://docs.expo.dev/build/introduction/)
|
|
29
31
|
|
|
30
32
|
---
|
|
31
33
|
|
|
32
34
|
## Install
|
|
33
|
-
You need both the `onesignal-expo-plugin` *and* the `react-native-onesignal` npm package.
|
|
34
|
-
|
|
35
|
-
```sh
|
|
36
|
-
npx expo install onesignal-expo-plugin
|
|
37
|
-
|
|
38
|
-
# npm
|
|
39
|
-
npm install react-native-onesignal
|
|
40
35
|
|
|
41
|
-
|
|
42
|
-
yarn add react-native-onesignal
|
|
43
|
-
```
|
|
36
|
+
See the [Setup Guide](https://documentation.onesignal.com/docs/en/react-native-expo-sdk-setup) for setup instructions.
|
|
44
37
|
|
|
45
38
|
## Configuration in app.json / app.config.js
|
|
39
|
+
|
|
46
40
|
### Plugin
|
|
41
|
+
|
|
47
42
|
Add the plugin to the **front** of the [plugin array](https://docs.expo.dev/versions/latest/config/app/). It should be added automatically if you ran `npx expo install`. Just make sure it is the first plugin in the array and to configure any desired plugin props:
|
|
48
43
|
|
|
49
44
|
**app.json**
|
|
45
|
+
|
|
50
46
|
```json
|
|
51
47
|
{
|
|
52
48
|
"plugins": [
|
|
53
49
|
[
|
|
54
50
|
"onesignal-expo-plugin",
|
|
55
51
|
{
|
|
56
|
-
"mode": "development"
|
|
52
|
+
"mode": "development"
|
|
57
53
|
}
|
|
58
54
|
]
|
|
59
55
|
]
|
|
@@ -63,6 +59,7 @@ Add the plugin to the **front** of the [plugin array](https://docs.expo.dev/vers
|
|
|
63
59
|
or
|
|
64
60
|
|
|
65
61
|
**app.config.js**
|
|
62
|
+
|
|
66
63
|
```js
|
|
67
64
|
export default {
|
|
68
65
|
...
|
|
@@ -78,22 +75,26 @@ export default {
|
|
|
78
75
|
```
|
|
79
76
|
|
|
80
77
|
#### Plugin Prop
|
|
78
|
+
|
|
81
79
|
You can pass props to the plugin config object to configure:
|
|
82
80
|
|
|
83
|
-
| Plugin Prop |
|
|
84
|
-
|
|
85
|
-
| `mode` | **required** | Used to configure
|
|
86
|
-
| `devTeam` | optional
|
|
87
|
-
| `iPhoneDeploymentTarget` | optional
|
|
88
|
-
| `smallIcons` | optional
|
|
89
|
-
| `largeIcons` | optional
|
|
90
|
-
| `smallIconAccentColor`
|
|
91
|
-
| `iosNSEFilePath` | optional
|
|
81
|
+
| Plugin Prop | | |
|
|
82
|
+
| ------------------------ | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
83
|
+
| `mode` | **required** | Used to configure [APNs environment](https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment) entitlement. `"development"` or `"production"` |
|
|
84
|
+
| `devTeam` | optional | Used to configure Apple Team ID. You can find your Apple Team ID by running `expo credentials:manager` e.g: `"91SW8A37CR"` |
|
|
85
|
+
| `iPhoneDeploymentTarget` | optional | Target `IPHONEOS_DEPLOYMENT_TARGET` value to be used when adding the iOS [NSE](https://documentation.onesignal.com/docs/service-extensions). A deployment target is nothing more than the minimum version of the operating system the application can run on. This value should match the value in your Podfile e.g: `"12.0"`. |
|
|
86
|
+
| `smallIcons` | optional | An array of local paths to small notification icons for Android. Image should be white, transparent, and 96x96 in size. Input images will be automatically scaled down and placed in the appropriate resource folders. e.g: `["./assets/ic_stat_onesignal_default.png"]`. See https://documentation.onesignal.com/docs/customize-notification-icons#small-notification-icons. |
|
|
87
|
+
| `largeIcons` | optional | An array of local paths to large notification icons for Android. Image should be white, transparent, and 256x256 in size. e.g: `["./assets/ic_onesignal_large_icon_default.png"]`. See https://documentation.onesignal.com/docs/customize-notification-icons#large-notification-icons. |
|
|
88
|
+
| `smallIconAccentColor` | optional | The accent color to use for notification icons on Android. Must be a valid hex value, e.g: `"#FF0000"` |
|
|
89
|
+
| `iosNSEFilePath` | optional | The local path to a custom Notification Service Extension (NSE), written in Objective-C. The NSE will typically start as a copy of the [default NSE](https://github.com/OneSignal/onesignal-expo-plugin/blob/main/support/serviceExtensionFiles/NotificationService.m), then altered to support any custom logic required. e.g: `"./assets/NotificationService.m"`. |
|
|
90
|
+
| `appGroupName` | optional | Used to configure a custom iOS [App Group](https://documentation.onesignal.com/docs/ios-sdk-setup#step-3-create-an-app-group) name. If not provided, defaults to `"group.{ios.bundleIdentifier}.onesignal"`. e.g: `"group.com.example.myapp.onesignal2"`. |
|
|
92
91
|
|
|
93
92
|
### OneSignal App ID
|
|
93
|
+
|
|
94
94
|
Add your OneSignal App ID to your [Expo constants via the `extra` param](https://docs.expo.dev/versions/latest/config/app/#extra):
|
|
95
95
|
|
|
96
96
|
**Example:**
|
|
97
|
+
|
|
97
98
|
```json
|
|
98
99
|
{
|
|
99
100
|
"extra": {
|
|
@@ -105,7 +106,7 @@ Add your OneSignal App ID to your [Expo constants via the `extra` param](https:/
|
|
|
105
106
|
You can then access the value to pass to the `initialize` function:
|
|
106
107
|
|
|
107
108
|
```js
|
|
108
|
-
import { OneSignal } from
|
|
109
|
+
import { OneSignal } from "react-native-onesignal";
|
|
109
110
|
import Constants from "expo-constants";
|
|
110
111
|
OneSignal.initialize(Constants.expoConfig.extra.oneSignalAppId);
|
|
111
112
|
```
|
|
@@ -117,31 +118,37 @@ OneSignal.initialize("YOUR-ONESIGNAL-APP-ID");
|
|
|
117
118
|
```
|
|
118
119
|
|
|
119
120
|
### Versioning
|
|
121
|
+
|
|
120
122
|
In your configuration file, make sure you set:
|
|
121
123
|
|
|
122
|
-
| Property
|
|
123
|
-
|
|
124
|
-
| `version`
|
|
125
|
-
| `ios.buildNumber`
|
|
126
|
-
| `ios.bundleIdentifier` | Bundle identifier for your iOS standalone app. Corresponds to `CFBundleIdentifier`. It's a unique identifier string that is used to identify an iOS app or bundle. It is typically in the format of `"com.companyname.appname"` (e.g. `"com.example.myapp"`). This value will be used in your NSE
|
|
124
|
+
| Property | Details |
|
|
125
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
126
|
+
| `version` | Your app version. Corresponds to `CFBundleShortVersionString` on iOS. It is a human-readable version number of an iOS app, and is typically in the format of "X.X.X" (e.g. "1.0" or "2.3.1"). It is the version number that is typically displayed to users in the App Store and in the app itself. This value will be used in your NSE\* target's plist file. |
|
|
127
|
+
| `ios.buildNumber` | Build number for your iOS standalone app. Corresponds to `CFBundleVersion` and must match Apple's specified format (e.g: "42" or "100"). The build number is used by the App Store and iOS to identify and track different versions of an app, and is typically incremented for each new release. It is a number typically used for the developer's and system reference. This value will be used in your NSE\* target's plist file. |
|
|
128
|
+
| `ios.bundleIdentifier` | Bundle identifier for your iOS standalone app. Corresponds to `CFBundleIdentifier`. It's a unique identifier string that is used to identify an iOS app or bundle. It is typically in the format of `"com.companyname.appname"` (e.g. `"com.example.myapp"`). This value will be used in your NSE\* target's plist and entitlements file. |
|
|
127
129
|
|
|
128
130
|
\* NSE = Notification Service Extension. Learn more about the NSE [here](https://documentation.onesignal.com/docs/service-extensions).
|
|
129
131
|
|
|
130
132
|
## EAS (Expo Application Services)
|
|
133
|
+
|
|
131
134
|
See our [EAS documentation](EAS.md) for help with EAS.
|
|
132
135
|
|
|
133
136
|
### iOS Credentials: OneSignal + EAS
|
|
137
|
+
|
|
134
138
|
To distribute your iOS application via EAS, you will need to ensure your credentials are set up correctly. See our [credentials setup guide for instructions](IOS_CREDENTIALS_EAS.md).
|
|
135
139
|
|
|
136
140
|
## Prebuild (optional)
|
|
141
|
+
|
|
137
142
|
Prebuilding in Expo will result in the generation of the native runtime code for the project (and `ios` and `android` directories being built). By prebuilding, we automatically link and configure the native modules that have implemented CocoaPods, autolinking, and other config plugins. You can think of prebuild like a native code bundler.
|
|
138
143
|
|
|
139
144
|
When you run `expo prebuild` we enter into a custom managed workflow which provides most of the benefits of bare workflows and managed workflows at the same time.
|
|
140
145
|
|
|
141
146
|
#### Why should I prebuild?
|
|
147
|
+
|
|
142
148
|
It may make sense to prebuild locally to inspect config plugin changes and help in debugging issues.
|
|
143
149
|
|
|
144
150
|
#### Run
|
|
151
|
+
|
|
145
152
|
```sh
|
|
146
153
|
npx expo prebuild
|
|
147
154
|
```
|
|
@@ -154,7 +161,9 @@ npx expo prebuild --clean
|
|
|
154
161
|
**EAS Note:** if you choose to stay in a fully managed workflow by not prebuilding, EAS will still run `npx expo prebuild` at build time. You can also prebuild locally but remain in a fully managed workflow by adding the `android` and `ios` directories to your .gitignore.
|
|
155
162
|
|
|
156
163
|
## Run
|
|
157
|
-
|
|
164
|
+
|
|
165
|
+
The following commands will prebuild _and_ run your application. Note that for iOS, push notifications will **not** work in the Simulator.
|
|
166
|
+
|
|
158
167
|
```sh
|
|
159
168
|
# Build and run your native iOS project
|
|
160
169
|
npx expo run:ios
|
|
@@ -175,10 +184,10 @@ Give a ⭐️ if this project helped you!
|
|
|
175
184
|
|
|
176
185
|
## OneSignal
|
|
177
186
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
187
|
+
- Website: https://onesignal.com
|
|
188
|
+
- Twitter: [@onesignal](https://twitter.com/onesignal)
|
|
189
|
+
- Github: [@OneSignal](https://github.com/OneSignal)
|
|
190
|
+
- LinkedIn: [@onesignal](https://linkedin.com/company/onesignal)
|
|
182
191
|
|
|
183
192
|
## 📝 License
|
|
184
193
|
|
|
@@ -17,23 +17,21 @@ const SMALL_ICON_DIRS_TO_SIZE = {
|
|
|
17
17
|
'drawable-hdpi': 36,
|
|
18
18
|
'drawable-xhdpi': 48,
|
|
19
19
|
'drawable-xxhdpi': 72,
|
|
20
|
-
'drawable-xxxhdpi': 96
|
|
20
|
+
'drawable-xxxhdpi': 96,
|
|
21
21
|
};
|
|
22
22
|
// The name of each large icon folder resource, and the icon size for that folder.
|
|
23
23
|
const LARGE_ICON_DIRS_TO_SIZE = {
|
|
24
|
-
'drawable-xxxhdpi': 256
|
|
24
|
+
'drawable-xxxhdpi': 256,
|
|
25
25
|
};
|
|
26
26
|
const withSmallIcons = (config, onesignalProps) => {
|
|
27
|
-
|
|
28
|
-
if (!onesignalProps.smallIcons && !((_a = config.notification) === null || _a === void 0 ? void 0 : _a.icon)) {
|
|
27
|
+
if (!onesignalProps.smallIcons && !config.notification?.icon) {
|
|
29
28
|
return config;
|
|
30
29
|
}
|
|
31
30
|
// we are modifying the android build (adding files) without a base mod
|
|
32
31
|
return (0, config_plugins_1.withDangerousMod)(config, [
|
|
33
32
|
'android',
|
|
34
33
|
async (config) => {
|
|
35
|
-
|
|
36
|
-
if ((_a = config.notification) === null || _a === void 0 ? void 0 : _a.icon) {
|
|
34
|
+
if (config.notification?.icon) {
|
|
37
35
|
await saveIconAsync(config.notification.icon, config.modRequest.projectRoot, SMALL_ICON_DIRS_TO_SIZE);
|
|
38
36
|
}
|
|
39
37
|
if (onesignalProps.smallIcons) {
|
|
@@ -63,15 +61,11 @@ const withSmallIconAccentColor = (config, onesignalProps) => {
|
|
|
63
61
|
return config;
|
|
64
62
|
}
|
|
65
63
|
return (0, config_plugins_1.withStringsXml)(config, (config) => {
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
const strings = (_b = config.modResults.resources.string) !== null && _b !== void 0 ? _b : [];
|
|
64
|
+
const colorInARGB = `FF${onesignalProps.smallIconAccentColor?.replace('#', '')}`;
|
|
65
|
+
const strings = config.modResults.resources.string ?? [];
|
|
69
66
|
// Check if the accent color entry already exists
|
|
70
|
-
const hasAccentColor = strings.some((stringEntry) =>
|
|
71
|
-
|
|
72
|
-
return ((_a = stringEntry.$) === null || _a === void 0 ? void 0 : _a.name) === 'onesignal_notification_accent_color' &&
|
|
73
|
-
stringEntry._ === colorInARGB;
|
|
74
|
-
});
|
|
67
|
+
const hasAccentColor = strings.some((stringEntry) => stringEntry.$?.name === 'onesignal_notification_accent_color' &&
|
|
68
|
+
stringEntry._ === colorInARGB);
|
|
75
69
|
if (!hasAccentColor) {
|
|
76
70
|
const accentColorEntry = {
|
|
77
71
|
$: { name: 'onesignal_notification_accent_color' },
|
|
@@ -89,7 +83,7 @@ async function saveIconsArrayAsync(projectRoot, icons, dirsToSize) {
|
|
|
89
83
|
}
|
|
90
84
|
async function saveIconAsync(icon, projectRoot, dirsToSize) {
|
|
91
85
|
const name = (0, path_1.parse)(icon).name;
|
|
92
|
-
OneSignalLog_1.OneSignalLog.log(
|
|
86
|
+
OneSignalLog_1.OneSignalLog.log('Saving icon ' + icon + ' as drawable resource ' + name);
|
|
93
87
|
for (const iconResourceDir in dirsToSize) {
|
|
94
88
|
const path = (0, path_1.resolve)(projectRoot, RESOURCE_ROOT_PATH, iconResourceDir);
|
|
95
89
|
if (!(0, fs_1.existsSync)(path)) {
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
7
|
if (k2 === undefined) k2 = k;
|
|
8
|
-
Object.
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
9
13
|
}) : (function(o, m, k, k2) {
|
|
10
14
|
if (k2 === undefined) k2 = k;
|
|
11
15
|
o[k2] = m[k];
|
|
@@ -15,13 +19,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
19
|
}) : function(o, v) {
|
|
16
20
|
o["default"] = v;
|
|
17
21
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
25
39
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
40
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
41
|
};
|
|
@@ -43,13 +57,13 @@ const getEasManagedCredentialsConfigExtra_1 = __importDefault(require("../suppor
|
|
|
43
57
|
*/
|
|
44
58
|
const withAppEnvironment = (config, onesignalProps) => {
|
|
45
59
|
return (0, config_plugins_1.withEntitlementsPlist)(config, (newConfig) => {
|
|
46
|
-
if (
|
|
60
|
+
if (onesignalProps?.mode == null) {
|
|
47
61
|
throw new Error(`
|
|
48
62
|
Missing required "mode" key in your app.json or app.config.js file for "onesignal-expo-plugin".
|
|
49
63
|
"mode" can be either "development" or "production".
|
|
50
64
|
Please see onesignal-expo-plugin's README.md for more details.`);
|
|
51
65
|
}
|
|
52
|
-
newConfig.modResults[
|
|
66
|
+
newConfig.modResults['aps-environment'] = onesignalProps.mode;
|
|
53
67
|
return newConfig;
|
|
54
68
|
});
|
|
55
69
|
};
|
|
@@ -58,7 +72,7 @@ const withAppEnvironment = (config, onesignalProps) => {
|
|
|
58
72
|
* @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps
|
|
59
73
|
*/
|
|
60
74
|
const withRemoteNotificationsPermissions = (config) => {
|
|
61
|
-
const BACKGROUND_MODE_KEYS = [
|
|
75
|
+
const BACKGROUND_MODE_KEYS = ['remote-notification'];
|
|
62
76
|
return (0, config_plugins_1.withInfoPlist)(config, (newConfig) => {
|
|
63
77
|
if (!Array.isArray(newConfig.modResults.UIBackgroundModes)) {
|
|
64
78
|
newConfig.modResults.UIBackgroundModes = [];
|
|
@@ -75,15 +89,14 @@ const withRemoteNotificationsPermissions = (config) => {
|
|
|
75
89
|
* Add "App Group" permission
|
|
76
90
|
* @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps (step 4.4)
|
|
77
91
|
*/
|
|
78
|
-
const withAppGroupPermissions = (config) => {
|
|
79
|
-
const APP_GROUP_KEY =
|
|
80
|
-
return (0, config_plugins_1.withEntitlementsPlist)(config, newConfig => {
|
|
81
|
-
var _a;
|
|
92
|
+
const withAppGroupPermissions = (config, props) => {
|
|
93
|
+
const APP_GROUP_KEY = 'com.apple.security.application-groups';
|
|
94
|
+
return (0, config_plugins_1.withEntitlementsPlist)(config, (newConfig) => {
|
|
82
95
|
if (!Array.isArray(newConfig.modResults[APP_GROUP_KEY])) {
|
|
83
96
|
newConfig.modResults[APP_GROUP_KEY] = [];
|
|
84
97
|
}
|
|
85
98
|
const modResultsArray = newConfig.modResults[APP_GROUP_KEY];
|
|
86
|
-
const entitlement =
|
|
99
|
+
const entitlement = (0, iosConstants_1.getAppGroupIdentifier)(newConfig?.ios?.bundleIdentifier || '', props?.appGroupName);
|
|
87
100
|
if (modResultsArray.indexOf(entitlement) !== -1) {
|
|
88
101
|
return newConfig;
|
|
89
102
|
}
|
|
@@ -91,10 +104,21 @@ const withAppGroupPermissions = (config) => {
|
|
|
91
104
|
return newConfig;
|
|
92
105
|
});
|
|
93
106
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Add OneSignal_app_groups_key to Info.plist when a custom app group name is provided.
|
|
109
|
+
* @see https://documentation.onesignal.com/docs/ios-sdk-setup#step-3-create-an-app-group
|
|
110
|
+
*/
|
|
111
|
+
const withCustomAppGroupsKey = (config, props) => {
|
|
112
|
+
return (0, config_plugins_1.withInfoPlist)(config, (newConfig) => {
|
|
113
|
+
if (props?.appGroupName) {
|
|
114
|
+
newConfig.modResults.OneSignal_app_groups_key = props.appGroupName;
|
|
115
|
+
}
|
|
116
|
+
return newConfig;
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
const withEasManagedCredentials = (config, props) => {
|
|
120
|
+
(0, assert_1.default)(config.ios?.bundleIdentifier, "Missing 'ios.bundleIdentifier' in app config.");
|
|
121
|
+
config.extra = (0, getEasManagedCredentialsConfigExtra_1.default)(config, props?.appGroupName);
|
|
98
122
|
return config;
|
|
99
123
|
};
|
|
100
124
|
const withOneSignalPodfile = (config) => {
|
|
@@ -102,21 +126,22 @@ const withOneSignalPodfile = (config) => {
|
|
|
102
126
|
'ios',
|
|
103
127
|
async (config) => {
|
|
104
128
|
// not awaiting in order to not block main thread
|
|
105
|
-
const iosRoot = path.join(config.modRequest.projectRoot,
|
|
106
|
-
(0, updatePodfile_1.updatePodfile)(iosRoot).catch(err => {
|
|
129
|
+
const iosRoot = path.join(config.modRequest.projectRoot, 'ios');
|
|
130
|
+
(0, updatePodfile_1.updatePodfile)(iosRoot).catch((err) => {
|
|
131
|
+
OneSignalLog_1.OneSignalLog.error(err);
|
|
132
|
+
});
|
|
107
133
|
return config;
|
|
108
134
|
},
|
|
109
135
|
]);
|
|
110
136
|
};
|
|
111
137
|
const withOneSignalNSE = (config, props) => {
|
|
112
138
|
// support for monorepos where node_modules can be above the project directory.
|
|
113
|
-
const pluginDir = require.resolve(
|
|
114
|
-
const sourceDir = path.join(pluginDir,
|
|
139
|
+
const pluginDir = require.resolve('onesignal-expo-plugin/package.json');
|
|
140
|
+
const sourceDir = path.join(pluginDir, '../build/support/serviceExtensionFiles/');
|
|
115
141
|
return (0, config_plugins_1.withDangerousMod)(config, [
|
|
116
142
|
'ios',
|
|
117
143
|
async (config) => {
|
|
118
|
-
|
|
119
|
-
const iosPath = path.join(config.modRequest.projectRoot, "ios");
|
|
144
|
+
const iosPath = path.join(config.modRequest.projectRoot, 'ios');
|
|
120
145
|
/* COPY OVER EXTENSION FILES */
|
|
121
146
|
fs.mkdirSync(`${iosPath}/${iosConstants_1.NSE_TARGET_NAME}`, { recursive: true });
|
|
122
147
|
for (let i = 0; i < iosConstants_1.NSE_EXT_FILES.length; i++) {
|
|
@@ -125,23 +150,26 @@ const withOneSignalNSE = (config, props) => {
|
|
|
125
150
|
await FileManager_1.FileManager.copyFile(`${sourceDir}${extFile}`, targetFile);
|
|
126
151
|
}
|
|
127
152
|
// Copy NSE source file either from configuration-provided location, falling back to the default one.
|
|
128
|
-
const sourcePath =
|
|
153
|
+
const sourcePath = props.iosNSEFilePath ?? `${sourceDir}${iosConstants_1.NSE_SOURCE_FILE}`;
|
|
129
154
|
const targetFile = `${iosPath}/${iosConstants_1.NSE_TARGET_NAME}/${iosConstants_1.NSE_SOURCE_FILE}`;
|
|
130
155
|
await FileManager_1.FileManager.copyFile(`${sourcePath}`, targetFile);
|
|
131
156
|
/* MODIFY COPIED EXTENSION FILES */
|
|
132
157
|
const nseUpdater = new NseUpdaterManager_1.default(iosPath);
|
|
133
|
-
|
|
134
|
-
await nseUpdater.
|
|
135
|
-
|
|
158
|
+
const appGroupId = (0, iosConstants_1.getAppGroupIdentifier)(config.ios?.bundleIdentifier ?? '', props.appGroupName);
|
|
159
|
+
await nseUpdater.updateNSEEntitlements(appGroupId);
|
|
160
|
+
if (props.appGroupName) {
|
|
161
|
+
await nseUpdater.updateNSEInfoPlistAppGroupKey(props.appGroupName);
|
|
162
|
+
}
|
|
163
|
+
await nseUpdater.updateNSEBundleVersion(config.ios?.buildNumber ?? iosConstants_1.DEFAULT_BUNDLE_VERSION);
|
|
164
|
+
await nseUpdater.updateNSEBundleShortVersion(config?.version ?? iosConstants_1.DEFAULT_BUNDLE_SHORT_VERSION);
|
|
136
165
|
return config;
|
|
137
166
|
},
|
|
138
167
|
]);
|
|
139
168
|
};
|
|
140
169
|
const withOneSignalXcodeProject = (config, props) => {
|
|
141
|
-
return (0, config_plugins_1.withXcodeProject)(config, newConfig => {
|
|
142
|
-
var _a, _b;
|
|
170
|
+
return (0, config_plugins_1.withXcodeProject)(config, (newConfig) => {
|
|
143
171
|
const xcodeProject = newConfig.modResults;
|
|
144
|
-
if (
|
|
172
|
+
if (xcodeProject.pbxTargetByName(iosConstants_1.NSE_TARGET_NAME)) {
|
|
145
173
|
OneSignalLog_1.OneSignalLog.log(`${iosConstants_1.NSE_TARGET_NAME} already exists in project. Skipping...`);
|
|
146
174
|
return newConfig;
|
|
147
175
|
}
|
|
@@ -149,9 +177,11 @@ const withOneSignalXcodeProject = (config, props) => {
|
|
|
149
177
|
const extGroup = xcodeProject.addPbxGroup([...iosConstants_1.NSE_EXT_FILES, iosConstants_1.NSE_SOURCE_FILE], iosConstants_1.NSE_TARGET_NAME, iosConstants_1.NSE_TARGET_NAME);
|
|
150
178
|
// Add the new PBXGroup to the top level group. This makes the
|
|
151
179
|
// files / folder appear in the file explorer in Xcode.
|
|
152
|
-
const groups = xcodeProject.hash.project.objects[
|
|
180
|
+
const groups = xcodeProject.hash.project.objects['PBXGroup'];
|
|
153
181
|
Object.keys(groups).forEach(function (key) {
|
|
154
|
-
if (typeof groups[key] ===
|
|
182
|
+
if (typeof groups[key] === 'object' &&
|
|
183
|
+
groups[key].name === undefined &&
|
|
184
|
+
groups[key].path === undefined) {
|
|
155
185
|
xcodeProject.addToPbxGroup(extGroup.uuid, key);
|
|
156
186
|
}
|
|
157
187
|
});
|
|
@@ -160,38 +190,42 @@ const withOneSignalXcodeProject = (config, props) => {
|
|
|
160
190
|
// An upstream fix should be made to the code referenced in this link:
|
|
161
191
|
// - https://github.com/apache/cordova-node-xcode/blob/8b98cabc5978359db88dc9ff2d4c015cba40f150/lib/pbxProject.js#L860
|
|
162
192
|
const projObjects = xcodeProject.hash.project.objects;
|
|
163
|
-
projObjects['PBXTargetDependency'] =
|
|
164
|
-
|
|
193
|
+
projObjects['PBXTargetDependency'] =
|
|
194
|
+
projObjects['PBXTargetDependency'] || {};
|
|
195
|
+
projObjects['PBXContainerItemProxy'] =
|
|
196
|
+
projObjects['PBXTargetDependency'] || {};
|
|
165
197
|
// Add the NSE target
|
|
166
198
|
// This adds PBXTargetDependency and PBXContainerItemProxy for you
|
|
167
|
-
const nseTarget = xcodeProject.addTarget(iosConstants_1.NSE_TARGET_NAME,
|
|
199
|
+
const nseTarget = xcodeProject.addTarget(iosConstants_1.NSE_TARGET_NAME, 'app_extension', iosConstants_1.NSE_TARGET_NAME, `${config.ios?.bundleIdentifier}.${iosConstants_1.NSE_TARGET_NAME}`);
|
|
168
200
|
// Add build phases to the new target
|
|
169
|
-
xcodeProject.addBuildPhase([
|
|
170
|
-
xcodeProject.addBuildPhase([],
|
|
171
|
-
xcodeProject.addBuildPhase([],
|
|
201
|
+
xcodeProject.addBuildPhase(['NotificationService.m'], 'PBXSourcesBuildPhase', 'Sources', nseTarget.uuid);
|
|
202
|
+
xcodeProject.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', nseTarget.uuid);
|
|
203
|
+
xcodeProject.addBuildPhase([], 'PBXFrameworksBuildPhase', 'Frameworks', nseTarget.uuid);
|
|
172
204
|
// Edit the Deployment info of the new Target, only IphoneOS and Targeted Device Family
|
|
173
205
|
// However, can be more
|
|
174
206
|
const configurations = xcodeProject.pbxXCBuildConfigurationSection();
|
|
175
207
|
for (const key in configurations) {
|
|
176
|
-
if (typeof configurations[key].buildSettings !==
|
|
208
|
+
if (typeof configurations[key].buildSettings !== 'undefined' &&
|
|
177
209
|
configurations[key].buildSettings.PRODUCT_NAME == `"${iosConstants_1.NSE_TARGET_NAME}"`) {
|
|
178
210
|
const buildSettingsObj = configurations[key].buildSettings;
|
|
179
|
-
buildSettingsObj.DEVELOPMENT_TEAM = props
|
|
180
|
-
buildSettingsObj.IPHONEOS_DEPLOYMENT_TARGET =
|
|
211
|
+
buildSettingsObj.DEVELOPMENT_TEAM = props?.devTeam;
|
|
212
|
+
buildSettingsObj.IPHONEOS_DEPLOYMENT_TARGET =
|
|
213
|
+
props?.iPhoneDeploymentTarget ?? iosConstants_1.IPHONEOS_DEPLOYMENT_TARGET;
|
|
181
214
|
buildSettingsObj.TARGETED_DEVICE_FAMILY = iosConstants_1.TARGETED_DEVICE_FAMILY;
|
|
182
215
|
buildSettingsObj.CODE_SIGN_ENTITLEMENTS = `${iosConstants_1.NSE_TARGET_NAME}/${iosConstants_1.NSE_TARGET_NAME}.entitlements`;
|
|
183
|
-
buildSettingsObj.CODE_SIGN_STYLE =
|
|
216
|
+
buildSettingsObj.CODE_SIGN_STYLE = 'Automatic';
|
|
184
217
|
}
|
|
185
218
|
}
|
|
186
219
|
// Add development teams to both your target and the original project
|
|
187
|
-
xcodeProject.addTargetAttribute(
|
|
188
|
-
xcodeProject.addTargetAttribute(
|
|
220
|
+
xcodeProject.addTargetAttribute('DevelopmentTeam', props?.devTeam, nseTarget);
|
|
221
|
+
xcodeProject.addTargetAttribute('DevelopmentTeam', props?.devTeam);
|
|
189
222
|
return newConfig;
|
|
190
223
|
});
|
|
191
224
|
};
|
|
192
225
|
const withOneSignalIos = (config, props) => {
|
|
193
226
|
config = withAppEnvironment(config, props);
|
|
194
227
|
config = withRemoteNotificationsPermissions(config, props);
|
|
228
|
+
config = withCustomAppGroupsKey(config, props);
|
|
195
229
|
config = withAppGroupPermissions(config, props);
|
|
196
230
|
config = withOneSignalPodfile(config, props);
|
|
197
231
|
config = withOneSignalNSE(config, props);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -11,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
11
15
|
}) : function(o, v) {
|
|
12
16
|
o["default"] = v;
|
|
13
17
|
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
21
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
36
|
exports.FileManager = void 0;
|
|
23
37
|
const fs = __importStar(require("fs"));
|
|
@@ -6,8 +6,8 @@ const iosConstants_1 = require("./iosConstants");
|
|
|
6
6
|
const entitlementsFileName = `OneSignalNotificationServiceExtension.entitlements`;
|
|
7
7
|
const plistFileName = `OneSignalNotificationServiceExtension-Info.plist`;
|
|
8
8
|
class NseUpdaterManager {
|
|
9
|
+
nsePath = '';
|
|
9
10
|
constructor(iosPath) {
|
|
10
|
-
this.nsePath = '';
|
|
11
11
|
this.nsePath = `${iosPath}/${iosConstants_1.NSE_TARGET_NAME}`;
|
|
12
12
|
}
|
|
13
13
|
async updateNSEEntitlements(groupIdentifier) {
|
|
@@ -28,5 +28,12 @@ class NseUpdaterManager {
|
|
|
28
28
|
plistFile = plistFile.replace(iosConstants_1.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX, version);
|
|
29
29
|
await FileManager_1.FileManager.writeFile(plistFilePath, plistFile);
|
|
30
30
|
}
|
|
31
|
+
async updateNSEInfoPlistAppGroupKey(appGroupName) {
|
|
32
|
+
const plistFilePath = `${this.nsePath}/${plistFileName}`;
|
|
33
|
+
let plistFile = await FileManager_1.FileManager.readFile(plistFilePath);
|
|
34
|
+
const appGroupEntry = `\t<key>OneSignal_app_groups_key</key>\n\t<string>${appGroupName}</string>\n</dict>\n</plist>`;
|
|
35
|
+
plistFile = plistFile.replace('</dict>\n</plist>', appGroupEntry);
|
|
36
|
+
await FileManager_1.FileManager.writeFile(plistFilePath, plistFile);
|
|
37
|
+
}
|
|
31
38
|
}
|
|
32
39
|
exports.default = NseUpdaterManager;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = getEasManagedCredentialsConfigExtra;
|
|
3
4
|
const iosConstants_1 = require("../iosConstants");
|
|
4
|
-
function getEasManagedCredentialsConfigExtra(config) {
|
|
5
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
5
|
+
function getEasManagedCredentialsConfigExtra(config, appGroupName) {
|
|
6
6
|
return {
|
|
7
7
|
...config.extra,
|
|
8
8
|
eas: {
|
|
9
|
-
...
|
|
9
|
+
...config.extra?.eas,
|
|
10
10
|
build: {
|
|
11
|
-
...
|
|
11
|
+
...config.extra?.eas?.build,
|
|
12
12
|
experimental: {
|
|
13
|
-
...
|
|
13
|
+
...config.extra?.eas?.build?.experimental,
|
|
14
14
|
ios: {
|
|
15
|
-
...
|
|
15
|
+
...config.extra?.eas?.build?.experimental?.ios,
|
|
16
16
|
appExtensions: [
|
|
17
|
-
...(
|
|
17
|
+
...(config.extra?.eas?.build?.experimental?.ios?.appExtensions ??
|
|
18
|
+
[]),
|
|
18
19
|
{
|
|
19
20
|
// keep in sync with native changes in NSE
|
|
20
21
|
targetName: iosConstants_1.NSE_TARGET_NAME,
|
|
21
|
-
bundleIdentifier: `${
|
|
22
|
+
bundleIdentifier: `${config?.ios?.bundleIdentifier}.${iosConstants_1.NSE_TARGET_NAME}`,
|
|
22
23
|
entitlements: {
|
|
23
24
|
'com.apple.security.application-groups': [
|
|
24
|
-
|
|
25
|
-
]
|
|
25
|
+
(0, iosConstants_1.getAppGroupIdentifier)(config?.ios?.bundleIdentifier ?? '', appGroupName),
|
|
26
|
+
],
|
|
26
27
|
},
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
|
-
exports.default = getEasManagedCredentialsConfigExtra;
|