Recently I moved to using an M1 Mac Mini as a build machine for Unity IOS projects through Xcode.
Often I would use the Unity option to ‘Build and Run’ which would auto open Xcode and build the app - often this would select the first available device target.
This M1 Mac Mini seems to have ‘My Mac (Designed for iPad)’ as a build target for iPhone/iPad only apps (not mac build target) and Xcode automatically chooses to build for that target rather than the connected iPhone when Unity exports the build.
Is there a way to exclude that My Mac build target in Xcode or in the Xcode project? I only want to test on device and we are exporting as Device SDK not Simulator SDK for this reason.
After that, choose “Append” instead of “Replace” every time you “Build and Run” your Unity project. If you choose “Replace”, Unity will erase Xcode settings and you will need to set it again.
My idea is to use the following post process script for iOS, so you can don’t mind replace/append step anymore.
#if UNITY_IOS
using System;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using UnityEngine;
public class iOSPostProccessorBuild
{
[PostProcessBuild(2000)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
Debug.Log("iOSBuildPostProcess is now postprocessing iOS Project");
var projectPath = PBXProject.GetPBXProjectPath(path);
var project = new PBXProject();
project.ReadFromFile(projectPath);
var targetGuid = project.GetUnityMainTargetGuid();
project.SetBuildProperty(targetGuid, "SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD", "NO");
try
{
var projectInString = File.ReadAllText(projectPath);
projectInString = projectInString.Replace("SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;",
$"SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;");
File.WriteAllText(projectPath, projectInString);
}
catch (Exception e)
{
Debug.LogException(e);
}
project.WriteToFile(projectPath);
}
}
#endif
Hi! You’re free to try the build without this code. Honestly, I’ve found this block of code somewhere else for another Info.plist parameter, so I just fixed it for our case.
Using the script provided by @AytoMaximo causes the Unity editor to become unresponsive and will not complete the build process. I’m using Unity editor 2021.3.5f1. Does anyone else see this or have any additional solutions?