onesignal-expo-plugin 1.0.0-beta1 → 1.0.0-beta10
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/CHANGELOG.md +13 -0
- package/LICENSE +24 -0
- package/README.md +78 -10
- package/app.plugin.js +1 -0
- package/build/onesignal/withOneSignalAndroid.js +11 -15
- package/build/onesignal/withOneSignalIos.js +153 -13
- package/build/support/NseUpdaterManager.js +56 -0
- package/build/support/OneSignalLog.js +12 -0
- package/build/support/ReaderManager.js +41 -0
- package/build/support/androidConstants.js +13 -0
- package/build/support/iosConstants.js +15 -0
- package/build/support/serviceExtensionFiles/NotificationService.h +8 -0
- package/build/support/serviceExtensionFiles/NotificationService.m +29 -0
- package/build/support/serviceExtensionFiles/OneSignalNotificationServiceExtension-Info.plist +31 -0
- package/build/support/serviceExtensionFiles/OneSignalNotificationServiceExtension.entitlements +10 -0
- package/build/support/updatePodfile.js +25 -0
- package/build/testRuniOS.js +20 -0
- package/onesignal/withOneSignal.ts +2 -1
- package/onesignal/withOneSignalAndroid.ts +12 -18
- package/onesignal/withOneSignalIos.ts +195 -18
- package/package.json +9 -5
- package/support/NseUpdaterManager.ts +42 -0
- package/support/OneSignalLog.ts +9 -0
- package/support/ReaderManager.ts +19 -0
- package/support/androidConstants.ts +11 -0
- package/support/iosConstants.ts +16 -0
- package/support/serviceExtensionFiles/NotificationService.h +8 -0
- package/support/serviceExtensionFiles/NotificationService.m +29 -0
- package/support/serviceExtensionFiles/OneSignalNotificationServiceExtension-Info.plist +31 -0
- package/support/serviceExtensionFiles/OneSignalNotificationServiceExtension.entitlements +10 -0
- package/support/updatePodfile.ts +19 -0
- package/testRuniOS.ts +26 -0
- package/tsconfig.json +2 -1
- package/types/xcode.d.ts +8 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
|
|
4
|
+
## January 2022
|
|
5
|
+
|
|
6
|
+
### `1.0.0-beta10` - 01/24/2022
|
|
7
|
+
#### Added
|
|
8
|
+
- ability to configure version numbers used in the NSE target's plist file.
|
|
9
|
+
- `OneSignalLog` class for better console logging.
|
|
10
|
+
- this changelog file.
|
|
11
|
+
|
|
12
|
+
#### Fixed
|
|
13
|
+
- re-running `expo prebuild` will no longer result in duplicate entitlements and dependencies added to native files.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Modified MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2021 OneSignal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
1. The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
2. All copies of substantial portions of the Software may only be used in connection
|
|
16
|
+
with services provided by OneSignal.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
<h1 align="center">Welcome to onesignal-expo-plugin 👋</h1>
|
|
2
2
|
<p>
|
|
3
|
-
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0--
|
|
3
|
+
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0--beta10-blue.svg?cacheSeconds=2592000" />
|
|
4
4
|
<a href="https://github.com/OneSignal/onesignal-expo-plugin#readme" target="_blank">
|
|
5
5
|
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
|
|
6
6
|
</a>
|
|
7
7
|
<a href="https://github.com/OneSignal/onesignal-expo-plugin/graphs/commit-activity" target="_blank">
|
|
8
8
|
<img alt="Maintenance" src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" />
|
|
9
9
|
</a>
|
|
10
|
-
<a href="https://github.com/OneSignal/onesignal-expo-plugin/blob/master/LICENSE" target="_blank">
|
|
11
|
-
<img alt="License: MIT" src="https://img.shields.io/github/license/OneSignal/onesignal-expo-plugin" />
|
|
12
|
-
</a>
|
|
13
10
|
<a href="https://twitter.com/onesignal" target="_blank">
|
|
14
11
|
<img alt="Twitter: onesignal" src="https://img.shields.io/twitter/follow/onesignal.svg?style=social" />
|
|
15
12
|
</a>
|
|
@@ -17,28 +14,71 @@
|
|
|
17
14
|
|
|
18
15
|
> The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
* 🏠 [Homepage](https://github.com/OneSignal/onesignal-expo-plugin#readme)
|
|
18
|
+
* 🖤 [npm](https://www.npmjs.com/package/onesignal-expo-plugin)
|
|
19
|
+
|
|
20
|
+
## 🚧 In Beta 🚧
|
|
21
|
+
## Overview
|
|
22
|
+
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.
|
|
23
|
+
|
|
24
|
+
## Supported environments:
|
|
25
|
+
* [The Expo run commands](https://docs.expo.dev/workflow/customizing/) (`expo run:[android|ios]`)
|
|
26
|
+
* [Custom clients](https://blog.expo.dev/introducing-custom-development-clients-5a2c79a9ddf8)
|
|
27
|
+
* [EAS Build](https://docs.expo.dev/build/introduction/)
|
|
28
|
+
|
|
29
|
+
---
|
|
21
30
|
|
|
22
31
|
## Install
|
|
23
32
|
|
|
24
33
|
```sh
|
|
25
34
|
expo install onesignal-expo-plugin
|
|
35
|
+
yarn add react-native-onesignal
|
|
26
36
|
```
|
|
27
37
|
|
|
28
|
-
**Note:** this does not install the [OneSignal SDK](https://github.com/OneSignal/react-native-onesignal).
|
|
29
|
-
|
|
30
38
|
## Configuration in app.json / app.config.js
|
|
31
39
|
### Plugin
|
|
32
|
-
Add the
|
|
40
|
+
Add the plugin to the [plugin array](https://docs.expo.dev/versions/latest/config/app/):
|
|
33
41
|
|
|
42
|
+
**app.json**
|
|
34
43
|
```json
|
|
35
44
|
{
|
|
36
45
|
"plugins": [
|
|
37
|
-
|
|
46
|
+
[
|
|
47
|
+
"onesignal-expo-plugin",
|
|
48
|
+
{
|
|
49
|
+
"mode": "development",
|
|
50
|
+
}
|
|
51
|
+
]
|
|
38
52
|
]
|
|
39
53
|
}
|
|
40
54
|
```
|
|
41
55
|
|
|
56
|
+
or
|
|
57
|
+
|
|
58
|
+
**app.config.js**
|
|
59
|
+
```js
|
|
60
|
+
export default {
|
|
61
|
+
...
|
|
62
|
+
plugins: [
|
|
63
|
+
[
|
|
64
|
+
"onesignal-expo-plugin",
|
|
65
|
+
{
|
|
66
|
+
mode: "development",
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
]
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### Plugin Prop
|
|
74
|
+
You can pass props to the plugin config object to configure:
|
|
75
|
+
|
|
76
|
+
| Plugin Prop | | |
|
|
77
|
+
|--------------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
78
|
+
| `mode` | **required** | Used to configure [APNs environment](https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment) entitlement. `"development"` or `"production"` |
|
|
79
|
+
| `devTeam` | optional | Used to configure Apple Team ID. You can find your Apple Team ID by running `expo credentials:manager` e.g: `"91SW8A37CR"` |
|
|
80
|
+
| `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"`. |
|
|
81
|
+
|
|
42
82
|
### OneSignal App ID
|
|
43
83
|
Add your OneSignal App ID to your [Expo constants via the `extra` param](https://docs.expo.dev/versions/latest/config/app/):
|
|
44
84
|
|
|
@@ -54,10 +94,38 @@ Add your OneSignal App ID to your [Expo constants via the `extra` param](https:/
|
|
|
54
94
|
You can then access the value to pass to the `setAppId` function:
|
|
55
95
|
|
|
56
96
|
```js
|
|
97
|
+
import OneSignal from 'react-native-onesignal';
|
|
57
98
|
import Constants from "expo-constants";
|
|
58
99
|
OneSignal.setAppId(Constants.manifest.extra.oneSignalAppId);
|
|
59
100
|
```
|
|
60
101
|
|
|
102
|
+
Alternatively, pass the app ID directly to the function:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
OneSignal.setAppId("YOUR-ONESIGNAL-APP-ID");
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Versioning
|
|
109
|
+
In your configuration file, make sure you set:
|
|
110
|
+
|
|
111
|
+
| Property | Details |
|
|
112
|
+
|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
113
|
+
| `version` | Your app version. Corresponds to `CFBundleShortVersionString` on iOS. This value will be used in your NSE* target's plist file. |
|
|
114
|
+
| `ios.buildNumber` | Build number for your iOS standalone app. Corresponds to `CFBundleVersion` and must match Apple's specified format. This value will be used in your NSE* target's plist file. |
|
|
115
|
+
|
|
116
|
+
\* NSE = Notification Service Extension. Learn more about the NSE [here](https://documentation.onesignal.com/docs/service-extensions).
|
|
117
|
+
|
|
118
|
+
## Run
|
|
119
|
+
```sh
|
|
120
|
+
$ expo prebuild --clean
|
|
121
|
+
|
|
122
|
+
# Build your native iOS project
|
|
123
|
+
$ expo run:ios
|
|
124
|
+
|
|
125
|
+
# Build your native Android project
|
|
126
|
+
$ expo run:android
|
|
127
|
+
```
|
|
128
|
+
|
|
61
129
|
---
|
|
62
130
|
|
|
63
131
|
## 🤝 Contributing
|
|
@@ -78,4 +146,4 @@ Give a ⭐️ if this project helped you!
|
|
|
78
146
|
## 📝 License
|
|
79
147
|
|
|
80
148
|
Copyright © 2021 [OneSignal](https://github.com/OneSignal).<br />
|
|
81
|
-
This project is [MIT](https://github.com/OneSignal/onesignal-expo-plugin/blob/
|
|
149
|
+
This project is [MIT](https://github.com/OneSignal/onesignal-expo-plugin/blob/main/LICENSE) licensed.
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./build/onesignal/withOneSignal.js');
|
|
@@ -6,26 +6,22 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.withOneSignalAndroid = void 0;
|
|
8
8
|
const config_plugins_1 = require("@expo/config-plugins");
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
buildscript {
|
|
12
|
-
repositories {
|
|
13
|
-
gradlePluginPortal()
|
|
14
|
-
}
|
|
15
|
-
dependencies {
|
|
16
|
-
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'`;
|
|
21
|
-
// ---------- ---------- ---------- ----------
|
|
9
|
+
const androidConstants_1 = require("../support/androidConstants");
|
|
10
|
+
const OneSignalLog_1 = require("../support/OneSignalLog");
|
|
22
11
|
const withGradleBuildConfig = (config) => {
|
|
23
12
|
return (0, config_plugins_1.withAppBuildGradle)(config, (newConfig) => {
|
|
24
|
-
|
|
13
|
+
let { contents } = newConfig.modResults;
|
|
14
|
+
// make sure we haven't previously added dependencies
|
|
15
|
+
if (!contents.includes(androidConstants_1.ONESIGNAL_GRADLE)) {
|
|
16
|
+
contents = `${androidConstants_1.ONESIGNAL_GRADLE}\n${contents}`;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
OneSignalLog_1.OneSignalLog.log("OneSignal dependencies already added to build.gradle. Skipping...");
|
|
20
|
+
}
|
|
21
|
+
newConfig.modResults.contents = contents;
|
|
25
22
|
return newConfig;
|
|
26
23
|
});
|
|
27
24
|
};
|
|
28
|
-
// ---------- ---------- ---------- ----------
|
|
29
25
|
const withOneSignalAndroid = (config, props) => {
|
|
30
26
|
withGradleBuildConfig(config, props);
|
|
31
27
|
return config;
|
|
@@ -3,17 +3,50 @@
|
|
|
3
3
|
* Expo config plugin for One Signal (iOS)
|
|
4
4
|
* @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps
|
|
5
5
|
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
6
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.withOneSignalIos = void 0;
|
|
29
|
+
exports.xcodeProjectAddNse = exports.withOneSignalIos = void 0;
|
|
8
30
|
const config_plugins_1 = require("@expo/config-plugins");
|
|
9
|
-
|
|
31
|
+
const fs = __importStar(require("fs"));
|
|
32
|
+
const xcode_1 = __importDefault(require("xcode"));
|
|
33
|
+
const iosConstants_1 = require("../support/iosConstants");
|
|
34
|
+
const updatePodfile_1 = require("../support/updatePodfile");
|
|
35
|
+
const NseUpdaterManager_1 = __importDefault(require("../support/NseUpdaterManager"));
|
|
36
|
+
const OneSignalLog_1 = require("../support/OneSignalLog");
|
|
10
37
|
/**
|
|
11
38
|
* Add 'app-environment' record with current environment to '<project-name>.entitlements' file
|
|
12
39
|
* @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps
|
|
13
40
|
*/
|
|
14
|
-
const withAppEnvironment = (config,
|
|
41
|
+
const withAppEnvironment = (config, onesignalProps) => {
|
|
15
42
|
return (0, config_plugins_1.withEntitlementsPlist)(config, (newConfig) => {
|
|
16
|
-
|
|
43
|
+
if ((onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.mode) == null) {
|
|
44
|
+
throw new Error(`
|
|
45
|
+
Missing required "mode" key in your app.json or app.config.js file for "onesignal-expo-plugin".
|
|
46
|
+
"mode" can be either "development" or "production".
|
|
47
|
+
Please see onesignal-expo-plugin's README.md for more details.`);
|
|
48
|
+
}
|
|
49
|
+
newConfig.modResults["aps-environment"] = onesignalProps.mode;
|
|
17
50
|
return newConfig;
|
|
18
51
|
});
|
|
19
52
|
};
|
|
@@ -22,11 +55,16 @@ const withAppEnvironment = (config, { mode }) => {
|
|
|
22
55
|
* @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps
|
|
23
56
|
*/
|
|
24
57
|
const withRemoteNotificationsPermissions = (config) => {
|
|
58
|
+
const BACKGROUND_MODE_KEYS = ["remote-notification"];
|
|
25
59
|
return (0, config_plugins_1.withInfoPlist)(config, (newConfig) => {
|
|
26
|
-
newConfig.modResults.UIBackgroundModes
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
60
|
+
if (!Array.isArray(newConfig.modResults.UIBackgroundModes)) {
|
|
61
|
+
newConfig.modResults.UIBackgroundModes = [];
|
|
62
|
+
}
|
|
63
|
+
for (const key of BACKGROUND_MODE_KEYS) {
|
|
64
|
+
if (!newConfig.modResults.UIBackgroundModes.includes(key)) {
|
|
65
|
+
newConfig.modResults.UIBackgroundModes.push(key);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
30
68
|
return newConfig;
|
|
31
69
|
});
|
|
32
70
|
};
|
|
@@ -35,19 +73,121 @@ const withRemoteNotificationsPermissions = (config) => {
|
|
|
35
73
|
* @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps (step 4.4)
|
|
36
74
|
*/
|
|
37
75
|
const withAppGroupPermissions = (config) => {
|
|
38
|
-
|
|
76
|
+
const APP_GROUP_KEY = "com.apple.security.application-groups";
|
|
77
|
+
return (0, config_plugins_1.withEntitlementsPlist)(config, newConfig => {
|
|
39
78
|
var _a;
|
|
40
|
-
newConfig.modResults[
|
|
41
|
-
|
|
42
|
-
|
|
79
|
+
if (!Array.isArray(newConfig.modResults[APP_GROUP_KEY])) {
|
|
80
|
+
newConfig.modResults[APP_GROUP_KEY] = [];
|
|
81
|
+
}
|
|
82
|
+
let modResultsArray = newConfig.modResults[APP_GROUP_KEY];
|
|
83
|
+
let entitlement = `group.${((_a = newConfig === null || newConfig === void 0 ? void 0 : newConfig.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier) || ""}.onesignal`;
|
|
84
|
+
if (modResultsArray.indexOf(entitlement) !== -1) {
|
|
85
|
+
return newConfig;
|
|
86
|
+
}
|
|
87
|
+
modResultsArray.push(entitlement);
|
|
43
88
|
return newConfig;
|
|
44
89
|
});
|
|
45
90
|
};
|
|
46
|
-
|
|
91
|
+
const withOneSignalNSE = (config, onesignalProps) => {
|
|
92
|
+
return (0, config_plugins_1.withXcodeProject)(config, async (props) => {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
const options = {
|
|
95
|
+
iosPath: props.modRequest.platformProjectRoot,
|
|
96
|
+
bundleIdentifier: (_a = props.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier,
|
|
97
|
+
devTeam: onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.devTeam,
|
|
98
|
+
bundleVersion: (_b = props.ios) === null || _b === void 0 ? void 0 : _b.buildNumber,
|
|
99
|
+
bundleShortVersion: props === null || props === void 0 ? void 0 : props.version,
|
|
100
|
+
iPhoneDeploymentTarget: onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.iPhoneDeploymentTarget
|
|
101
|
+
};
|
|
102
|
+
xcodeProjectAddNse(props.modRequest.projectName || "", options, "node_modules/onesignal-expo-plugin/build/support/serviceExtensionFiles/");
|
|
103
|
+
return props;
|
|
104
|
+
});
|
|
105
|
+
};
|
|
47
106
|
const withOneSignalIos = (config, props) => {
|
|
48
107
|
withAppEnvironment(config, props);
|
|
49
108
|
withRemoteNotificationsPermissions(config, props);
|
|
50
109
|
withAppGroupPermissions(config, props);
|
|
110
|
+
withOneSignalNSE(config, props);
|
|
51
111
|
return config;
|
|
52
112
|
};
|
|
53
113
|
exports.withOneSignalIos = withOneSignalIos;
|
|
114
|
+
function xcodeProjectAddNse(appName, options, sourceDir) {
|
|
115
|
+
const { iosPath, devTeam, bundleIdentifier, bundleVersion, bundleShortVersion, iPhoneDeploymentTarget } = options;
|
|
116
|
+
(0, updatePodfile_1.updatePodfile)(iosPath);
|
|
117
|
+
NseUpdaterManager_1.default.updateNSEEntitlements(`group.${bundleIdentifier}.onesignal`);
|
|
118
|
+
NseUpdaterManager_1.default.updateNSEBundleVersion(bundleVersion !== null && bundleVersion !== void 0 ? bundleVersion : iosConstants_1.DEFAULT_BUNDLE_VERSION);
|
|
119
|
+
NseUpdaterManager_1.default.updateNSEBundleShortVersion(bundleShortVersion !== null && bundleShortVersion !== void 0 ? bundleShortVersion : iosConstants_1.DEFAULT_BUNDLE_SHORT_VERSION);
|
|
120
|
+
const projPath = `${iosPath}/${appName}.xcodeproj/project.pbxproj`;
|
|
121
|
+
const targetName = "OneSignalNotificationServiceExtension";
|
|
122
|
+
const extFiles = [
|
|
123
|
+
"NotificationService.h",
|
|
124
|
+
"NotificationService.m",
|
|
125
|
+
`${targetName}.entitlements`,
|
|
126
|
+
`${targetName}-Info.plist`
|
|
127
|
+
];
|
|
128
|
+
const xcodeProject = xcode_1.default.project(projPath);
|
|
129
|
+
xcodeProject.parse(function (err) {
|
|
130
|
+
if (err) {
|
|
131
|
+
OneSignalLog_1.OneSignalLog.log(`Error parsing iOS project: ${JSON.stringify(err)}`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
// Copy in the extension files
|
|
135
|
+
fs.mkdirSync(`${iosPath}/${targetName}`, { recursive: true });
|
|
136
|
+
extFiles.forEach(function (extFile) {
|
|
137
|
+
let targetFile = `${iosPath}/${targetName}/${extFile}`;
|
|
138
|
+
try {
|
|
139
|
+
fs.createReadStream(`${sourceDir}${extFile}`).pipe(fs.createWriteStream(targetFile));
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
OneSignalLog_1.OneSignalLog.log(err);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
const projObjects = xcodeProject.hash.project.objects;
|
|
146
|
+
// Create new PBXGroup for the extension
|
|
147
|
+
let extGroup = xcodeProject.addPbxGroup(extFiles, targetName, targetName);
|
|
148
|
+
// Add the new PBXGroup to the top level group. This makes the
|
|
149
|
+
// files / folder appear in the file explorer in Xcode.
|
|
150
|
+
let groups = xcodeProject.hash.project.objects["PBXGroup"];
|
|
151
|
+
Object.keys(groups).forEach(function (key) {
|
|
152
|
+
if (groups[key].name === undefined) {
|
|
153
|
+
xcodeProject.addToPbxGroup(extGroup.uuid, key);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
// WORK AROUND for codeProject.addTarget BUG
|
|
157
|
+
// Xcode projects don't contain these if there is only one target
|
|
158
|
+
// An upstream fix should be made to the code referenced in this link:
|
|
159
|
+
// - https://github.com/apache/cordova-node-xcode/blob/8b98cabc5978359db88dc9ff2d4c015cba40f150/lib/pbxProject.js#L860
|
|
160
|
+
projObjects['PBXTargetDependency'] = projObjects['PBXTargetDependency'] || {};
|
|
161
|
+
projObjects['PBXContainerItemProxy'] = projObjects['PBXTargetDependency'] || {};
|
|
162
|
+
if (!!xcodeProject.pbxTargetByName(targetName)) {
|
|
163
|
+
OneSignalLog_1.OneSignalLog.log(`${targetName} already exists in project. Skipping...`);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// Add the NSE target
|
|
167
|
+
// This adds PBXTargetDependency and PBXContainerItemProxy for you
|
|
168
|
+
const nseTarget = xcodeProject.addTarget(targetName, "app_extension", targetName, `${bundleIdentifier}.${targetName}`);
|
|
169
|
+
// Add build phases to the new target
|
|
170
|
+
xcodeProject.addBuildPhase(["NotificationService.m"], "PBXSourcesBuildPhase", "Sources", nseTarget.uuid);
|
|
171
|
+
xcodeProject.addBuildPhase([], "PBXResourcesBuildPhase", "Resources", nseTarget.uuid);
|
|
172
|
+
xcodeProject.addBuildPhase([], "PBXFrameworksBuildPhase", "Frameworks", nseTarget.uuid);
|
|
173
|
+
// Edit the Deployment info of the new Target, only IphoneOS and Targeted Device Family
|
|
174
|
+
// However, can be more
|
|
175
|
+
let configurations = xcodeProject.pbxXCBuildConfigurationSection();
|
|
176
|
+
for (let key in configurations) {
|
|
177
|
+
if (typeof configurations[key].buildSettings !== "undefined" &&
|
|
178
|
+
configurations[key].buildSettings.PRODUCT_NAME == `"${targetName}"`) {
|
|
179
|
+
let buildSettingsObj = configurations[key].buildSettings;
|
|
180
|
+
buildSettingsObj.DEVELOPMENT_TEAM = devTeam;
|
|
181
|
+
buildSettingsObj.IPHONEOS_DEPLOYMENT_TARGET = iPhoneDeploymentTarget !== null && iPhoneDeploymentTarget !== void 0 ? iPhoneDeploymentTarget : iosConstants_1.IPHONEOS_DEPLOYMENT_TARGET;
|
|
182
|
+
buildSettingsObj.TARGETED_DEVICE_FAMILY = iosConstants_1.TARGETED_DEVICE_FAMILY;
|
|
183
|
+
buildSettingsObj.CODE_SIGN_ENTITLEMENTS = `${targetName}/${targetName}.entitlements`;
|
|
184
|
+
buildSettingsObj.CODE_SIGN_STYLE = "Automatic";
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Add development teams to both your target and the original project
|
|
188
|
+
xcodeProject.addTargetAttribute("DevelopmentTeam", devTeam, nseTarget);
|
|
189
|
+
xcodeProject.addTargetAttribute("DevelopmentTeam", devTeam);
|
|
190
|
+
fs.writeFileSync(projPath, xcodeProject.writeSync());
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
exports.xcodeProjectAddNse = xcodeProjectAddNse;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
const fs = __importStar(require("fs"));
|
|
23
|
+
const iosConstants_1 = require("./iosConstants");
|
|
24
|
+
const OneSignalLog_1 = require("./OneSignalLog");
|
|
25
|
+
const ReaderManager_1 = require("./ReaderManager");
|
|
26
|
+
const entitlementsFilePath = `${__dirname}/serviceExtensionFiles/OneSignalNotificationServiceExtension.entitlements`;
|
|
27
|
+
const plistFilePath = `${__dirname}/serviceExtensionFiles/OneSignalNotificationServiceExtension-Info.plist`;
|
|
28
|
+
const logIfError = (err) => {
|
|
29
|
+
if (err) {
|
|
30
|
+
OneSignalLog_1.OneSignalLog.error("Error updating OneSignal NSE Entitlement File.");
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
class NseUpdaterManager {
|
|
34
|
+
static async updateNSEEntitlements(groupIdentifier) {
|
|
35
|
+
let entitlementsFile = await ReaderManager_1.ReaderManager.readFile(entitlementsFilePath);
|
|
36
|
+
entitlementsFile = entitlementsFile.replace(iosConstants_1.GROUP_IDENTIFIER_TEMPLATE_REGEX, groupIdentifier);
|
|
37
|
+
fs.writeFile(entitlementsFilePath, entitlementsFile, 'utf-8', (err) => {
|
|
38
|
+
logIfError(err);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
static async updateNSEBundleVersion(version) {
|
|
42
|
+
let plistFile = await ReaderManager_1.ReaderManager.readFile(plistFilePath);
|
|
43
|
+
plistFile = plistFile.replace(iosConstants_1.BUNDLE_VERSION_TEMPLATE_REGEX, version);
|
|
44
|
+
fs.writeFile(plistFilePath, plistFile, 'utf-8', err => {
|
|
45
|
+
logIfError(err);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
static async updateNSEBundleShortVersion(version) {
|
|
49
|
+
let plistFile = await ReaderManager_1.ReaderManager.readFile(plistFilePath);
|
|
50
|
+
plistFile = plistFile.replace(iosConstants_1.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX, version);
|
|
51
|
+
fs.writeFile(plistFilePath, plistFile, 'utf-8', err => {
|
|
52
|
+
logIfError(err);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.default = NseUpdaterManager;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OneSignalLog = void 0;
|
|
4
|
+
class OneSignalLog {
|
|
5
|
+
static log(str) {
|
|
6
|
+
console.log(`\tonesignal-expo-plugin: ${str}`);
|
|
7
|
+
}
|
|
8
|
+
static error(str) {
|
|
9
|
+
console.error(`\tonesignal-expo-plugin: ${str}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.OneSignalLog = OneSignalLog;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.ReaderManager = void 0;
|
|
23
|
+
const fs = __importStar(require("fs"));
|
|
24
|
+
const OneSignalLog_1 = require("./OneSignalLog");
|
|
25
|
+
class ReaderManager {
|
|
26
|
+
static async readFile(path, replace) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
fs.readFile(path, 'utf8', (err, data) => {
|
|
29
|
+
if (err) {
|
|
30
|
+
reject(err);
|
|
31
|
+
}
|
|
32
|
+
if (!data) {
|
|
33
|
+
OneSignalLog_1.OneSignalLog.error("Couldn't read file:" + path);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
resolve(data);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.ReaderManager = ReaderManager;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ONESIGNAL_GRADLE = void 0;
|
|
4
|
+
exports.ONESIGNAL_GRADLE = `buildscript {
|
|
5
|
+
repositories {
|
|
6
|
+
gradlePluginPortal()
|
|
7
|
+
}
|
|
8
|
+
dependencies {
|
|
9
|
+
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_BUNDLE_SHORT_VERSION = exports.DEFAULT_BUNDLE_VERSION = exports.BUNDLE_VERSION_TEMPLATE_REGEX = exports.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = exports.GROUP_IDENTIFIER_TEMPLATE_REGEX = exports.NSE_PODFILE_REGEX = exports.NSE_PODFILE_SNIPPET = exports.TARGETED_DEVICE_FAMILY = exports.IPHONEOS_DEPLOYMENT_TARGET = void 0;
|
|
4
|
+
exports.IPHONEOS_DEPLOYMENT_TARGET = "11.0";
|
|
5
|
+
exports.TARGETED_DEVICE_FAMILY = `\"1,2\"`;
|
|
6
|
+
exports.NSE_PODFILE_SNIPPET = `
|
|
7
|
+
target 'OneSignalNotificationServiceExtension' do
|
|
8
|
+
pod 'OneSignalXCFramework', '>= 3.0', '< 4.0'
|
|
9
|
+
end`;
|
|
10
|
+
exports.NSE_PODFILE_REGEX = /target 'OneSignalNotificationServiceExtension'/;
|
|
11
|
+
exports.GROUP_IDENTIFIER_TEMPLATE_REGEX = /{{GROUP_IDENTIFIER}}/gm;
|
|
12
|
+
exports.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = /{{BUNDLE_SHORT_VERSION}}/gm;
|
|
13
|
+
exports.BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm;
|
|
14
|
+
exports.DEFAULT_BUNDLE_VERSION = '1';
|
|
15
|
+
exports.DEFAULT_BUNDLE_SHORT_VERSION = '1.0';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#import <OneSignal/OneSignal.h>
|
|
2
|
+
|
|
3
|
+
#import "NotificationService.h"
|
|
4
|
+
|
|
5
|
+
@interface NotificationService ()
|
|
6
|
+
|
|
7
|
+
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
|
|
8
|
+
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
|
|
9
|
+
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
|
|
10
|
+
|
|
11
|
+
@end
|
|
12
|
+
|
|
13
|
+
@implementation NotificationService
|
|
14
|
+
|
|
15
|
+
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
|
|
16
|
+
self.receivedRequest = request;
|
|
17
|
+
self.contentHandler = contentHandler;
|
|
18
|
+
self.bestAttemptContent = [request.content mutableCopy];
|
|
19
|
+
[OneSignal didReceiveNotificationExtensionRequest:self.receivedRequest
|
|
20
|
+
withMutableNotificationContent:self.bestAttemptContent
|
|
21
|
+
withContentHandler:self.contentHandler];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
- (void)serviceExtensionTimeWillExpire {
|
|
25
|
+
[OneSignal serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
|
|
26
|
+
self.contentHandler(self.bestAttemptContent);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleDisplayName</key>
|
|
8
|
+
<string>OneSignalNotificationServiceExtension</string>
|
|
9
|
+
<key>CFBundleExecutable</key>
|
|
10
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
11
|
+
<key>CFBundleIdentifier</key>
|
|
12
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
13
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
14
|
+
<string>6.0</string>
|
|
15
|
+
<key>CFBundleName</key>
|
|
16
|
+
<string>$(PRODUCT_NAME)</string>
|
|
17
|
+
<key>CFBundlePackageType</key>
|
|
18
|
+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
|
|
19
|
+
<key>CFBundleShortVersionString</key>
|
|
20
|
+
<string>{{BUNDLE_SHORT_VERSION}}</string>
|
|
21
|
+
<key>CFBundleVersion</key>
|
|
22
|
+
<string>{{BUNDLE_VERSION}}</string>
|
|
23
|
+
<key>NSExtension</key>
|
|
24
|
+
<dict>
|
|
25
|
+
<key>NSExtensionPointIdentifier</key>
|
|
26
|
+
<string>com.apple.usernotifications.service</string>
|
|
27
|
+
<key>NSExtensionPrincipalClass</key>
|
|
28
|
+
<string>NotificationService</string>
|
|
29
|
+
</dict>
|
|
30
|
+
</dict>
|
|
31
|
+
</plist>
|
package/build/support/serviceExtensionFiles/OneSignalNotificationServiceExtension.entitlements
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>com.apple.security.application-groups</key>
|
|
6
|
+
<array>
|
|
7
|
+
<string>{{GROUP_IDENTIFIER}}</string>
|
|
8
|
+
</array>
|
|
9
|
+
</dict>
|
|
10
|
+
</plist>
|