Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Resolve OneSignal Android SDK version
id: android-sdk-version
run: |
VERSION=$(grep "com.onesignal:OneSignal:" android/build.gradle | sed -E "s/.*OneSignal:([^\"']+).*/\1/")
VERSION=$(grep "def oneSignalVersion =" android/build.gradle | sed -E "s/.*= ['\"]([^'\"]+)['\"].*/\1/")
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Wait for OneSignal Android SDK on Maven Central
Expand Down
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,39 @@ See the [Setup Guide](https://documentation.onesignal.com/docs/react-native-sdk-

By default, `react-native-onesignal` includes OneSignal's native location module so `OneSignal.Location` works without extra setup. If your app does not use location features, you can exclude the native location module from iOS and Android builds.

In your iOS `Podfile`, set this before React Native installs native modules:
Set `ONESIGNAL_DISABLE_LOCATION=true` in the environment before resolving or building, for both CocoaPods (iOS) and Gradle (Android):

```ruby
$OneSignalDisableLocation = true
```sh
ONESIGNAL_DISABLE_LOCATION=true pod install # iOS, from the ios directory
ONESIGNAL_DISABLE_LOCATION=true ./gradlew assembleDebug # Android, from the android directory
```

In your Android `gradle.properties`, set:
In GitHub Actions, you can also set it once at the job or step level so
`pod install`, `pod update`, and Gradle builds inherit it:

```properties
OneSignal_disableLocation=true
```yaml
env:
ONESIGNAL_DISABLE_LOCATION: true
```

When disabled, `OneSignal.Location.requestPermission()` and `OneSignal.Location.setShared()` no-op on native builds without the location module, and `OneSignal.Location.isShared()` resolves `false`.

##### Applying the change (clearing cached pods)

The environment variable is only read when dependencies are **resolved**. CocoaPods pins the resolved pods in `Podfile.lock`, so after changing the variable on an existing project you must reinstall pods in a shell where the variable is exported:

```sh
cd ios
pod deintegrate
rm -rf Pods Podfile.lock
ONESIGNAL_DISABLE_LOCATION=true pod install
```

Gradle re-reads the variable on each configuration, so a clean build with the variable set is enough on Android.

> [!IMPORTANT]
> 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. On CI, key any CocoaPods / Gradle caches on the value of `ONESIGNAL_DISABLE_LOCATION` so a restored cache does not resurrect the location module.

#### Change Log

See this repository's [release tags](https://github.com/OneSignal/react-native-onesignal/releases) for a complete change log of every released version.
Expand Down
12 changes: 4 additions & 8 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def safePropGet(prop, fallback) {
if (rootProject.ext.has(prop)) {
return rootProject.ext.get(prop)
}

def value = rootProject.findProperty(prop)
return value != null ? value : fallback
def safeEnvFlagGet(prop) {
def value = System.getenv(prop)
return value != null && value.toString().toBoolean()
}

def oneSignalVersion = '5.9.3'
def oneSignalDisableLocation = safePropGet('OneSignal_disableLocation', false).toString().toBoolean()
def oneSignalDisableLocation = safeEnvFlagGet('ONESIGNAL_DISABLE_LOCATION')

android {
namespace "com.onesignal.rnonesignalandroid"
Expand Down
24 changes: 17 additions & 7 deletions examples/demo-no-location/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,34 @@ vp run ios
vp run android
```

Both platforms exclude the native location module by setting the
`ONESIGNAL_DISABLE_LOCATION=true` environment variable when dependencies are
resolved.

## iOS

The CocoaPods flag is set before `use_native_modules!` installs React Native pods:
The `pods` and `update:pods` scripts in `package.json` export the variable so
CocoaPods resolves OneSignal without the location subspec:

```ruby
$OneSignalDisableLocation = true
```sh
ONESIGNAL_DISABLE_LOCATION=true bundle exec pod install
```

See `ios/Podfile`.
If you run `pod install` or `pod update` manually, set
`ONESIGNAL_DISABLE_LOCATION=true` in that shell too.

## Android

The Gradle property is set in `android/gradle.properties`:
The `android` script in `package.json` exports the variable so Gradle resolves
OneSignal without the location module:

```properties
OneSignal_disableLocation=true
```sh
ONESIGNAL_DISABLE_LOCATION=true bash ../run-android.sh
```

If you build Android another way (Android Studio, a raw `./gradlew` invocation),
set `ONESIGNAL_DISABLE_LOCATION=true` in that environment too.

## App Code

`App.tsx` initializes OneSignal and requests notification permission without calling the `OneSignal.Location` namespace. With the native flags enabled, the build excludes the native OneSignal location module.

This file was deleted.

This file was deleted.

Binary file not shown.
3 changes: 0 additions & 3 deletions examples/demo-no-location/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,3 @@ hermesEnabled=true
# This allows your app to draw behind system bars for an immersive UI.
# Note: Only works with ReactActivity and should not be used with custom Activity.
edgeToEdgeEnabled=false

# Exclude OneSignal's native location module from Android builds.
OneSignal_disableLocation=true
4 changes: 2 additions & 2 deletions examples/demo-no-location/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/demo-no-location/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$OneSignalDisableLocation = true
# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
'require.resolve(
Expand Down
4 changes: 2 additions & 2 deletions examples/demo-no-location/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,6 @@ SPEC CHECKSUMS:
ReactNativeDependencies: 247df240f5ecafe765afbfba15da0a8daa4a2985
Yoga: 772166513f9cd2d61a6251d0dacbbfaa5b537479

PODFILE CHECKSUM: c3ac62d933cd818342aa59fcf882cd94a6cd1af2
PODFILE CHECKSUM: f3189232211372e657ece2d9f66c621325fb421a

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
4 changes: 0 additions & 4 deletions examples/demo-no-location/ios/demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
5F8F7D5C84F8947D278D5B06 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */; };
761780ED2CA45674006654EE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 761780EC2CA45674006654EE /* AppDelegate.swift */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
B10000000000000000000001 /* vine_boom.wav in Resources */ = {isa = PBXBuildFile; fileRef = B20000000000000000000001 /* vine_boom.wav */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -55,7 +54,6 @@
A2000000000000000000000F /* libPods-OneSignalNotificationServiceExtension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OneSignalNotificationServiceExtension.a"; sourceTree = BUILT_PRODUCTS_DIR; };
A20000000000000000000010 /* libPods-OneSignalWidgetExtension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OneSignalWidgetExtension.a"; sourceTree = BUILT_PRODUCTS_DIR; };
A20000000000000000000011 /* demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = demo.entitlements; path = demo/demo.entitlements; sourceTree = "<group>"; };
B20000000000000000000001 /* vine_boom.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = vine_boom.wav; path = demo/vine_boom.wav; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

Expand All @@ -80,7 +78,6 @@
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */,
A20000000000000000000011 /* demo.entitlements */,
B20000000000000000000001 /* vine_boom.wav */,
);
name = demo;
sourceTree = "<group>";
Expand Down Expand Up @@ -234,7 +231,6 @@
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
5F8F7D5C84F8947D278D5B06 /* PrivacyInfo.xcprivacy in Resources */,
B10000000000000000000001 /* vine_boom.wav in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 3 additions & 3 deletions examples/demo-no-location/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"setup": "../setup.sh",
"preandroid": "vp run setup",
"preios": "vp run setup && vp run pods",
"android": "bash ../run-android.sh",
"android": "ONESIGNAL_DISABLE_LOCATION=true bash ../run-android.sh",
"ios": "bash ../run-ios.sh",
"pods": "bundle install && (cd ios && bundle exec pod install)",
"update:pods": "(cd ios && pod update OneSignalXCFramework --no-repo-update)",
"pods": "bundle install && (cd ios && ONESIGNAL_DISABLE_LOCATION=true bundle exec pod install)",
"update:pods": "(cd ios && ONESIGNAL_DISABLE_LOCATION=true pod update OneSignalXCFramework --no-repo-update)",
"clean:android": "rm -rf android/app/build android/app/.cxx android/build && adb uninstall com.onesignal.example >/dev/null 2>&1 || true",
"clean:ios": "rm -rf ios/build ios/Pods",
"start": "react-native start"
Expand Down
2 changes: 1 addition & 1 deletion react-native-onesignal.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'json'
package_json = JSON.parse(File.read('package.json'))
onesignal_xcframework_version = '5.5.2'
onesignal_disable_location = defined?($OneSignalDisableLocation) && $OneSignalDisableLocation == true
onesignal_disable_location = ENV['ONESIGNAL_DISABLE_LOCATION'] == 'true'

Pod::Spec.new do |s|
s.name = "react-native-onesignal"
Expand Down
Loading