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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ All notable changes to this package will be documented in this file.
### Android
* Custom callbacks need the default in-window presentation. With `AndroidPaywallPresentation.Activity`, Unity is paused while the paywall is open, so each callback fails straight away and logs an error instead of leaving the paywall waiting.

### Fixes
* iOS paywalls now follow the orientations the game allows through `Screen.autorotateTo*` and `Screen.orientation`. Before, a landscape-only game could be rotated to portrait while a paywall was open, and stayed in portrait after it closed.

### Dependencies
* iOS: the generated Podfile now requires SuperwallKit `>= 4.12.10, < 5.0`, the first versions with the custom callback API. A Podfile kept by an Append build is updated.
* iOS: the generated Podfile now requires SuperwallKit `>= 4.19.1, < 5.0`. 4.12.10 added the custom callback API and 4.19.1 keeps paywalls to the game's orientations. A Podfile kept by an Append build is updated, unless you changed the SuperwallKit requirement by hand.

## [0.3.0]

Expand Down
48 changes: 40 additions & 8 deletions Editor/SuperwallPostBuildProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@
{
public int callbackOrder => 99;

// 4.12.10 added the custom callback API the bridge calls. 4.19.1 keeps a paywall to the
// orientations the game allows (Screen.autorotateTo*), and stops it leaving the game
// rotated after it closes.
public const string SuperwallKitPod = "pod 'SuperwallKit', '>= 4.19.1', '< 5.0'";

// Requirements earlier versions of this package wrote. A Podfile still naming one of these
// is moved to SuperwallKitPod; any other requirement was set by hand and is kept. Only the
// version part is spelled out here so native-sdk-bump.yml's rewrite of SuperwallKitPod
// leaves these alone.
private static readonly string[] PreviousSuperwallKitRequirements =
{
"'~> 4.0'",
"'>= 4.12.10', '< 5.0'",
};

/// <summary>
/// Moves a SuperwallKit requirement written by an earlier version of this package to the
/// current one. Returns the Podfile unchanged if it has none.
/// </summary>
public static string UpdateSuperwallKitRequirement(string podfileContent)
{
foreach (string requirement in PreviousSuperwallKitRequirements)
{
string previousPod = "pod 'SuperwallKit', " + requirement;
if (previousPod != SuperwallKitPod)
{
podfileContent = podfileContent.Replace(previousPod, SuperwallKitPod);

Check warning on line 42 in Editor/SuperwallPostBuildProcessor.cs

View check run for this annotation

Maple Review Bot / Maple / review

correctness: `UpdateSuperwallKitRequirement` rewrites customized constraint lists

A developer who appends `'< 4.19.0'` to the existing `'>= 4.12.10', '< 5.0'` requirement gets `'>= 4.19.1', '< 5.0', '< 4.19.0'` on the next Append build. The substring replacement changes a hand-customized requirement into contradictory bounds, breaking dependency resolution instead of preserving the customization.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

UpdateSuperwallKitRequirement rewrites customized constraint lists

F1 · Warning · correctness

A developer who appends '< 4.19.0' to the existing '>= 4.12.10', '< 5.0' requirement gets '>= 4.19.1', '< 5.0', '< 4.19.0' on the next Append build. The substring replacement changes a hand-customized requirement into contradictory bounds, breaking dependency resolution instead of preserving the customization.

Match the complete version-constraint list before replacing it, allowing trailing CocoaPods options or comments but leaving additional version constraints untouched. Add a regression test for an appended upper bound.
🤖 Prompt to fix with an AI agent
In `Editor/SuperwallPostBuildProcessor.cs:42`: `UpdateSuperwallKitRequirement` rewrites customized constraint lists.

A developer who appends `'< 4.19.0'` to the existing `'>= 4.12.10', '< 5.0'` requirement gets `'>= 4.19.1', '< 5.0', '< 4.19.0'` on the next Append build. The substring replacement changes a hand-customized requirement into contradictory bounds, breaking dependency resolution instead of preserving the customization.

Suggested fix: Match the complete version-constraint list before replacing it, allowing trailing CocoaPods options or comments but leaving additional version constraints untouched. Add a regression test for an appended upper bound.

Verify the problem exists at that location before changing it, and keep the fix to those lines.

}
}
return podfileContent;
}

public void OnPostprocessBuild(BuildReport report)
{
#if UNITY_IOS
Expand All @@ -24,10 +56,6 @@
}

#if UNITY_IOS
// 4.12.10 added the custom callback API the bridge calls.
private const string SuperwallKitPod = "pod 'SuperwallKit', '>= 4.12.10', '< 5.0'";
private const string LegacySuperwallKitPod = "pod 'SuperwallKit', '~> 4.0'";

private static void PostProcessIOS(string buildPath)
{
string podfilePath = Path.Combine(buildPath, "Podfile");
Expand Down Expand Up @@ -84,12 +112,16 @@
File.WriteAllText(podfilePath, podfileContent);
Debug.Log("[Superwall] Added SuperwallKit pod to existing Podfile");
}
else if (podfileContent.Contains(LegacySuperwallKitPod))
else
{
// An Append build keeps the Podfile from the last export. Without this, its old
// requirement lets Podfile.lock hold a SuperwallKit the bridge can't compile against.
File.WriteAllText(podfilePath, podfileContent.Replace(LegacySuperwallKitPod, SuperwallKitPod));
Debug.Log("[Superwall] Updated the SuperwallKit requirement in the existing Podfile");
// requirement lets Podfile.lock hold a SuperwallKit older than the bridge needs.
string updated = UpdateSuperwallKitRequirement(podfileContent);
if (updated != podfileContent)
{
File.WriteAllText(podfilePath, updated);
Debug.Log("[Superwall] Updated the SuperwallKit requirement in the existing Podfile");
}
}
}

