Question by
DarioPavan · Jan 08, 2016 at 09:56 AM ·
build-errorxcodecloud
Unity cloud build by xcode 7
Hi There,
I'm working on Unity 5.1.1 and using Unity cloud build for iOS with xcode 7 option. My problem is I can't disable App transport Security, disable bitcode and enable "requires full screen" option on xcode 7. So, game always errors when build.
Thanks for support!
Comment
Best Answer
Answer by DarioPavan · Mar 02, 2016 at 06:53 AM
Guys, I figured it out!
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using UnityEditor.Callbacks;
using UnityEditor;
#if (UNITY_5 && UNITY_IOS)
using UnityEditor.iOS.Xcode;
#endif
namespace WhateverYouWant
{
public class Postprocessor
{
[PostProcessBuildAttribute(1)]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
{
BuildTarget iOSBuildTarget;
#if UNITY_5
iOSBuildTarget = BuildTarget.iOS;
#else
iOSBuildTarget = BuildTarget.iPhone;
#endif
if(target == iOSBuildTarget)
{
setBuildSettingAttrs(pathToBuiltProject);
addAppTransportSecuritySetting(pathToBuiltProject);
}
}
static void setBuildSettingAttrs(string path)
{
#if (UNITY_5 && UNITY_IOS)
string pbxprojPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
PBXProject project = new PBXProject();
project.ReadFromString(File.ReadAllText(pbxprojPath));
string target = project.TargetGuidByName("Unity-iPhone");
project.SetBuildProperty(target, "CLANG_ENABLE_MODULES", "YES");
project.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); // Disable bitcode to build on cloud
project.AddBuildProperty(target, "OTHER_LDFLAGS", "$(inherited)");
project.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
File.WriteAllText(pbxprojPath, project.WriteToString());
#else
UnityEngine.Debug.Log("Unable to modify build settings in XCode project. Build " +
"settings must be set manually");
#endif
}
static void addAppTransportSecuritySetting (string path){
// Get plist
string plistPath = path + "/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
// Get root
PlistElementDict rootDict = plist.root;
// Add NSAppTransportSecurity to plist
PlistElementDict appTransportDic = rootDict.CreateDict ("NSAppTransportSecurity");
appTransportDic.SetBoolean("NSAllowsArbitraryLoads", true);
// Write to file
File.WriteAllText(plistPath, plist.WriteToString());
}
}
}
Place this code into PostProcessor.cs then the file MUST BE placed in Editor folder. It works for me! @Mycroft
Answer by Mycroft · Jan 22, 2016 at 06:10 PM
@DarioPavan have you been able to fix this issue?
Anyone else have a good example for this issue?