diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bb3896..079e949 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/Editor/SuperwallPostBuildProcessor.cs b/Editor/SuperwallPostBuildProcessor.cs index 725871a..69acc98 100644 --- a/Editor/SuperwallPostBuildProcessor.cs +++ b/Editor/SuperwallPostBuildProcessor.cs @@ -13,6 +13,38 @@ public class SuperwallPostBuildProcessor : IPostprocessBuildWithReport { 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'", + }; + + /// + /// Moves a SuperwallKit requirement written by an earlier version of this package to the + /// current one. Returns the Podfile unchanged if it has none. + /// + public static string UpdateSuperwallKitRequirement(string podfileContent) + { + foreach (string requirement in PreviousSuperwallKitRequirements) + { + string previousPod = "pod 'SuperwallKit', " + requirement; + if (previousPod != SuperwallKitPod) + { + podfileContent = podfileContent.Replace(previousPod, SuperwallKitPod); + } + } + return podfileContent; + } + public void OnPostprocessBuild(BuildReport report) { #if UNITY_IOS @@ -24,10 +56,6 @@ public void OnPostprocessBuild(BuildReport report) } #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"); @@ -84,12 +112,16 @@ private static void PostProcessIOS(string buildPath) 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"); + } } } diff --git a/Tests/Editor/PodfileRequirementTests.cs b/Tests/Editor/PodfileRequirementTests.cs new file mode 100644 index 0000000..4da606a --- /dev/null +++ b/Tests/Editor/PodfileRequirementTests.cs @@ -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)); + } + } +} diff --git a/Tests/Editor/PodfileRequirementTests.cs.meta b/Tests/Editor/PodfileRequirementTests.cs.meta new file mode 100644 index 0000000..058c79e --- /dev/null +++ b/Tests/Editor/PodfileRequirementTests.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 475dada1ffcc4deabb158715b5904d53 \ No newline at end of file