Expand Down
42 changes: 42 additions & 0 deletions Tests/Editor/PodfileRequirementTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using NUnit.Framework;
using Superwall.Editor;

namespace Superwall.Editor.Tests
{
class PodfileRequirementTests
{
private static string Podfile(string pod) =>
"platform :ios, '15.0'\nuse_frameworks!\n\ntarget 'UnityFramework' do\n " + pod + "\nend\n";

[Test]
public void SuperwallKitPod_RequiresTheVersionThatKeepsPaywallsToTheGamesOrientations()
{
Assert.AreEqual("pod 'SuperwallKit', '>= 4.19.1', '< 5.0'", SuperwallPostBuildProcessor.SuperwallKitPod);
}

[TestCase("pod 'SuperwallKit', '~> 4.0'")]
[TestCase("pod 'SuperwallKit', '>= 4.12.10', '< 5.0'")]
public void UpdateSuperwallKitRequirement_MovesRequirementsThisPackageWroteBefore(string previousPod)
{
string updated = SuperwallPostBuildProcessor.UpdateSuperwallKitRequirement(Podfile(previousPod));

Assert.AreEqual(Podfile(SuperwallPostBuildProcessor.SuperwallKitPod), updated);
}

[Test]
public void UpdateSuperwallKitRequirement_LeavesTheCurrentRequirementAlone()
{
string podfile = Podfile(SuperwallPostBuildProcessor.SuperwallKitPod);

Assert.AreEqual(podfile, SuperwallPostBuildProcessor.UpdateSuperwallKitRequirement(podfile));
}

[Test]
public void UpdateSuperwallKitRequirement_KeepsARequirementSetByHand()
{
string podfile = Podfile("pod 'SuperwallKit', '4.19.3'");

Assert.AreEqual(podfile, SuperwallPostBuildProcessor.UpdateSuperwallKitRequirement(podfile));
}
}
}
2 changes: 2 additions & 0 deletions Tests/Editor/PodfileRequirementTests.cs.meta

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

Loading