Skip to content
Open
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
14 changes: 8 additions & 6 deletions .github/scripts/validate-unity-distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
"com.onesignal.unitysdk.ios",
)
CORE_PACKAGE = PACKAGE_NAMES[0]
PLATFORM_PACKAGES = PACKAGE_NAMES[1:]
ANDROID_PACKAGE = PACKAGE_NAMES[1]
IOS_PACKAGE = PACKAGE_NAMES[2]
EDM_PACKAGE = "com.unity.external-dependency-manager"
EDM_VERSION = "2.0.0"
MINIMUM_UNITY_VERSION = "2022.3"
MINIMUM_UNITY_RELEASE = "0f1"
MINIMUM_UNITY_VERSION = "6000.0"
MINIMUM_UNITY_RELEASE = "23f1"

EXCLUDED_PREFIXES = (
"Assets/OneSignal/Attribution",
Expand Down Expand Up @@ -153,9 +154,10 @@ def validate_packages() -> None:
if package.get("dependencies", {}).get(CORE_PACKAGE) != core_version:
fail(f"{name} does not depend on {CORE_PACKAGE}@{core_version}")

for name in PLATFORM_PACKAGES:
if packages[name].get("dependencies", {}).get(EDM_PACKAGE) != EDM_VERSION:
fail(f"{name} does not depend on {EDM_PACKAGE}@{EDM_VERSION}")
if packages[ANDROID_PACKAGE].get("dependencies", {}).get(EDM_PACKAGE) != EDM_VERSION:
fail(f"{ANDROID_PACKAGE} does not depend on {EDM_PACKAGE}@{EDM_VERSION}")
if EDM_PACKAGE in packages[IOS_PACKAGE].get("dependencies", {}):
fail(f"{IOS_PACKAGE} uses the OneSignal Swift package, not {EDM_PACKAGE}")

legacy_installer = ROOT / CORE_PACKAGE / "Editor/SetupSteps/InstallEdm4uStep.cs"
if legacy_installer.exists():
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ 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.unitysdk.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.unitysdk.ios/Editor/OneSignaliOSDependencies.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.unitysdk.ios/Editor/OneSignalSwiftPackage.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
Expand Down Expand Up @@ -141,13 +141,12 @@ jobs:
VERSION="${{ inputs.ios_version }}"
if ! curl --fail --silent --show-error --retry 4 --retry-delay 30 \
-H "Authorization: token ${{ github.token }}" \
"https://api.github.com/repos/OneSignal/OneSignal-iOS-SDK/releases/tags/${VERSION}" \
"https://api.github.com/repos/OneSignal/OneSignal-XCFramework/releases/tags/${VERSION}" \
>/dev/null; then
echo "✗ iOS SDK version ${VERSION} not found"
echo "✗ OneSignal-XCFramework ${VERSION} not found"
exit 1
fi
sed -i -E "s/const string Version = \"[0-9][0-9.]*\"/const string Version = \"$VERSION\"/" com.onesignal.unitysdk.ios/Editor/OneSignaliOSDependencies.cs
sed -i -E "s/version=\"[0-9][0-9.]*\"/version=\"$VERSION\"/" examples/demo/Assets/OneSignal/Editor/OneSignaliOSDependencies.xml
sed -i -E "s/const string Version = \"[0-9][0-9.]*\"/const string Version = \"$VERSION\"/" com.onesignal.unitysdk.ios/Editor/OneSignalSwiftPackage.cs

# Only commit if there are changes
git add -A
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ jobs:

- name: Cache Xcode DerivedData
# Hash inputs to the Unity iOS export (files that exist at checkout
# time) rather than the exported Xcode project / Podfile, which
# don't exist until later steps run. Mirrors the Android Unity
# time) rather than the exported Xcode project, which doesn't
# exist until later steps run. Mirrors the Android Unity
# Library cache key shape above.
uses: actions/cache@v5
with:
Expand All @@ -169,10 +169,6 @@ jobs:
allowDirtyBuild: true
cacheUnityInstallationOnMac: true

- name: Pod install
working-directory: examples/demo/Build/iOS
run: pod install --repo-update

- name: Set up iOS codesigning
uses: OneSignal/sdk-shared/.github/actions/setup-ios-demo-codesigning@main
with:
Expand All @@ -185,13 +181,12 @@ jobs:
- name: Build signed IPA
working-directory: examples/demo/Build/iOS
# Unity always names the generated Xcode project Unity-iPhone, even
# though the demo's product name is "OneSignal Demo". After
# `pod install` an Unity-iPhone.xcworkspace exists and must be used;
# without CocoaPods we fall back to the .xcodeproj. The
# though the demo's product name is "OneSignal Demo". The
# SigningPostProcessor already pinned DEVELOPMENT_TEAM and the NSE /
# Live Activity bundle IDs to match ExportOptions.plist. CI only has the
# in-house distribution cert, so the identity and team are also pinned
# here for targets the post-processor skips (UnityFramework, Pods).
# External Dependency Manager runs `pod install`, which adds a workspace.
run: |
if [ -d Unity-iPhone.xcworkspace ]; then
CONTAINER_ARGS=(-workspace Unity-iPhone.xcworkspace)
Expand Down
4 changes: 2 additions & 2 deletions com.onesignal.unitysdk.android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "com.onesignal.unitysdk.android",
"displayName": "OneSignal SDK Android",
"version": "6.0.0",
"unity": "2022.3",
"unityRelease": "0f1",
"unity": "6000.0",
"unityRelease": "23f1",
"description": "Android platform implementation for the OneSignal Unity SDK, including native dependency resolution and notification resources.",
"dependencies": {
"com.onesignal.unitysdk.core": "6.0.0",
Expand Down
4 changes: 2 additions & 2 deletions com.onesignal.unitysdk.core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "com.onesignal.unitysdk.core",
"displayName": "OneSignal SDK Core",
"version": "6.0.0",
"unity": "2022.3",
"unityRelease": "0f1",
"unity": "6000.0",
"unityRelease": "23f1",
"description": "Core APIs, editor setup, and shared runtime for the OneSignal Unity SDK. Install the Android and/or iOS package for native platform support.",
"keywords": [
"push-notifications",
Expand Down
67 changes: 22 additions & 45 deletions com.onesignal.unitysdk.ios/Editor/BuildPostProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@
using System.IO;
using UnityEditor;
using UnityEditor.iOS.Xcode;
using System.Text.RegularExpressions;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.iOS.Xcode.Extensions;
using UnityDebug = UnityEngine.Debug;
using UnityEditor.Callbacks;

namespace OneSignalSDK.iOS
Expand Down Expand Up @@ -93,10 +91,6 @@ public class BuildPostProcessor : IPostprocessBuildWithReport

private string _appGroupName => $"group.{PlayerSettings.applicationIdentifier}.onesignal";

/// <summary>
/// must be between 40 and 50 to ensure that it's not overriden by Podfile generation (40) and that it's
/// added before "pod install" (50)
/// </summary>
public int callbackOrder => 45;

/// <summary>
Expand All @@ -115,6 +109,8 @@ public void OnPostprocessBuild(BuildReport report)
// Turn on capabilities required by OneSignal
AddProjectCapabilities();

AddSwiftPackageProducts();

// Add the service extension
AddNotificationServiceExtension();

Expand Down Expand Up @@ -195,9 +191,8 @@ private void AddProjectCapabilities()
private void AddNotificationServiceExtension()
{
#if !UNITY_CLOUD_BUILD
// refresh plist and podfile on appends
// refresh plist on appends
ExtensionCreatePlist(_outputPath);
ExtensionAddPodsToTarget();

var extensionGuid = _project.TargetGuidByName(ServiceExtensionTargetName);

Expand Down Expand Up @@ -233,6 +228,8 @@ private void AddNotificationServiceExtension()
$"$(PROJECT_DIR)/Libraries/{PluginLibrariesPath.Replace("\\", "/")}"
);

OneSignalSwiftPackage.AddProduct(_project, extensionGuid, "OneSignalExtension");

_project.WriteToFile(_projectPath);

// add capabilities + entitlements
Expand Down Expand Up @@ -300,44 +297,24 @@ private bool ExtensionCreatePlist(string path)
return alreadyExists;
}

private void ExtensionAddPodsToTarget()
/// <summary>
/// Link the OneSignal Swift package to the app, and to UnityFramework where the bridge code compiles
/// </summary>
private void AddSwiftPackageProducts()
{
var podfilePath = Path.Combine(_outputPath, "Podfile");

if (!File.Exists(podfilePath))
{
UnityDebug.LogError(
$"Could not find Podfile. {ServiceExtensionFilename} will have errors."
);
return;
}

var podfile = File.ReadAllText(podfilePath);
var podfileRegex = new Regex(
$@"target '{ServiceExtensionTargetName}' do\n pod 'OneSignalXCFramework(?:/OneSignalExtension)?', '(.+)'\nend\n"
);

var requiredVersion = OneSignaliOSDependencies.Version;
var requiredTarget =
$"target '{ServiceExtensionTargetName}' do\n pod 'OneSignalXCFramework/OneSignalExtension', '{requiredVersion}'\nend\n";

if (!podfileRegex.IsMatch(podfile))
podfile += requiredTarget;
else
{
var podfileTarget = podfileRegex.Match(podfile).ToString();
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);
var products = OneSignalSDK.OneSignalSDKSettings.EffectiveDisableLocation
? new[] { "OneSignalFramework", "OneSignalInAppMessages" }
: new[] { "OneSignalFramework", "OneSignalInAppMessages", "OneSignalLocation" };

foreach (
var targetGuid in new[]
{
_project.GetMainTargetGuid(),
_project.GetUnityFrameworkTargetGuid(),
}
)
foreach (var product in products)
OneSignalSwiftPackage.AddProduct(_project, targetGuid, product);
}

private void ConfigureLocationModule()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": false,
"autoReferenced": true,
"defineConstraints": []
}
99 changes: 99 additions & 0 deletions com.onesignal.unitysdk.ios/Editor/OneSignalSwiftPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Modified MIT License
*
* Copyright 2026 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.
*/

#if UNITY_IOS
using System.Text.RegularExpressions;
using UnityEditor.iOS.Xcode;

namespace OneSignalSDK.iOS
{
/// <summary>
/// Adds the OneSignal iOS SDK to an exported Xcode project as a Swift package.
/// </summary>
public static class OneSignalSwiftPackage
{
public const string RepositoryUrl = "https://github.com/OneSignal/OneSignal-XCFramework";
public const string Version = "5.8.1";

/// <summary>
/// Links a OneSignal package product, such as <c>OneSignalFramework</c> or
/// <c>OneSignalExtension</c>, to a target. Safe to call again on appended builds.
/// </summary>
public static void AddProduct(PBXProject project, string targetGuid, string product)
{
var packageGuid = GetOrAddReference(project);

if (TargetHasProduct(project.WriteToString(), targetGuid, product))
return;

project.AddRemotePackageFrameworkToProject(targetGuid, product, packageGuid, false);
}

private static string GetOrAddReference(PBXProject project)
{
var contents = project.WriteToString();
var match = ReferenceRegex.Match(contents);

if (!match.Success)
return project.AddRemotePackageReferenceAtVersion(RepositoryUrl, Version);

var requirement = match.Groups["requirement"];
var pinned =
$"requirement = {{\n\t\t\t\tkind = exactVersion;\n\t\t\t\tversion = {Version};\n\t\t\t}};";

if (requirement.Value != pinned)
project.ReadFromString(
contents
.Remove(requirement.Index, requirement.Length)
.Insert(requirement.Index, pinned)
);

return match.Groups["guid"].Value;
}

private static bool TargetHasProduct(string contents, string targetGuid, string product)
{
var target = new Regex(
$@"\t\t{targetGuid} /\* .+? \*/ = {{\s*isa = PBXNativeTarget;.*?\n\t\t}};",
RegexOptions.Singleline
).Match(contents);

return target.Success
&& Regex.IsMatch(
target.Value,
$@"packageProductDependencies = \([^)]*/\* {Regex.Escape(product)} \*/"
);
}

private static readonly Regex ReferenceRegex = new Regex(
@"(?<guid>[0-9A-F]{24}) /\* XCRemoteSwiftPackageReference ""[^""]*"" \*/ = {\s*isa = XCRemoteSwiftPackageReference;\s*repositoryURL = ""?"
+ Regex.Escape(RepositoryUrl)
+ @"(?:\.git)?""?;\s*(?<requirement>requirement = {[^}]*};)"
);
}
}
#endif
11 changes: 11 additions & 0 deletions com.onesignal.unitysdk.ios/Editor/OneSignalSwiftPackage.cs.meta

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

Loading