@onesignal/capacitor-plugin 1.0.5 → 1.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/OneSignalCapacitorPlugin.podspec +9 -1
- package/Package.swift +29 -13
- package/README.md +132 -16
- package/android/build.gradle.kts +15 -1
- package/android/gradle/libs.versions.toml +1 -1
- package/android/src/main/kotlin/com/onesignal/capacitor/OneSignalCapacitorPlugin.kt +27 -22
- package/ios/Sources/OneSignalCapacitorPlugin/OneSignalCapacitorPlugin.swift +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
require 'json'
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
onesignal_xcframework_version = '5.5.2'
|
|
5
|
+
onesignal_disable_location_env = ENV['ONESIGNAL_DISABLE_LOCATION'].to_s.strip.downcase
|
|
6
|
+
onesignal_disable_location = ['true', '1'].include?(onesignal_disable_location_env)
|
|
4
7
|
|
|
5
8
|
Pod::Spec.new do |s|
|
|
6
9
|
s.name = 'OnesignalCapacitorPlugin'
|
|
@@ -20,5 +23,10 @@ Pod::Spec.new do |s|
|
|
|
20
23
|
s.swift_version = '5.9'
|
|
21
24
|
|
|
22
25
|
s.dependency 'Capacitor'
|
|
23
|
-
|
|
26
|
+
if onesignal_disable_location
|
|
27
|
+
s.dependency 'OneSignalXCFramework/OneSignal', onesignal_xcframework_version
|
|
28
|
+
s.dependency 'OneSignalXCFramework/OneSignalInAppMessages', onesignal_xcframework_version
|
|
29
|
+
else
|
|
30
|
+
s.dependency 'OneSignalXCFramework', onesignal_xcframework_version
|
|
31
|
+
end
|
|
24
32
|
end
|
package/Package.swift
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
// swift-tools-version: 5.9
|
|
2
2
|
|
|
3
3
|
import PackageDescription
|
|
4
|
+
import Foundation
|
|
5
|
+
|
|
6
|
+
func oneSignalEnvFlag(_ name: String) -> Bool {
|
|
7
|
+
let value = Context.environment[name]?.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
|
|
8
|
+
return value == "true" || value == "1"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let oneSignalDisableLocation = oneSignalEnvFlag("ONESIGNAL_DISABLE_LOCATION")
|
|
12
|
+
|
|
13
|
+
// InAppMessages, Location, and Extension are separate library products in
|
|
14
|
+
// OneSignal-XCFramework and must be linked explicitly under SPM. Location can
|
|
15
|
+
// be omitted for apps that do not use OneSignal.Location.
|
|
16
|
+
var oneSignalDependencies: [Target.Dependency] = [
|
|
17
|
+
.product(name: "OneSignalFramework", package: "OneSignal-XCFramework"),
|
|
18
|
+
.product(name: "OneSignalInAppMessages", package: "OneSignal-XCFramework"),
|
|
19
|
+
.product(name: "OneSignalExtension", package: "OneSignal-XCFramework"),
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
if !oneSignalDisableLocation {
|
|
23
|
+
oneSignalDependencies.append(.product(name: "OneSignalLocation", package: "OneSignal-XCFramework"))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var capacitorPluginDependencies: [Target.Dependency] = [
|
|
27
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
28
|
+
.product(name: "Cordova", package: "capacitor-swift-pm"),
|
|
29
|
+
]
|
|
30
|
+
capacitorPluginDependencies.append(contentsOf: oneSignalDependencies)
|
|
31
|
+
capacitorPluginDependencies.append("OSCapacitorLaunchOptions")
|
|
4
32
|
|
|
5
33
|
let package = Package(
|
|
6
34
|
name: "OnesignalCapacitorPlugin",
|
|
@@ -28,19 +56,7 @@ let package = Package(
|
|
|
28
56
|
),
|
|
29
57
|
.target(
|
|
30
58
|
name: "OnesignalCapacitorPlugin",
|
|
31
|
-
dependencies:
|
|
32
|
-
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
33
|
-
.product(name: "Cordova", package: "capacitor-swift-pm"),
|
|
34
|
-
// InAppMessages and Location are separate library products in
|
|
35
|
-
// OneSignal-XCFramework and must be linked explicitly under SPM,
|
|
36
|
-
// otherwise their xcframeworks aren't loaded and the namespaces
|
|
37
|
-
// are silent no-ops at runtime.
|
|
38
|
-
.product(name: "OneSignalFramework", package: "OneSignal-XCFramework"),
|
|
39
|
-
.product(name: "OneSignalInAppMessages", package: "OneSignal-XCFramework"),
|
|
40
|
-
.product(name: "OneSignalLocation", package: "OneSignal-XCFramework"),
|
|
41
|
-
.product(name: "OneSignalExtension", package: "OneSignal-XCFramework"),
|
|
42
|
-
"OSCapacitorLaunchOptions"
|
|
43
|
-
],
|
|
59
|
+
dependencies: capacitorPluginDependencies,
|
|
44
60
|
path: "ios/Sources/OneSignalCapacitorPlugin"
|
|
45
61
|
)
|
|
46
62
|
]
|
package/README.md
CHANGED
|
@@ -4,11 +4,93 @@ The pure [Capacitor](https://capacitorjs.com/) plugin for [OneSignal](https://on
|
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
+
Install with your package manager of choice:
|
|
8
|
+
|
|
7
9
|
```bash
|
|
10
|
+
# with vp
|
|
11
|
+
vp add @onesignal/capacitor-plugin
|
|
12
|
+
|
|
13
|
+
# with bun
|
|
14
|
+
bun add @onesignal/capacitor-plugin
|
|
15
|
+
|
|
16
|
+
# with npm
|
|
8
17
|
npm install @onesignal/capacitor-plugin
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then sync Capacitor:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# with vp
|
|
24
|
+
vpx cap sync
|
|
25
|
+
|
|
26
|
+
# with bun
|
|
27
|
+
bunx cap sync
|
|
28
|
+
|
|
29
|
+
# with npm
|
|
9
30
|
npx cap sync
|
|
10
31
|
```
|
|
11
32
|
|
|
33
|
+
## Disabling OneSignal Location
|
|
34
|
+
|
|
35
|
+
If your app does not use `OneSignal.Location`, you can exclude the native OneSignal location module from iOS and Android builds.
|
|
36
|
+
|
|
37
|
+
Set `ONESIGNAL_DISABLE_LOCATION=true` in the environment before resolving or building native dependencies. The value is case-insensitive, and `1` is also accepted.
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
ONESIGNAL_DISABLE_LOCATION=true npx cap sync
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
For day-to-day native builds and runs, keep the same environment variable set so Capacitor, Swift Package Manager, CocoaPods, and Gradle do not re-resolve with the location module included:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
ONESIGNAL_DISABLE_LOCATION=true npx cap run ios
|
|
47
|
+
ONESIGNAL_DISABLE_LOCATION=true npx cap run android
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
In GitHub Actions, set it once at the job or step level so Swift Package Manager, CocoaPods, and Gradle builds inherit it:
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
env:
|
|
54
|
+
ONESIGNAL_DISABLE_LOCATION: true
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
With the location module disabled, calls to `OneSignal.Location` are ignored on Android and `OneSignal.Location.isShared()` resolves `false`.
|
|
58
|
+
|
|
59
|
+
### Applying the change
|
|
60
|
+
|
|
61
|
+
The environment variable is read when native dependencies are resolved. If you change the variable in an existing project, clear the relevant cache and re-resolve in a shell where the variable is exported.
|
|
62
|
+
|
|
63
|
+
> [!IMPORTANT]
|
|
64
|
+
> When using Xcode or Android Studio, launch the IDE from a terminal that has `ONESIGNAL_DISABLE_LOCATION` exported. An IDE launched from the Dock/Finder does not inherit variables set only in your shell profile.
|
|
65
|
+
|
|
66
|
+
Swift Package Manager:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
rm -rf ~/Library/Caches/org.swift.swiftpm ~/Library/Developer/Xcode/DerivedData/*
|
|
70
|
+
ONESIGNAL_DISABLE_LOCATION=true npx cap sync ios
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
In Xcode, you can instead use **File -> Packages -> Reset Package Caches** with the variable exported, then build.
|
|
74
|
+
|
|
75
|
+
CocoaPods:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
cd ios/App
|
|
79
|
+
pod deintegrate
|
|
80
|
+
rm -rf Pods Podfile.lock
|
|
81
|
+
ONESIGNAL_DISABLE_LOCATION=true pod install
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Android Gradle, which re-reads the variable on each configuration:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
ONESIGNAL_DISABLE_LOCATION=true npx cap sync android
|
|
88
|
+
cd android
|
|
89
|
+
ONESIGNAL_DISABLE_LOCATION=true ./gradlew assembleDebug
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
On CI, key any DerivedData, SwiftPM, CocoaPods, or Gradle caches on the value of `ONESIGNAL_DISABLE_LOCATION` so a restored cache does not resurrect the location module.
|
|
93
|
+
|
|
12
94
|
## Usage
|
|
13
95
|
|
|
14
96
|
```ts
|
|
@@ -24,13 +106,13 @@ See the `examples/demo` directory for a full working example.
|
|
|
24
106
|
|
|
25
107
|
<docgen-index>
|
|
26
108
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
109
|
+
* [`initialize(...)`](#initialize)
|
|
110
|
+
* [`login(...)`](#login)
|
|
111
|
+
* [`logout()`](#logout)
|
|
112
|
+
* [`setConsentRequired(...)`](#setconsentrequired)
|
|
113
|
+
* [`setConsentGiven(...)`](#setconsentgiven)
|
|
114
|
+
* [Interfaces](#interfaces)
|
|
115
|
+
* [Type Aliases](#type-aliases)
|
|
34
116
|
|
|
35
117
|
</docgen-index>
|
|
36
118
|
|
|
@@ -51,7 +133,8 @@ Initialize the SDK with your OneSignal app ID. Call during app startup.
|
|
|
51
133
|
| ----------- | ------------------- |
|
|
52
134
|
| **`appId`** | <code>string</code> |
|
|
53
135
|
|
|
54
|
-
|
|
136
|
+
--------------------
|
|
137
|
+
|
|
55
138
|
|
|
56
139
|
### login(...)
|
|
57
140
|
|
|
@@ -65,7 +148,8 @@ Log in to OneSignal as the user identified by `externalId`, switching the user c
|
|
|
65
148
|
| ---------------- | ------------------- |
|
|
66
149
|
| **`externalId`** | <code>string</code> |
|
|
67
150
|
|
|
68
|
-
|
|
151
|
+
--------------------
|
|
152
|
+
|
|
69
153
|
|
|
70
154
|
### logout()
|
|
71
155
|
|
|
@@ -75,7 +159,8 @@ logout() => Promise<void>
|
|
|
75
159
|
|
|
76
160
|
Log out the current user. The SDK will reference a new device-scoped user.
|
|
77
161
|
|
|
78
|
-
|
|
162
|
+
--------------------
|
|
163
|
+
|
|
79
164
|
|
|
80
165
|
### setConsentRequired(...)
|
|
81
166
|
|
|
@@ -89,7 +174,8 @@ Set whether user privacy consent is required before sending data to OneSignal. C
|
|
|
89
174
|
| -------------- | -------------------- |
|
|
90
175
|
| **`required`** | <code>boolean</code> |
|
|
91
176
|
|
|
92
|
-
|
|
177
|
+
--------------------
|
|
178
|
+
|
|
93
179
|
|
|
94
180
|
### setConsentGiven(...)
|
|
95
181
|
|
|
@@ -103,10 +189,12 @@ Indicate whether the user has granted privacy consent.
|
|
|
103
189
|
| ------------- | -------------------- |
|
|
104
190
|
| **`granted`** | <code>boolean</code> |
|
|
105
191
|
|
|
106
|
-
|
|
192
|
+
--------------------
|
|
193
|
+
|
|
107
194
|
|
|
108
195
|
### Interfaces
|
|
109
196
|
|
|
197
|
+
|
|
110
198
|
#### OneSignalDebugAPI
|
|
111
199
|
|
|
112
200
|
Debug helpers exposed via `OneSignal.Debug`.
|
|
@@ -116,6 +204,7 @@ Debug helpers exposed via `OneSignal.Debug`.
|
|
|
116
204
|
| **setLogLevel** | (logLevel: <a href="#loglevel">LogLevel</a>) => void | Set the log level printed to LogCat (Android) or the Xcode console (iOS). |
|
|
117
205
|
| **setAlertLevel** | (visualLogLevel: <a href="#loglevel">LogLevel</a>) => void | Set the log level shown to the user as alert dialogs. |
|
|
118
206
|
|
|
207
|
+
|
|
119
208
|
#### OneSignalUserAPI
|
|
120
209
|
|
|
121
210
|
Current-user operations exposed via `OneSignal.User`.
|
|
@@ -146,12 +235,14 @@ Current-user operations exposed via `OneSignal.User`.
|
|
|
146
235
|
| **getExternalId** | () => Promise<string \| null> | Get the external ID set via `login`, or null if the user is anonymous. |
|
|
147
236
|
| **trackEvent** | (name: string, properties?: object \| undefined) => Promise<void> | Track a custom event with an optional set of JSON-serializable properties. |
|
|
148
237
|
|
|
238
|
+
|
|
149
239
|
#### UserChangedState
|
|
150
240
|
|
|
151
241
|
| Prop | Type |
|
|
152
242
|
| ------------- | ----------------------------------------------- |
|
|
153
243
|
| **`current`** | <code><a href="#userstate">UserState</a></code> |
|
|
154
244
|
|
|
245
|
+
|
|
155
246
|
#### UserState
|
|
156
247
|
|
|
157
248
|
| Prop | Type |
|
|
@@ -159,6 +250,7 @@ Current-user operations exposed via `OneSignal.User`.
|
|
|
159
250
|
| **`onesignalId`** | <code>string</code> |
|
|
160
251
|
| **`externalId`** | <code>string</code> |
|
|
161
252
|
|
|
253
|
+
|
|
162
254
|
#### OneSignalPushSubscriptionAPI
|
|
163
255
|
|
|
164
256
|
Push subscription state and controls exposed via `OneSignal.User.pushSubscription`.
|
|
@@ -173,6 +265,7 @@ Push subscription state and controls exposed via `OneSignal.User.pushSubscriptio
|
|
|
173
265
|
| **optIn** | () => Promise<void> | Opt the user in to push notifications. Prompts for permission if needed. |
|
|
174
266
|
| **optOut** | () => Promise<void> | Opt the user out of push notifications on this device. |
|
|
175
267
|
|
|
268
|
+
|
|
176
269
|
#### PushSubscriptionChangedState
|
|
177
270
|
|
|
178
271
|
| Prop | Type |
|
|
@@ -180,6 +273,7 @@ Push subscription state and controls exposed via `OneSignal.User.pushSubscriptio
|
|
|
180
273
|
| **`previous`** | <code><a href="#pushsubscriptionstate">PushSubscriptionState</a></code> |
|
|
181
274
|
| **`current`** | <code><a href="#pushsubscriptionstate">PushSubscriptionState</a></code> |
|
|
182
275
|
|
|
276
|
+
|
|
183
277
|
#### PushSubscriptionState
|
|
184
278
|
|
|
185
279
|
| Prop | Type |
|
|
@@ -188,6 +282,7 @@ Push subscription state and controls exposed via `OneSignal.User.pushSubscriptio
|
|
|
188
282
|
| **`token`** | <code>string</code> |
|
|
189
283
|
| **`optedIn`** | <code>boolean</code> |
|
|
190
284
|
|
|
285
|
+
|
|
191
286
|
#### OneSignalNotificationsAPI
|
|
192
287
|
|
|
193
288
|
Notification permission and event handling exposed via `OneSignal.Notifications`.
|
|
@@ -205,6 +300,7 @@ Notification permission and event handling exposed via `OneSignal.Notifications`
|
|
|
205
300
|
| **removeNotification** | (id: number) => Promise<void> | Android only. Cancel a single notification by its Android notification ID. |
|
|
206
301
|
| **removeGroupedNotifications** | (id: string) => Promise<void> | Android only. Cancel a group of notifications by group key. |
|
|
207
302
|
|
|
303
|
+
|
|
208
304
|
#### NotificationClickEvent
|
|
209
305
|
|
|
210
306
|
| Prop | Type |
|
|
@@ -212,6 +308,7 @@ Notification permission and event handling exposed via `OneSignal.Notifications`
|
|
|
212
308
|
| **`result`** | <code><a href="#notificationclickresult">NotificationClickResult</a></code> |
|
|
213
309
|
| **`notification`** | <code>OSNotification</code> |
|
|
214
310
|
|
|
311
|
+
|
|
215
312
|
#### NotificationClickResult
|
|
216
313
|
|
|
217
314
|
| Prop | Type |
|
|
@@ -219,6 +316,7 @@ Notification permission and event handling exposed via `OneSignal.Notifications`
|
|
|
219
316
|
| **`actionId`** | <code>string</code> |
|
|
220
317
|
| **`url`** | <code>string</code> |
|
|
221
318
|
|
|
319
|
+
|
|
222
320
|
#### OneSignalInAppMessagesAPI
|
|
223
321
|
|
|
224
322
|
In-app message triggers and event handling exposed via `OneSignal.InAppMessages`.
|
|
@@ -235,6 +333,7 @@ In-app message triggers and event handling exposed via `OneSignal.InAppMessages`
|
|
|
235
333
|
| **setPaused** | (pause: boolean) => void | Pause or resume the display of in-app messages. |
|
|
236
334
|
| **getPaused** | () => Promise<boolean> | Whether in-app messaging is currently paused. |
|
|
237
335
|
|
|
336
|
+
|
|
238
337
|
#### InAppMessageClickEvent
|
|
239
338
|
|
|
240
339
|
| Prop | Type |
|
|
@@ -242,12 +341,14 @@ In-app message triggers and event handling exposed via `OneSignal.InAppMessages`
|
|
|
242
341
|
| **`message`** | <code><a href="#osinappmessage">OSInAppMessage</a></code> |
|
|
243
342
|
| **`result`** | <code><a href="#inappmessageclickresult">InAppMessageClickResult</a></code> |
|
|
244
343
|
|
|
344
|
+
|
|
245
345
|
#### OSInAppMessage
|
|
246
346
|
|
|
247
347
|
| Prop | Type |
|
|
248
348
|
| --------------- | ------------------- |
|
|
249
349
|
| **`messageId`** | <code>string</code> |
|
|
250
350
|
|
|
351
|
+
|
|
251
352
|
#### InAppMessageClickResult
|
|
252
353
|
|
|
253
354
|
| Prop | Type |
|
|
@@ -257,30 +358,35 @@ In-app message triggers and event handling exposed via `OneSignal.InAppMessages`
|
|
|
257
358
|
| **`url`** | <code>string</code> |
|
|
258
359
|
| **`urlTarget`** | <code><a href="#inappmessageactionurltype">InAppMessageActionUrlType</a></code> |
|
|
259
360
|
|
|
361
|
+
|
|
260
362
|
#### InAppMessageWillDisplayEvent
|
|
261
363
|
|
|
262
364
|
| Prop | Type |
|
|
263
365
|
| ------------- | --------------------------------------------------------- |
|
|
264
366
|
| **`message`** | <code><a href="#osinappmessage">OSInAppMessage</a></code> |
|
|
265
367
|
|
|
368
|
+
|
|
266
369
|
#### InAppMessageDidDisplayEvent
|
|
267
370
|
|
|
268
371
|
| Prop | Type |
|
|
269
372
|
| ------------- | --------------------------------------------------------- |
|
|
270
373
|
| **`message`** | <code><a href="#osinappmessage">OSInAppMessage</a></code> |
|
|
271
374
|
|
|
375
|
+
|
|
272
376
|
#### InAppMessageWillDismissEvent
|
|
273
377
|
|
|
274
378
|
| Prop | Type |
|
|
275
379
|
| ------------- | --------------------------------------------------------- |
|
|
276
380
|
| **`message`** | <code><a href="#osinappmessage">OSInAppMessage</a></code> |
|
|
277
381
|
|
|
382
|
+
|
|
278
383
|
#### InAppMessageDidDismissEvent
|
|
279
384
|
|
|
280
385
|
| Prop | Type |
|
|
281
386
|
| ------------- | --------------------------------------------------------- |
|
|
282
387
|
| **`message`** | <code><a href="#osinappmessage">OSInAppMessage</a></code> |
|
|
283
388
|
|
|
389
|
+
|
|
284
390
|
#### OneSignalSessionAPI
|
|
285
391
|
|
|
286
392
|
Outcome reporting exposed via `OneSignal.Session`.
|
|
@@ -291,6 +397,7 @@ Outcome reporting exposed via `OneSignal.Session`.
|
|
|
291
397
|
| **addUniqueOutcome** | (name: string) => Promise<void> | <a href="#record">Record</a> a unique outcome with the given name against the current session. |
|
|
292
398
|
| **addOutcomeWithValue** | (name: string, value: number) => Promise<void> | <a href="#record">Record</a> an outcome with the given name and value against the current session. |
|
|
293
399
|
|
|
400
|
+
|
|
294
401
|
#### OneSignalLocationAPI
|
|
295
402
|
|
|
296
403
|
Location permission and sharing exposed via `OneSignal.Location`.
|
|
@@ -301,6 +408,7 @@ Location permission and sharing exposed via `OneSignal.Location`.
|
|
|
301
408
|
| **setShared** | (shared: boolean) => void | Enable or disable sharing the device location with OneSignal. |
|
|
302
409
|
| **isShared** | () => Promise<boolean> | Whether the device location is currently shared with OneSignal. |
|
|
303
410
|
|
|
411
|
+
|
|
304
412
|
#### OneSignalLiveActivitiesAPI
|
|
305
413
|
|
|
306
414
|
Live activity controls exposed via `OneSignal.LiveActivities`. iOS only unless noted.
|
|
@@ -314,48 +422,56 @@ Live activity controls exposed via `OneSignal.LiveActivities`. iOS only unless n
|
|
|
314
422
|
| **setupDefault** | (options?: <a href="#liveactivitysetupoptions">LiveActivitySetupOptions</a> \| undefined) => Promise<void> | Set up the OneSignal default live activity, optionally enabling pushToStart/pushToUpdate. |
|
|
315
423
|
| **startDefault** | (activityId: string, attributes: <a href="#record">Record</a><string, unknown>, content: <a href="#record">Record</a><string, unknown>) => Promise<void> | Start a live activity backed by the OneSignal default attributes type. |
|
|
316
424
|
|
|
425
|
+
|
|
317
426
|
### Type Aliases
|
|
318
427
|
|
|
428
|
+
|
|
319
429
|
#### LogLevel
|
|
320
430
|
|
|
321
431
|
<code>(typeof <a href="#loglevel">LogLevel</a>)[keyof typeof LogLevel]</code>
|
|
322
432
|
|
|
433
|
+
|
|
323
434
|
#### Record
|
|
324
435
|
|
|
325
436
|
Construct a type with a set of properties K of type T
|
|
326
437
|
|
|
327
|
-
<code>{
|
|
328
|
-
[P in K]: T;
|
|
329
|
-
}</code>
|
|
438
|
+
<code>{
|
|
330
439
|
[P in K]: T;
|
|
331
440
|
}</code>
|
|
441
|
+
|
|
332
442
|
|
|
333
443
|
#### OSNotificationPermission
|
|
334
444
|
|
|
335
445
|
<code>(typeof <a href="#osnotificationpermission">OSNotificationPermission</a>)[keyof typeof OSNotificationPermission]</code>
|
|
336
446
|
|
|
447
|
+
|
|
337
448
|
#### NotificationEventName
|
|
338
449
|
|
|
339
450
|
<code>'click' | 'foregroundWillDisplay' | 'permissionChange'</code>
|
|
340
451
|
|
|
452
|
+
|
|
341
453
|
#### NotificationEventTypeMap
|
|
342
454
|
|
|
343
455
|
<code>{ click: <a href="#notificationclickevent">NotificationClickEvent</a>; foregroundWillDisplay: NotificationWillDisplayEvent; permissionChange: boolean; }</code>
|
|
344
456
|
|
|
457
|
+
|
|
345
458
|
#### InAppMessageEventName
|
|
346
459
|
|
|
347
460
|
<code>'click' | 'willDisplay' | 'didDisplay' | 'willDismiss' | 'didDismiss'</code>
|
|
348
461
|
|
|
462
|
+
|
|
349
463
|
#### InAppMessageEventTypeMap
|
|
350
464
|
|
|
351
465
|
<code>{ click: <a href="#inappmessageclickevent">InAppMessageClickEvent</a>; willDisplay: <a href="#inappmessagewilldisplayevent">InAppMessageWillDisplayEvent</a>; didDisplay: <a href="#inappmessagediddisplayevent">InAppMessageDidDisplayEvent</a>; willDismiss: <a href="#inappmessagewilldismissevent">InAppMessageWillDismissEvent</a>; didDismiss: <a href="#inappmessagediddismissevent">InAppMessageDidDismissEvent</a>; }</code>
|
|
352
466
|
|
|
467
|
+
|
|
353
468
|
#### InAppMessageActionUrlType
|
|
354
469
|
|
|
355
470
|
<code>'browser' | 'webview' | 'replacement'</code>
|
|
356
471
|
|
|
472
|
+
|
|
357
473
|
#### LiveActivitySetupOptions
|
|
358
474
|
|
|
359
475
|
The setup options for `OneSignal.LiveActivities.setupDefault`.
|
|
360
476
|
|
|
361
|
-
<code>{ /**
|
|
477
|
+
<code>{ /** * When true, OneSignal will listen for pushToStart tokens for the `OneSignalLiveActivityAttributes` structure. */ enablePushToStart: boolean; /** * When true, OneSignal will listen for pushToUpdate tokens for each start live activity that uses the * `OneSignalLiveActivityAttributes` structure. */ enablePushToUpdate: boolean; }</code>
|
|
362
478
|
|
|
363
479
|
</docgen-api>
|
package/android/build.gradle.kts
CHANGED
|
@@ -84,8 +84,16 @@ fun propertyOrCatalog(propertyName: String, catalogKey: String): String =
|
|
|
84
84
|
fun intPropertyOrCatalog(propertyName: String, catalogKey: String): Int =
|
|
85
85
|
project.findProperty(propertyName)?.toString()?.toInt() ?: catalogVersion(catalogKey).toInt()
|
|
86
86
|
|
|
87
|
+
fun envFlag(envName: String): Boolean {
|
|
88
|
+
val value = System.getenv(envName)
|
|
89
|
+
val normalizedValue = value?.trim()
|
|
90
|
+
return normalizedValue.equals("true", ignoreCase = true) || normalizedValue == "1"
|
|
91
|
+
}
|
|
92
|
+
|
|
87
93
|
val junitVersion: String = propertyOrCatalog("junitVersion", "junit")
|
|
88
94
|
val androidxAppCompatVersion: String = propertyOrCatalog("androidxAppCompatVersion", "androidxAppCompat")
|
|
95
|
+
val oneSignalVersion: String = catalogVersion("onesignal")
|
|
96
|
+
val oneSignalDisableLocation: Boolean = envFlag("ONESIGNAL_DISABLE_LOCATION")
|
|
89
97
|
|
|
90
98
|
extra["junitVersion"] = junitVersion
|
|
91
99
|
extra["androidxAppCompatVersion"] = androidxAppCompatVersion
|
|
@@ -126,7 +134,13 @@ repositories {
|
|
|
126
134
|
dependencies {
|
|
127
135
|
"implementation"(project(":capacitor-android"))
|
|
128
136
|
"implementation"("androidx.appcompat:appcompat:$androidxAppCompatVersion")
|
|
129
|
-
|
|
137
|
+
if (oneSignalDisableLocation) {
|
|
138
|
+
"implementation"("com.onesignal:core:$oneSignalVersion")
|
|
139
|
+
"implementation"("com.onesignal:notifications:$oneSignalVersion")
|
|
140
|
+
"implementation"("com.onesignal:in-app-messages:$oneSignalVersion")
|
|
141
|
+
} else {
|
|
142
|
+
"implementation"("com.onesignal:OneSignal:$oneSignalVersion")
|
|
143
|
+
}
|
|
130
144
|
"testImplementation"("junit:junit:$junitVersion")
|
|
131
145
|
"androidTestImplementation"("androidx.test.ext:junit:${catalogVersion("androidxTestJunit")}")
|
|
132
146
|
"androidTestImplementation"("androidx.test.espresso:espresso-core:${catalogVersion("androidxEspresso")}")
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
package com.onesignal.capacitor
|
|
2
2
|
|
|
3
|
-
import android.app.Application
|
|
4
3
|
import com.getcapacitor.JSObject
|
|
5
4
|
import com.getcapacitor.Plugin
|
|
6
5
|
import com.getcapacitor.PluginCall
|
|
@@ -8,7 +7,7 @@ import com.getcapacitor.PluginMethod
|
|
|
8
7
|
import com.getcapacitor.annotation.CapacitorPlugin
|
|
9
8
|
import com.onesignal.OneSignal
|
|
10
9
|
import com.onesignal.common.OneSignalWrapper
|
|
11
|
-
import com.onesignal.
|
|
10
|
+
import com.onesignal.debug.internal.logging.Logging
|
|
12
11
|
import com.onesignal.inAppMessages.IInAppMessageClickEvent
|
|
13
12
|
import com.onesignal.inAppMessages.IInAppMessageClickListener
|
|
14
13
|
import com.onesignal.inAppMessages.IInAppMessageDidDismissEvent
|
|
@@ -26,6 +25,7 @@ import com.onesignal.user.state.IUserStateObserver
|
|
|
26
25
|
import com.onesignal.user.state.UserChangedState
|
|
27
26
|
import com.onesignal.user.subscriptions.IPushSubscriptionObserver
|
|
28
27
|
import com.onesignal.user.subscriptions.PushSubscriptionChangedState
|
|
28
|
+
import kotlinx.coroutines.CancellationException
|
|
29
29
|
import kotlinx.coroutines.MainScope
|
|
30
30
|
import kotlinx.coroutines.cancel
|
|
31
31
|
import kotlinx.coroutines.launch
|
|
@@ -46,6 +46,8 @@ class OneSignalCapacitorPlugin : Plugin(),
|
|
|
46
46
|
// provisional (3), and ephemeral (4) states do not apply here.
|
|
47
47
|
private const val PERMISSION_DENIED = 1
|
|
48
48
|
private const val PERMISSION_AUTHORIZED = 2
|
|
49
|
+
private const val LOCATION_CALL_FAILED =
|
|
50
|
+
"OneSignal.Location call failed. The location module may not be included in this build."
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
private val notificationWillDisplayCache = mutableMapOf<String, INotificationWillDisplayEvent>()
|
|
@@ -58,6 +60,10 @@ class OneSignalCapacitorPlugin : Plugin(),
|
|
|
58
60
|
// call into the dead Capacitor bridge.
|
|
59
61
|
private val pluginScope = MainScope()
|
|
60
62
|
|
|
63
|
+
private fun logLocationCallFailed(throwable: Throwable) {
|
|
64
|
+
Logging.error(LOCATION_CALL_FAILED, throwable)
|
|
65
|
+
}
|
|
66
|
+
|
|
61
67
|
private val permissionObserver = object : IPermissionObserver {
|
|
62
68
|
override fun onNotificationPermissionChange(permission: Boolean) {
|
|
63
69
|
val ret = JSObject()
|
|
@@ -134,14 +140,9 @@ class OneSignalCapacitorPlugin : Plugin(),
|
|
|
134
140
|
initialized = true
|
|
135
141
|
|
|
136
142
|
OneSignalWrapper.sdkType = "capacitor"
|
|
137
|
-
OneSignalWrapper.sdkVersion = "
|
|
143
|
+
OneSignalWrapper.sdkVersion = "010100"
|
|
138
144
|
OneSignal.initWithContext(context, appId)
|
|
139
145
|
|
|
140
|
-
// If the SDK was initialized from a non-Activity context (FCM/work
|
|
141
|
-
// managers) before this call, its ALC missed MainActivity.onResume
|
|
142
|
-
// and isInForeground stays false. Forward the missed events now.
|
|
143
|
-
nudgeApplicationServiceForeground()
|
|
144
|
-
|
|
145
146
|
OneSignal.Notifications.addPermissionObserver(permissionObserver)
|
|
146
147
|
OneSignal.Notifications.addForegroundLifecycleListener(this)
|
|
147
148
|
OneSignal.Notifications.addClickListener(this)
|
|
@@ -153,17 +154,6 @@ class OneSignalCapacitorPlugin : Plugin(),
|
|
|
153
154
|
call.resolve()
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
/** Forward the missed activity-resume to the SDK so isInForeground is
|
|
157
|
-
* correct on cold start. No-op if the SDK already saw the resume. */
|
|
158
|
-
private fun nudgeApplicationServiceForeground() {
|
|
159
|
-
val activity = activity ?: return
|
|
160
|
-
val appSvc = runCatching { OneSignal.getServiceOrNull<IApplicationService>() }.getOrNull() ?: return
|
|
161
|
-
if (appSvc.isInForeground && appSvc.current === activity) return
|
|
162
|
-
val callbacks = appSvc as? Application.ActivityLifecycleCallbacks ?: return
|
|
163
|
-
callbacks.onActivityStarted(activity)
|
|
164
|
-
callbacks.onActivityResumed(activity)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
157
|
private fun buildClickEventJson(event: INotificationClickEvent): JSObject {
|
|
168
158
|
val ret = JSObject()
|
|
169
159
|
val clickResult = JSObject()
|
|
@@ -658,7 +648,13 @@ class OneSignalCapacitorPlugin : Plugin(),
|
|
|
658
648
|
@PluginMethod
|
|
659
649
|
fun requestLocationPermission(call: PluginCall) {
|
|
660
650
|
pluginScope.launch {
|
|
661
|
-
|
|
651
|
+
try {
|
|
652
|
+
OneSignal.Location.requestPermission()
|
|
653
|
+
} catch (e: CancellationException) {
|
|
654
|
+
throw e
|
|
655
|
+
} catch (t: Throwable) {
|
|
656
|
+
logLocationCallFailed(t)
|
|
657
|
+
}
|
|
662
658
|
call.resolve()
|
|
663
659
|
}
|
|
664
660
|
}
|
|
@@ -666,14 +662,23 @@ class OneSignalCapacitorPlugin : Plugin(),
|
|
|
666
662
|
@PluginMethod
|
|
667
663
|
fun setLocationShared(call: PluginCall) {
|
|
668
664
|
val shared = call.getBoolean("shared") ?: false
|
|
669
|
-
|
|
665
|
+
try {
|
|
666
|
+
OneSignal.Location.isShared = shared
|
|
667
|
+
} catch (t: Throwable) {
|
|
668
|
+
logLocationCallFailed(t)
|
|
669
|
+
}
|
|
670
670
|
call.resolve()
|
|
671
671
|
}
|
|
672
672
|
|
|
673
673
|
@PluginMethod
|
|
674
674
|
fun isLocationShared(call: PluginCall) {
|
|
675
675
|
val ret = JSObject()
|
|
676
|
-
|
|
676
|
+
try {
|
|
677
|
+
ret.put("shared", OneSignal.Location.isShared)
|
|
678
|
+
} catch (t: Throwable) {
|
|
679
|
+
logLocationCallFailed(t)
|
|
680
|
+
ret.put("shared", false)
|
|
681
|
+
}
|
|
677
682
|
call.resolve(ret)
|
|
678
683
|
}
|
|
679
684
|
|
|
@@ -110,7 +110,7 @@ public class OneSignalCapacitorPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
110
110
|
initialized = true
|
|
111
111
|
|
|
112
112
|
OneSignalWrapper.sdkType = "capacitor"
|
|
113
|
-
OneSignalWrapper.sdkVersion = "
|
|
113
|
+
OneSignalWrapper.sdkVersion = "010100"
|
|
114
114
|
// OSCapacitorLaunchOptions's +load captures the dictionary from
|
|
115
115
|
// UIApplicationDidFinishLaunchingNotification at process start (before
|
|
116
116
|
// main()), so cold-start notification taps that arrive via launchOptions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onesignal/capacitor-plugin",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "OneSignal is a high volume Push Notification service for mobile apps. This is the pure Capacitor plugin for OneSignal, providing push notifications, in-app messaging, and more.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apns",
|