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 @@ -51,7 +51,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
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,69 @@ If you run into any challenges or have concerns, please contact our support team
#### Installation
See the [Setup Guide](https://documentation.onesignal.com/docs/flutter-sdk-setup) for setup instructions.

#### Disabling OneSignal Location

If your app does not use `OneSignal.Location`, you can exclude the native OneSignal location module from iOS and Android builds.

For Swift Package Manager, CocoaPods, and Android Gradle builds, set
`ONESIGNAL_DISABLE_LOCATION=true` in the environment before resolving or
building. The value is case-insensitive, and `1` is also accepted.

In GitHub Actions, you can set it once at the job or step level so Swift Package
Manager, CocoaPods, and Gradle builds inherit it:

```yaml
env:
ONESIGNAL_DISABLE_LOCATION: true
```

With the location module disabled, calls to `OneSignal.Location` are ignored on Android and `OneSignal.Location.isShared()` returns `false`.

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

The environment variable is only read when dependencies are **resolved**, and
each platform caches the resolved set. If you change the variable on an existing
project, you must clear the relevant cache and re-resolve in a shell where the
variable is exported. Otherwise a stale build can keep (or drop) the location
module regardless of the new value.

> [!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.

Swift Package Manager:

```sh
flutter clean
rm -rf ios/.build
rm -rf ~/Library/Caches/org.swift.swiftpm ~/Library/Developer/Xcode/DerivedData/*
ONESIGNAL_DISABLE_LOCATION=true flutter build ios
```

In Xcode, you can instead use **File → Packages → Reset Package Caches** (with
the variable exported), then build.

CocoaPods:

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

Android Gradle (Gradle re-reads the variable on each configuration, so a clean
build is usually enough):

```sh
ONESIGNAL_DISABLE_LOCATION=true flutter build apk
```

On CI, key any DerivedData / SwiftPM / CocoaPods / Gradle caches on the value of
`ONESIGNAL_DISABLE_LOCATION` (or skip restoring them for no-location builds) so a
restored cache does not resurrect the location module.

#### Change Log
See this repository's [release tags](https://github.com/onesignal/onesignal-flutter-sdk/releases) for a complete change log of every released version.

Expand Down
17 changes: 16 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
group 'com.onesignal.flutter'
version '5.5.8'

def safeEnvFlagGet(prop) {
def value = System.getenv(prop)
def normalizedValue = value?.toString()?.trim()
return normalizedValue != null && (normalizedValue.equalsIgnoreCase('true') || normalizedValue == '1')
}

def oneSignalVersion = '5.9.3'
def oneSignalDisableLocation = safeEnvFlagGet('ONESIGNAL_DISABLE_LOCATION')

buildscript {
repositories {
google()
Expand Down Expand Up @@ -38,5 +47,11 @@ android {
}

dependencies {
implementation 'com.onesignal:OneSignal:5.9.3'
if (oneSignalDisableLocation) {
implementation "com.onesignal:core:${oneSignalVersion}"
implementation "com.onesignal:notifications:${oneSignalVersion}"
implementation "com.onesignal:in-app-messages:${oneSignalVersion}"
} else {
implementation "com.onesignal:OneSignal:${oneSignalVersion}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.onesignal.Continue;
import com.onesignal.OneSignal;
import com.onesignal.debug.internal.logging.Logging;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand All @@ -10,6 +11,8 @@

public class OneSignalLocation extends FlutterMessengerResponder implements MethodCallHandler {
private static OneSignalLocation sharedInstance;
private static final String LOCATION_MODULE_NOT_AVAILABLE =
"OneSignal location module is not available. Add the location dependency to use OneSignal.Location.";

public static OneSignalLocation getSharedInstance() {
if (sharedInstance == null) {
Expand Down Expand Up @@ -40,18 +43,38 @@ public void run() {
private void handleMethodCall(MethodCall call, Result result) {
if (call.method.contentEquals("OneSignal#requestPermission")) this.requestPermission(result);
else if (call.method.contentEquals("OneSignal#setShared")) this.setShared(call, result);
else if (call.method.contentEquals("OneSignal#isShared"))
replySuccess(result, OneSignal.getLocation().isShared());
else if (call.method.contentEquals("OneSignal#isShared")) this.isShared(result);
else replyNotImplemented(result);
}

private void logLocationModuleNotAvailable(Throwable throwable) {
Logging.error(LOCATION_MODULE_NOT_AVAILABLE, throwable);
}

private void requestPermission(Result reply) {
OneSignal.getLocation().requestPermission(Continue.none());
try {
OneSignal.getLocation().requestPermission(Continue.none());
} catch (Throwable t) {
logLocationModuleNotAvailable(t);
}
replySuccess(reply, null);
}

private void setShared(MethodCall call, Result result) {
OneSignal.getLocation().setShared((boolean) call.arguments);
try {
OneSignal.getLocation().setShared((boolean) call.arguments);
} catch (Throwable t) {
logLocationModuleNotAvailable(t);
}
replySuccess(result, null);
}

private void isShared(Result result) {
try {
replySuccess(result, OneSignal.getLocation().isShared());
} catch (Throwable t) {
logLocationModuleNotAvailable(t);
replySuccess(result, false);
}
}
}
11 changes: 10 additions & 1 deletion ios/onesignal_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
onesignal_xcframework_version = '5.5.2'
onesignal_disable_location_env = ENV['ONESIGNAL_DISABLE_LOCATION'].to_s.strip.downcase
onesignal_disable_location = ['true', '1'].include?(onesignal_disable_location_env)

s.name = 'onesignal_flutter'
s.version = '5.5.8'
s.summary = 'The OneSignal Flutter SDK'
Expand All @@ -13,7 +17,12 @@ Pod::Spec.new do |s|
s.source_files = 'onesignal_flutter/Sources/onesignal_flutter/**/*.{h,m}'
s.public_header_files = 'onesignal_flutter/Sources/onesignal_flutter/include/**/*.h'
s.dependency 'Flutter'
s.dependency 'OneSignalXCFramework', '5.5.2'
if onesignal_disable_location
s.dependency 'OneSignalXCFramework/OneSignal', onesignal_xcframework_version
s.dependency 'OneSignalXCFramework/OneSignalInAppMessages', onesignal_xcframework_version
else
s.dependency 'OneSignalXCFramework', onesignal_xcframework_version
end
s.ios.deployment_target = '11.0'
s.static_framework = true
end
25 changes: 19 additions & 6 deletions ios/onesignal_flutter/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
import Foundation

func oneSignalEnvFlag(_ name: String) -> Bool {
let value = Context.environment[name]?.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
return value == "true" || value == "1"
}

let oneSignalDisableLocation = oneSignalEnvFlag("ONESIGNAL_DISABLE_LOCATION")

var oneSignalDependencies: [Target.Dependency] = [
.product(name: "OneSignalFramework", package: "OneSignal-XCFramework"),
.product(name: "OneSignalInAppMessages", package: "OneSignal-XCFramework"),
.product(name: "OneSignalExtension", package: "OneSignal-XCFramework"),
]

if !oneSignalDisableLocation {
oneSignalDependencies.append(.product(name: "OneSignalLocation", package: "OneSignal-XCFramework"))
}

let package = Package(
name: "onesignal_flutter",
Expand All @@ -17,12 +35,7 @@ let package = Package(
targets: [
.target(
name: "onesignal_flutter",
dependencies: [
.product(name: "OneSignalFramework", package: "OneSignal-XCFramework"),
.product(name: "OneSignalInAppMessages", package: "OneSignal-XCFramework"),
.product(name: "OneSignalLocation", package: "OneSignal-XCFramework"),
.product(name: "OneSignalExtension", package: "OneSignal-XCFramework"),
],
dependencies: oneSignalDependencies,
cSettings: [
.headerSearchPath("include/onesignal_flutter")
]
Expand Down
Loading