Skip to content

Commit

Permalink
[SDK-908] Feature/webview fix (#37)
Browse files Browse the repository at this point in the history
-  ios build processor now correctly adds WebKit framework dependency
  • Loading branch information
HarrisonHough authored Apr 25, 2024
1 parent 3766c03 commit 7da2c60
Showing 1 changed file with 49 additions and 16 deletions.
65 changes: 49 additions & 16 deletions Editor/IOSBuildProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,63 @@
#if UNITY_IOS
using System;
using System.IO;
using UnityEditor.Callbacks;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.iOS.Xcode;
using UnityEngine;

namespace ReadyPlayerMe.WebView.Editor
{
public class IOSBuildProcessor : IPostprocessBuildWithReport
public class IOSBuildProcessor
{
public int callbackOrder => 0;

public void OnPostprocessBuild(BuildReport report)
[PostProcessBuild(100)]
public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
{
if (report.summary.platform != BuildTarget.iOS) return;
if (buildTarget != BuildTarget.iOS) return;

var projectPath = $"{report.summary.outputPath}/Unity-iPhone.xcodeproj/project.pbxproj";
var projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
var type = Type.GetType("UnityEditor.iOS.Xcode.PBXProject, UnityEditor.iOS.Extensions.Xcode");
if (type == null)
{
Debug.LogError("unitywebview: failed to get PBXProject. please install iOS build support.");
return;
}
var src = File.ReadAllText(projPath);
var proj = type.GetConstructor(Type.EmptyTypes).Invoke(null);
{
var method = type.GetMethod("ReadFromString");
method.Invoke(proj, new object[] { src });
}
var target = "";
{
var method = type.GetMethod("GetUnityFrameworkTargetGuid");
target = (string) method.Invoke(proj, null);
}

var pbxProject = new PBXProject();
pbxProject.ReadFromFile(projectPath);

// Main
var targetGuid = pbxProject.GetUnityMainTargetGuid();
pbxProject.AddFrameworkToProject(targetGuid, "WebKit.framework", false);

pbxProject.WriteToFile(projectPath);
{
var method = type.GetMethod("AddFrameworkToProject");
method.Invoke(proj, new object[] { target, "WebKit.framework", false });
}
var cflags = "";
if (EditorUserBuildSettings.development)
{
cflags += " -DUNITYWEBVIEW_DEVELOPMENT";
}
#if UNITYWEBVIEW_IOS_ALLOW_FILE_URLS
cflags += " -DUNITYWEBVIEW_IOS_ALLOW_FILE_URLS";
#endif
cflags = cflags.Trim();
if (!string.IsNullOrEmpty(cflags))
{
var method = type.GetMethod("AddBuildProperty", new Type[] { typeof(string), typeof(string), typeof(string) });
method.Invoke(proj, new object[] { target, "OTHER_CFLAGS", cflags });
}
var dst = "";
{
var method = type.GetMethod("WriteToString");
dst = (string) method.Invoke(proj, null);
}
File.WriteAllText(projPath, dst);
}
}
}
Expand Down

0 comments on commit 7da2c60

Please sign in to comment.