Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save moto2002/b5a575a30931cb2411dbf5ce91c7ebc9 to your computer and use it in GitHub Desktop.

Select an option

Save moto2002/b5a575a30931cb2411dbf5ce91c7ebc9 to your computer and use it in GitHub Desktop.

Revisions

  1. @sanukin39 sanukin39 revised this gist Jun 19, 2016. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions XcodeSettingsPostProcesser.cs
    Original file line number Diff line number Diff line change
    @@ -56,10 +56,10 @@ public static void OnPostprocessBuild (BuildTarget buildTarget, string pathToBui

    // Add URL Scheme
    var array = plist.root.CreateArray ("CFBundleURLTypes");
    var dmgDict = array.AddDict ();
    dmgDict.SetString ("CFBundleURLName", "hogehogeName");
    var dmgInnerArray = dmgDict.CreateArray ("CFBundleURLSchemes");
    dmgInnerArray.AddString ("hogehogeValue");
    var urlDict = array.AddDict ();
    urlDict.SetString ("CFBundleURLName", "hogehogeName");
    var urlInnerArray = urlDict.CreateArray ("CFBundleURLSchemes");
    urlInnerArray.AddString ("hogehogeValue");

    // Apply editing settings to Info.plist
    plist.WriteToFile (plistPath);
  2. @sanukin39 sanukin39 created this gist Jun 19, 2016.
    67 changes: 67 additions & 0 deletions XcodeSettingsPostProcesser.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    using System.IO;
    using UnityEngine;
    using UnityEditor;
    using UnityEditor.iOS.Xcode;
    using UnityEditor.Callbacks;
    using System.Collections;

    public class XcodeSettingsPostProcesser
    {

    [PostProcessBuildAttribute (0)]
    public static void OnPostprocessBuild (BuildTarget buildTarget, string pathToBuiltProject)
    {

    // Stop processing if targe is NOT iOS
    if (buildTarget != BuildTarget.iOS)
    return;

    // Initialize PbxProject
    var projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
    PBXProject pbxProject = new PBXProject ();
    pbxProject.ReadFromFile (projectPath);
    string targetGuid = pbxProject.TargetGuidByName ("Unity-iPhone");

    // Sample of adding build property
    pbxProject.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-all_load");

    // Sample of setting build property
    pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");

    // Sample of update build property
    pbxProject.UpdateBuildProperty(targetGuid, "OTHER_LDFLAGS", new string[]{"-ObjC"}, new string[]{"-weak_framework"});

    // Sample of adding REQUIRED framwrok
    pbxProject.AddFrameworkToProject(targetGuid, "Security.framework", false);

    // Sample of adding OPTIONAL framework
    pbxProject.AddFrameworkToProject(targetGuid, "SafariServices.framework", true);

    // Sample of setting compile flags
    var guid = pbxProject.FindFileGuidByProjectPath("Classes/UI/Keyboard.mm");
    var flags = pbxProject.GetCompileFlagsForFile(targetGuid, guid);
    flags.Add("-fno-objc-arc");
    pbxProject.SetCompileFlagsForFile(targetGuid, guid, flags);

    // Apply settings
    File.WriteAllText (projectPath, pbxProject.WriteToString ());

    // Samlpe of editing Info.plist
    var plistPath = Path.Combine (pathToBuiltProject, "Info.plist");
    var plist = new PlistDocument ();
    plist.ReadFromFile (plistPath);

    // Add string setting
    plist.root.SetString ("hogehogeId", "dummyid");

    // Add URL Scheme
    var array = plist.root.CreateArray ("CFBundleURLTypes");
    var dmgDict = array.AddDict ();
    dmgDict.SetString ("CFBundleURLName", "hogehogeName");
    var dmgInnerArray = dmgDict.CreateArray ("CFBundleURLSchemes");
    dmgInnerArray.AddString ("hogehogeValue");

    // Apply editing settings to Info.plist
    plist.WriteToFile (plistPath);
    }
    }