diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml index a7828556c..8e97384e0 100644 --- a/.github/workflows/create-release-pr.yml +++ b/.github/workflows/create-release-pr.yml @@ -89,8 +89,8 @@ jobs: # Get versions from target branch (not the release branch) CURRENT_VERSION=$(git show origin/${{ inputs.target_branch }}:examples/demo/Assets/OneSignal/VERSION | tr -d '\n\r' | xargs) - ANDROID_VERSION=$(git show origin/${{ inputs.target_branch }}:com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml | grep -oE 'spec="com.onesignal:OneSignal:[0-9]+\.[0-9]+\.[0-9]+"' | sed -E 's/.*OneSignal:([0-9]+\.[0-9]+\.[0-9]+)".*/\1/' | head -1) - IOS_VERSION=$(git show origin/${{ inputs.target_branch }}:com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml | grep -oE 'version="[0-9.]+"' | grep -oE '[0-9.]+' | head -1) + ANDROID_VERSION=$(git show origin/${{ inputs.target_branch }}:com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs | grep -oE 'Version = "[0-9]+\.[0-9]+\.[0-9]+"' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) + IOS_VERSION=$(git show origin/${{ inputs.target_branch }}:com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.cs | grep -oE 'Version = "[0-9]+\.[0-9]+\.[0-9]+"' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) echo "unity_from=${CURRENT_VERSION}" >> $GITHUB_OUTPUT echo "android_from=${ANDROID_VERSION}" >> $GITHUB_OUTPUT echo "ios_from=${IOS_VERSION}" >> $GITHUB_OUTPUT @@ -109,7 +109,8 @@ jobs: sleep 30 done if [ "$FOUND" != "true" ]; then echo "✗ Android SDK version ${VERSION} not found after 5 attempts"; exit 1; fi - sed -i -E "s/spec=\"com\.onesignal:OneSignal:[0-9][0-9.]*\"/spec=\"com.onesignal:OneSignal:$VERSION\"/" com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml + sed -i -E "s/const string Version = \"[0-9][0-9.]*\"/const string Version = \"$VERSION\"/" com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs + sed -i -E "s/com\.onesignal:OneSignal:[0-9][0-9.]*<\/package>/com.onesignal:OneSignal:$VERSION<\/package>/" examples/demo/ProjectSettings/AndroidResolverDependencies.xml @@ -132,7 +133,8 @@ jobs: sleep 30 done if [ "$FOUND" != "true" ]; then echo "✗ iOS SDK version ${VERSION} not found after 5 attempts"; exit 1; fi - sed -i -E "s/version=\"[0-9][0-9.]*\"/version=\"$VERSION\"/" com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml + sed -i -E "s/const string Version = \"[0-9][0-9.]*\"/const string Version = \"$VERSION\"/" com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.cs + sed -i -E "s/version=\"[0-9][0-9.]*\"/version=\"$VERSION\"/" examples/demo/Assets/OneSignal/Editor/OneSignaliOSDependencies.xml # Only commit if there are changes git add -A diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 1a8751261..1828c7110 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -45,9 +45,9 @@ jobs: - name: Resolve OneSignal Android SDK version id: android-sdk-version run: | - VERSION=$(grep -oE 'com\.onesignal:OneSignal:[^"]+' com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml | head -n1 | cut -d: -f3) + VERSION=$(grep -oE 'Version = "[0-9]+\.[0-9]+\.[0-9]+"' com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs | head -n1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') if [ -z "$VERSION" ]; then - echo "::error::Could not parse OneSignal Android SDK version from OneSignalAndroidDependencies.xml" + echo "::error::Could not parse OneSignal Android SDK version from OneSignalAndroidDependencies.cs" exit 1 fi echo "version=${VERSION}" >> "$GITHUB_OUTPUT" diff --git a/README.md b/README.md index 62ee47318..1e28fadd1 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,23 @@ The only thing remaining is to setup your own notification icons. You can do thi with your own. There is a complete guide for this [in the plugin's README](com.onesignal.unity.android/Editor/OneSignalConfig.androidlib/README.md). See our [Customize Notification Icons](https://documentation.onesignal.com/docs/customize-notification-icons) page for additional details. +### Disable Location Module + +By default, the OneSignal Unity SDK 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. There are two ways to opt out: + +- **Editor toggle** (interactive): select **OneSignal > Disable Location Module** in the Unity Editor before resolving Android dependencies or building iOS. This is persisted per project in `ProjectSettings/OneSignalSettings.json`. +- **Environment variable** (CLI/CI): set `ONESIGNAL_DISABLE_LOCATION=true` (or `1`) in the environment before launching Unity, for example: + + ```sh + ONESIGNAL_DISABLE_LOCATION=true /path/to/Unity -batchmode -quit -projectPath . -buildTarget iOS -executeMethod BuildScript.BuildiOSSimulator + ``` + +When set, the environment variable takes precedence over the Editor toggle, so headless builds can opt out without changing project settings. + +With the location module disabled, Android resolves OneSignal's native modules without the location artifact and iOS uses OneSignal pods without `OneSignalLocation`. `OneSignal.Location.RequestPermission()` and `OneSignal.Location.IsShared = ...` no-op on native builds without the location module, and `OneSignal.Location.IsShared` returns `false`. + +When toggling the flag, clear stale native outputs (the generated Xcode project, CocoaPods/Gradle caches, and prior `Build/` artifacts) so a previously linked location module isn't reused. + ## Usage You can find a complete implementation in our included [example MonoBehaviour](OneSignalExample/Assets/OneSignal/Example/OneSignalExampleBehaviour.cs). Additionally we have included a [sample scene](OneSignalExample/Assets/OneSignal/Example/OneSignalExampleScene.unity) which you can run to test out the SDK. diff --git a/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs b/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs new file mode 100644 index 000000000..28685924c --- /dev/null +++ b/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs @@ -0,0 +1,103 @@ +/* + * Modified MIT License + * + * Copyright 2023 OneSignal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * 1. The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 2. All copies of substantial portions of the Software may only be used in connection + * with services provided by OneSignal. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +using System; +using System.IO; +using UnityEditor; +using UnityDebug = UnityEngine.Debug; + +namespace OneSignalSDK +{ + [InitializeOnLoad] + internal static class OneSignalAndroidDependencies + { + static OneSignalAndroidDependencies() + { + OneSignalSDKSettings.Changed += WriteDependencies; + WriteDependencies(); + } + + internal static void WriteDependencies() + { + var contents = OneSignalSDKSettings.EffectiveDisableLocation + ? DisabledLocationDependencies + : DefaultDependencies; + + try + { + if ( + File.Exists(_dependenciesPath) + && File.ReadAllText(_dependenciesPath) == contents + ) + return; + + Directory.CreateDirectory(Path.GetDirectoryName(_dependenciesPath)); + File.WriteAllText(_dependenciesPath, contents); + AssetDatabase.ImportAsset(_dependenciesPath); + } + catch (Exception exception) + { + UnityDebug.LogWarning( + $"Could not update OneSignal Android dependencies at {_dependenciesPath}: {exception.Message}" + ); + } + } + + internal const string Version = "5.9.5"; + + private static readonly string _dependenciesPath = Path.Combine( + "Assets", + "OneSignal", + "Editor", + "OneSignalAndroidDependencies.xml" + ); + + private static string DefaultDependencies => + $@" + + + https://repo.maven.apache.org/maven2 + + + + +"; + + private static string DisabledLocationDependencies => + $@" + + + https://repo.maven.apache.org/maven2 + + + + + + +"; + } +} diff --git a/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs.meta b/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs.meta new file mode 100644 index 000000000..3dfe5c242 --- /dev/null +++ b/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7c79cba1d8d84b6bba362e113f39e1d2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.onesignal.unity.android/Runtime/AndroidLocationManager.cs b/com.onesignal.unity.android/Runtime/AndroidLocationManager.cs index 22cd337ee..3827606f4 100644 --- a/com.onesignal.unity.android/Runtime/AndroidLocationManager.cs +++ b/com.onesignal.unity.android/Runtime/AndroidLocationManager.cs @@ -25,8 +25,9 @@ * THE SOFTWARE. */ -using System.Threading.Tasks; +using System; using OneSignalSDK.Android.Utilities; +using OneSignalSDK.Debug.Utilities; using OneSignalSDK.Location; using UnityEngine; @@ -34,23 +35,62 @@ namespace OneSignalSDK.Android.Location { internal sealed class AndroidLocationManager : ILocationManager { + private const string LocationModuleNotAvailable = + "OneSignal location module is not available. Add the location dependency to use OneSignal.Location."; + private readonly AndroidJavaObject _location; public AndroidLocationManager(AndroidJavaClass sdkClass) { - _location = sdkClass.CallStatic("getLocation"); + try + { + _location = sdkClass.CallStatic("getLocation"); + } + catch (Exception) + { + SDKDebug.Error(LocationModuleNotAvailable); + } } public bool IsShared { - get => _location.Call("isShared"); - set => _location.Call("setShared", value); + get + { + try + { + return _location != null && _location.Call("isShared"); + } + catch (Exception) + { + SDKDebug.Error(LocationModuleNotAvailable); + return false; + } + } + set + { + try + { + if (_location != null) + _location.Call("setShared", value); + } + catch (Exception) + { + SDKDebug.Error(LocationModuleNotAvailable); + } + } } public void RequestPermission() { - var continuation = new BoolContinuation(); - _location.Call("requestPermission", continuation.Proxy); + try + { + var continuation = new BoolContinuation(); + _location.Call("requestPermission", continuation.Proxy); + } + catch (Exception) + { + SDKDebug.Error(LocationModuleNotAvailable); + } } } } diff --git a/com.onesignal.unity.core/Editor/OneSignalSDKSettings.cs b/com.onesignal.unity.core/Editor/OneSignalSDKSettings.cs new file mode 100644 index 000000000..c51b91c14 --- /dev/null +++ b/com.onesignal.unity.core/Editor/OneSignalSDKSettings.cs @@ -0,0 +1,125 @@ +/* + * Modified MIT License + * + * Copyright 2023 OneSignal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * 1. The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 2. All copies of substantial portions of the Software may only be used in connection + * with services provided by OneSignal. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +using System; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace OneSignalSDK +{ + public static class OneSignalSDKSettings + { + public const string DisableLocationEnvVar = "ONESIGNAL_DISABLE_LOCATION"; + + public static event Action Changed; + + public static bool DisableLocation + { + get => _settings.disableLocation; + set + { + if (_settings.disableLocation == value) + return; + + _settings.disableLocation = value; + Save(); + Changed?.Invoke(); + AssetDatabase.Refresh(); + } + } + + /// + /// Resolved value used by the build pipeline. The + /// environment variable, when present, overrides the persisted Editor setting so CLI + /// and CI builds can opt out without mutating project settings. + /// + public static bool EffectiveDisableLocation + { + get + { + var environmentValue = Environment.GetEnvironmentVariable(DisableLocationEnvVar); + if (!string.IsNullOrEmpty(environmentValue)) + { + var normalized = environmentValue.Trim(); + return normalized.Equals("true", StringComparison.OrdinalIgnoreCase) + || normalized == "1"; + } + + return _settings.disableLocation; + } + } + + public static void Save() + { + Directory.CreateDirectory(Path.GetDirectoryName(_settingsPath)); + File.WriteAllText(_settingsPath, JsonUtility.ToJson(_settings, true)); + } + + [MenuItem("OneSignal/Disable Location Module")] + private static void ToggleDisableLocation() + { + DisableLocation = !DisableLocation; + } + + [MenuItem("OneSignal/Disable Location Module", true)] + private static bool ToggleDisableLocationValidate() + { + Menu.SetChecked("OneSignal/Disable Location Module", DisableLocation); + return true; + } + + private static readonly string _settingsPath = Path.Combine( + "ProjectSettings", + "OneSignalSettings.json" + ); + + private static Settings _settings = Load(); + + private static Settings Load() + { + if (!File.Exists(_settingsPath)) + return new Settings(); + + try + { + return JsonUtility.FromJson(File.ReadAllText(_settingsPath)) + ?? new Settings(); + } + catch + { + return new Settings(); + } + } + + [Serializable] + private sealed class Settings + { + public bool disableLocation; + } + } +} diff --git a/com.onesignal.unity.core/Editor/OneSignalSDKSettings.cs.meta b/com.onesignal.unity.core/Editor/OneSignalSDKSettings.cs.meta new file mode 100644 index 000000000..1e308d59b --- /dev/null +++ b/com.onesignal.unity.core/Editor/OneSignalSDKSettings.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5f3f0ff2a9a0419ca5b5fae3f72396ad +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.onesignal.unity.ios/Editor/BuildPostProcessor.cs b/com.onesignal.unity.ios/Editor/BuildPostProcessor.cs index 6a294b321..de9721e49 100644 --- a/com.onesignal.unity.ios/Editor/BuildPostProcessor.cs +++ b/com.onesignal.unity.ios/Editor/BuildPostProcessor.cs @@ -60,7 +60,7 @@ using UnityEditor.Build; using UnityEditor.Build.Reporting; using UnityEditor.iOS.Xcode.Extensions; -using Debug = UnityEngine.Debug; +using UnityDebug = UnityEngine.Debug; using UnityEditor.Callbacks; namespace OneSignalSDK.iOS @@ -73,14 +73,8 @@ public class BuildPostProcessor : IPostprocessBuildWithReport { private const string ServiceExtensionTargetName = "OneSignalNotificationServiceExtension"; private const string ServiceExtensionFilename = "NotificationService.swift"; - private const string DependenciesFilename = "OneSignaliOSDependencies.xml"; private const string PackageName = "com.onesignal.unity.ios"; - private static readonly string EditorFilesPath = Path.Combine( - "Packages", - PackageName, - "Editor" - ); private static readonly string PluginLibrariesPath = Path.Combine( PackageName, "Runtime", @@ -126,8 +120,10 @@ public void OnPostprocessBuild(BuildReport report) AddNotificationServiceExtension(); DisableBitcode(); + ConfigureLocationModule(); - AddLocationUsageDescription(); + if (!OneSignalSDK.OneSignalSDKSettings.EffectiveDisableLocation) + AddLocationUsageDescription(); // Save the project back out File.WriteAllText(_projectPath, _project.WriteToString()); @@ -311,41 +307,20 @@ private void ExtensionAddPodsToTarget() if (!File.Exists(podfilePath)) { - Debug.LogError( + UnityDebug.LogError( $"Could not find Podfile. {ServiceExtensionFilename} will have errors." ); return; } - var dependenciesFilePath = Path.Combine(EditorFilesPath, DependenciesFilename); - - if (!File.Exists(dependenciesFilePath)) - { - Debug.LogError($"Could not find {DependenciesFilename}"); - return; - } - - var dependenciesFile = File.ReadAllText(dependenciesFilePath); - var dependenciesRegex = new Regex( - "(?<=)" - ); - - if (!dependenciesRegex.IsMatch(dependenciesFile)) - { - Debug.LogError( - $"Could not read current iOS framework dependency version from {DependenciesFilename}" - ); - return; - } - var podfile = File.ReadAllText(podfilePath); var podfileRegex = new Regex( - $@"target '{ServiceExtensionTargetName}' do\n pod 'OneSignalXCFramework', '(.+)'\nend\n" + $@"target '{ServiceExtensionTargetName}' do\n pod 'OneSignalXCFramework(?:/OneSignalExtension)?', '(.+)'\nend\n" ); - var requiredVersion = dependenciesRegex.Match(dependenciesFile).ToString(); + var requiredVersion = OneSignaliOSDependencies.Version; var requiredTarget = - $"target '{ServiceExtensionTargetName}' do\n pod 'OneSignalXCFramework', '{requiredVersion}'\nend\n"; + $"target '{ServiceExtensionTargetName}' do\n pod 'OneSignalXCFramework/OneSignalExtension', '{requiredVersion}'\nend\n"; if (!podfileRegex.IsMatch(podfile)) podfile += requiredTarget; @@ -355,9 +330,29 @@ private void ExtensionAddPodsToTarget() podfile = podfile.Replace(podfileTarget, requiredTarget); } + // The app, widget, and notification service extension targets each copy the + // OneSignal XCFrameworks. With static frameworks this declares the same output + // file from multiple script phases, which newer Xcode treats as a hard + // "Multiple commands produce" error. Dropping the declared input/output paths + // makes the copy phases run unconditionally and resolves the conflict. + if (!podfile.Contains("disable_input_output_paths")) + podfile = "install! 'cocoapods', :disable_input_output_paths => true\n" + podfile; + File.WriteAllText(podfilePath, podfile); } + private void ConfigureLocationModule() + { + if (!OneSignalSDK.OneSignalSDKSettings.EffectiveDisableLocation) + return; + + _project.AddBuildProperty( + _project.GetUnityFrameworkTargetGuid(), + "GCC_PREPROCESSOR_DEFINITIONS", + "ONESIGNAL_DISABLE_LOCATION=1" + ); + } + private void AddLocationUsageDescription() { var plistPath = Path.Combine(_outputPath, "Info.plist"); diff --git a/com.onesignal.unity.ios/Editor/OneSignal.iOS.Editor.asmdef b/com.onesignal.unity.ios/Editor/OneSignal.iOS.Editor.asmdef index 54663dac3..23c5084c8 100644 --- a/com.onesignal.unity.ios/Editor/OneSignal.iOS.Editor.asmdef +++ b/com.onesignal.unity.ios/Editor/OneSignal.iOS.Editor.asmdef @@ -1,6 +1,8 @@ { "name": "OneSignal.iOS.Editor", - "references": [], + "references": [ + "OneSignal.Core.Editor" + ], "optionalUnityReferences": [], "includePlatforms": [ "Editor" diff --git a/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.cs b/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.cs new file mode 100644 index 000000000..32e075815 --- /dev/null +++ b/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.cs @@ -0,0 +1,96 @@ +/* + * Modified MIT License + * + * Copyright 2023 OneSignal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * 1. The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 2. All copies of substantial portions of the Software may only be used in connection + * with services provided by OneSignal. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +using System; +using System.IO; +using UnityEditor; +using UnityDebug = UnityEngine.Debug; + +namespace OneSignalSDK.iOS +{ + [InitializeOnLoad] + internal static class OneSignaliOSDependencies + { + static OneSignaliOSDependencies() + { + OneSignalSDK.OneSignalSDKSettings.Changed += WriteDependencies; + WriteDependencies(); + } + + internal static void WriteDependencies() + { + var contents = OneSignalSDK.OneSignalSDKSettings.EffectiveDisableLocation + ? DisabledLocationDependencies + : DefaultDependencies; + + try + { + if ( + File.Exists(_dependenciesPath) + && File.ReadAllText(_dependenciesPath) == contents + ) + return; + + Directory.CreateDirectory(Path.GetDirectoryName(_dependenciesPath)); + File.WriteAllText(_dependenciesPath, contents); + AssetDatabase.ImportAsset(_dependenciesPath); + } + catch (Exception exception) + { + UnityDebug.LogWarning( + $"Could not update OneSignal iOS dependencies at {_dependenciesPath}: {exception.Message}" + ); + } + } + + internal const string Version = "5.5.3"; + + private static readonly string _dependenciesPath = Path.Combine( + "Assets", + "OneSignal", + "Editor", + "OneSignaliOSDependencies.xml" + ); + + private static string DefaultDependencies => + $@" + + + + +"; + + private static string DisabledLocationDependencies => + $@" + + + + + +"; + } +} diff --git a/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.cs.meta b/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.cs.meta new file mode 100644 index 000000000..49c9aa34e --- /dev/null +++ b/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b70d336c6c914452a259cd750a23da35 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.onesignal.unity.ios/Runtime/Plugins/iOS/OneSignalUnityBridgeLocation.mm b/com.onesignal.unity.ios/Runtime/Plugins/iOS/OneSignalUnityBridgeLocation.mm index 2c6988afb..a5c6c2d58 100644 --- a/com.onesignal.unity.ios/Runtime/Plugins/iOS/OneSignalUnityBridgeLocation.mm +++ b/com.onesignal.unity.ios/Runtime/Plugins/iOS/OneSignalUnityBridgeLocation.mm @@ -31,16 +31,31 @@ #import #import +static NSString *const OneSignalLocationModuleNotFoundMessage = @"OneSignalLocation not found. In order to use OneSignal's location features the OneSignalLocation module must be added."; + extern "C" { bool _oneSignalLocationGetIsShared() { +#if ONESIGNAL_DISABLE_LOCATION + [OneSignalLog onesignalLog:ONE_S_LL_ERROR message:OneSignalLocationModuleNotFoundMessage]; + return false; +#else return [OneSignal.Location isShared]; +#endif } void _oneSignalLocationSetIsShared(bool shared) { +#if ONESIGNAL_DISABLE_LOCATION + [OneSignalLog onesignalLog:ONE_S_LL_ERROR message:OneSignalLocationModuleNotFoundMessage]; +#else [OneSignal.Location setShared:shared]; +#endif } void _oneSignalLocationRequestPermission() { +#if ONESIGNAL_DISABLE_LOCATION + [OneSignalLog onesignalLog:ONE_S_LL_ERROR message:OneSignalLocationModuleNotFoundMessage]; +#else [OneSignal.Location requestPermission]; +#endif } } \ No newline at end of file diff --git a/examples/demo/Assets/App/Editor/iOS/BuildPostProcessor.cs b/examples/demo/Assets/App/Editor/iOS/BuildPostProcessor.cs index 424bbb889..a3fb9cab1 100644 --- a/examples/demo/Assets/App/Editor/iOS/BuildPostProcessor.cs +++ b/examples/demo/Assets/App/Editor/iOS/BuildPostProcessor.cs @@ -228,8 +228,8 @@ static void AddWidgetExtensionToPodFile(string outputPath) static string ResolveOneSignalXCFrameworkVersion() { var dependenciesFilePath = Path.Combine( - "Packages", - "com.onesignal.unity.ios", + "Assets", + "OneSignal", "Editor", "OneSignaliOSDependencies.xml" ); diff --git a/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml b/examples/demo/Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml similarity index 100% rename from com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml rename to examples/demo/Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml diff --git a/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml.meta b/examples/demo/Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml.meta similarity index 59% rename from com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml.meta rename to examples/demo/Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml.meta index 079545c0c..4d0c987ab 100644 --- a/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml.meta +++ b/examples/demo/Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml.meta @@ -1,7 +1,5 @@ fileFormatVersion: 2 -guid: 127a9573f8846469b8feaf4dd86f9587 -timeCreated: 1521620682 -licenseType: Free +guid: b7aeb390ee8404c2fb63778d3f0870c7 TextScriptImporter: externalObjects: {} userData: diff --git a/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml b/examples/demo/Assets/OneSignal/Editor/OneSignaliOSDependencies.xml similarity index 100% rename from com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml rename to examples/demo/Assets/OneSignal/Editor/OneSignaliOSDependencies.xml diff --git a/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml.meta b/examples/demo/Assets/OneSignal/Editor/OneSignaliOSDependencies.xml.meta similarity index 75% rename from com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml.meta rename to examples/demo/Assets/OneSignal/Editor/OneSignaliOSDependencies.xml.meta index 69b8a119e..732ef7698 100644 --- a/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml.meta +++ b/examples/demo/Assets/OneSignal/Editor/OneSignaliOSDependencies.xml.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 033a0fbaaa064a48ad2e72d8e35d5f36 +guid: df6b6a1d706cb43d99405e586ebe2bee TextScriptImporter: externalObjects: {} userData: diff --git a/examples/demo/Assets/Plugins/Android/mainTemplate.gradle b/examples/demo/Assets/Plugins/Android/mainTemplate.gradle index c690b6b96..c918d55bc 100644 --- a/examples/demo/Assets/Plugins/Android/mainTemplate.gradle +++ b/examples/demo/Assets/Plugins/Android/mainTemplate.gradle @@ -8,7 +8,7 @@ apply from: '../shared/common.gradle' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) // Android Resolver Dependencies Start - implementation 'com.onesignal:OneSignal:5.9.5' // Packages/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml:6 + implementation 'com.onesignal:OneSignal:5.9.5' // Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml:6 // Android Resolver Dependencies End **DEPS**} diff --git a/examples/demo/Assets/Plugins/Android/settingsTemplate.gradle b/examples/demo/Assets/Plugins/Android/settingsTemplate.gradle index e1430ece3..49f680b5d 100644 --- a/examples/demo/Assets/Plugins/Android/settingsTemplate.gradle +++ b/examples/demo/Assets/Plugins/Android/settingsTemplate.gradle @@ -19,7 +19,7 @@ dependencyResolutionManagement { // Android Resolver Repos Start def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/") maven { - url "https://repo.maven.apache.org/maven2" // Packages/com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml:5 + url "https://repo.maven.apache.org/maven2" // Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml:5 } mavenLocal() // Android Resolver Repos End