@onesignal/capacitor-plugin 1.0.6 → 1.1.1
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 +82 -0
- 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 -4
- package/ios/Sources/OneSignalCapacitorPlugin/OneSignalCapacitorPlugin.swift +1 -1
- package/package.json +6 -6
|
@@ -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.3'
|
|
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
|
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")}")
|
|
@@ -7,6 +7,7 @@ import com.getcapacitor.PluginMethod
|
|
|
7
7
|
import com.getcapacitor.annotation.CapacitorPlugin
|
|
8
8
|
import com.onesignal.OneSignal
|
|
9
9
|
import com.onesignal.common.OneSignalWrapper
|
|
10
|
+
import com.onesignal.debug.internal.logging.Logging
|
|
10
11
|
import com.onesignal.inAppMessages.IInAppMessageClickEvent
|
|
11
12
|
import com.onesignal.inAppMessages.IInAppMessageClickListener
|
|
12
13
|
import com.onesignal.inAppMessages.IInAppMessageDidDismissEvent
|
|
@@ -24,6 +25,7 @@ import com.onesignal.user.state.IUserStateObserver
|
|
|
24
25
|
import com.onesignal.user.state.UserChangedState
|
|
25
26
|
import com.onesignal.user.subscriptions.IPushSubscriptionObserver
|
|
26
27
|
import com.onesignal.user.subscriptions.PushSubscriptionChangedState
|
|
28
|
+
import kotlinx.coroutines.CancellationException
|
|
27
29
|
import kotlinx.coroutines.MainScope
|
|
28
30
|
import kotlinx.coroutines.cancel
|
|
29
31
|
import kotlinx.coroutines.launch
|
|
@@ -44,6 +46,8 @@ class OneSignalCapacitorPlugin : Plugin(),
|
|
|
44
46
|
// provisional (3), and ephemeral (4) states do not apply here.
|
|
45
47
|
private const val PERMISSION_DENIED = 1
|
|
46
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."
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
private val notificationWillDisplayCache = mutableMapOf<String, INotificationWillDisplayEvent>()
|
|
@@ -56,6 +60,10 @@ class OneSignalCapacitorPlugin : Plugin(),
|
|
|
56
60
|
// call into the dead Capacitor bridge.
|
|
57
61
|
private val pluginScope = MainScope()
|
|
58
62
|
|
|
63
|
+
private fun logLocationCallFailed(throwable: Throwable) {
|
|
64
|
+
Logging.error(LOCATION_CALL_FAILED, throwable)
|
|
65
|
+
}
|
|
66
|
+
|
|
59
67
|
private val permissionObserver = object : IPermissionObserver {
|
|
60
68
|
override fun onNotificationPermissionChange(permission: Boolean) {
|
|
61
69
|
val ret = JSObject()
|
|
@@ -132,7 +140,7 @@ class OneSignalCapacitorPlugin : Plugin(),
|
|
|
132
140
|
initialized = true
|
|
133
141
|
|
|
134
142
|
OneSignalWrapper.sdkType = "capacitor"
|
|
135
|
-
OneSignalWrapper.sdkVersion = "
|
|
143
|
+
OneSignalWrapper.sdkVersion = "010101"
|
|
136
144
|
OneSignal.initWithContext(context, appId)
|
|
137
145
|
|
|
138
146
|
OneSignal.Notifications.addPermissionObserver(permissionObserver)
|
|
@@ -640,7 +648,13 @@ class OneSignalCapacitorPlugin : Plugin(),
|
|
|
640
648
|
@PluginMethod
|
|
641
649
|
fun requestLocationPermission(call: PluginCall) {
|
|
642
650
|
pluginScope.launch {
|
|
643
|
-
|
|
651
|
+
try {
|
|
652
|
+
OneSignal.Location.requestPermission()
|
|
653
|
+
} catch (e: CancellationException) {
|
|
654
|
+
throw e
|
|
655
|
+
} catch (t: Throwable) {
|
|
656
|
+
logLocationCallFailed(t)
|
|
657
|
+
}
|
|
644
658
|
call.resolve()
|
|
645
659
|
}
|
|
646
660
|
}
|
|
@@ -648,14 +662,23 @@ class OneSignalCapacitorPlugin : Plugin(),
|
|
|
648
662
|
@PluginMethod
|
|
649
663
|
fun setLocationShared(call: PluginCall) {
|
|
650
664
|
val shared = call.getBoolean("shared") ?: false
|
|
651
|
-
|
|
665
|
+
try {
|
|
666
|
+
OneSignal.Location.isShared = shared
|
|
667
|
+
} catch (t: Throwable) {
|
|
668
|
+
logLocationCallFailed(t)
|
|
669
|
+
}
|
|
652
670
|
call.resolve()
|
|
653
671
|
}
|
|
654
672
|
|
|
655
673
|
@PluginMethod
|
|
656
674
|
fun isLocationShared(call: PluginCall) {
|
|
657
675
|
val ret = JSObject()
|
|
658
|
-
|
|
676
|
+
try {
|
|
677
|
+
ret.put("shared", OneSignal.Location.isShared)
|
|
678
|
+
} catch (t: Throwable) {
|
|
679
|
+
logLocationCallFailed(t)
|
|
680
|
+
ret.put("shared", false)
|
|
681
|
+
}
|
|
659
682
|
call.resolve(ret)
|
|
660
683
|
}
|
|
661
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 = "010101"
|
|
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.
|
|
3
|
+
"version": "1.1.1",
|
|
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",
|
|
@@ -59,18 +59,18 @@
|
|
|
59
59
|
"@capacitor/core": "7.0.0",
|
|
60
60
|
"@capacitor/docgen": "^0.2.2",
|
|
61
61
|
"@types/bun": "latest",
|
|
62
|
-
"@vitest/coverage-v8": "^4.1.
|
|
62
|
+
"@vitest/coverage-v8": "^4.1.9",
|
|
63
63
|
"typescript": "^5.9.3",
|
|
64
|
-
"vite-plus": "0.1.
|
|
64
|
+
"vite-plus": "0.1.24"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"@capacitor/core": ">=7.0.0"
|
|
68
68
|
},
|
|
69
69
|
"overrides": {
|
|
70
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@0.1.
|
|
71
|
-
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.
|
|
70
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.1.24",
|
|
71
|
+
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.24"
|
|
72
72
|
},
|
|
73
|
-
"packageManager": "bun@1.3.
|
|
73
|
+
"packageManager": "bun@1.3.14",
|
|
74
74
|
"capacitor": {
|
|
75
75
|
"ios": {
|
|
76
76
|
"src": "ios"
|