Mobile Protect SDK for Unity (iOS)
Deprecated: refer to Mobile Protect SDK to an Unity App for the updated installation for version 0.0.7 and above.
Step 1: Configure your Unity project to use Cocoapods
In your Unity project, create a PostprocessBuild.cs
script inside Assets/Editor/
if you don’t have one yet, and add the following contents to it:
using UnityEditor;
using UnityEditor.Callbacks;
using System.Diagnostics;
using System.IO;
using UnityEngine;
using UnityEditor.iOS.Xcode;
public class PostprocessBuild
{
[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
{
if (buildTarget == BuildTarget.iOS)
{
// Create Podfile and add MobileProtect dependency
string podfilePath = Path.Combine(pathToBuiltProject, "Podfile");
using (StreamWriter writer = new StreamWriter(podfilePath, true))
{
writer.WriteLine("\n# Added by Unity");
writer.WriteLine("target 'Unity-iPhone' do");
writer.WriteLine(" use_frameworks!");
writer.WriteLine(" pod 'MobileProtect'");
writer.WriteLine("end");
}
// Run pod install automatically
Process proc = new Process();
proc.StartInfo.FileName = "/bin/bash";
proc.StartInfo.Arguments = "-c \"cd " + pathToBuiltProject + " && pod install\"";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
}
}
}
Step 2: Build your Unity project
Go to File > Build Settings
, select iOS
from the list of platforms, tap to Switch Platform
if needed and build
(do not build & run
).
Step 3: Open the generated iOS project in Xcode
Search for the Unity-iPhone.xcworkspace
file that the Unity build generated. If the only file you can find is Unity-iPhone.xcodeproj
, something went wrong while running pod install
in PostprocessBuild.cs
. You can run it manually by going into the iOS project folder in your terminal - this will create Unity-iPhone.xcworkspace
.
Open Unity-iPhone.xcworkspace
using Xcode.
Step 4: Add MobileProtect configuration file
Add MobileProtect.plist
to the iOS project.