using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.iOS.Xcode;
using UnityEditor.Callbacks;
using System.IO;
using System.Text;
public class SSIOSBuildSetting
{
//脚本放到Editor文件夹下。
[PostProcessBuild]
static void OnPostprocessBuild(BuildTarget target, string pathToBuildProject)
{
string unityEditorAssetPath = Application.dataPath;
if (target != BuildTarget.iOS)
{
Debug.LogWarning("Target is not iPhone. XcodePostProcess will not run");
return;
}
ModifyProj(pathToBuildProject);
SetPlist(pathToBuildProject);
}
public static void ModifyProj(string pathToBuildProject)
{
string _projPath = PBXProject.GetPBXProjectPath(pathToBuildProject);
PBXProject _pbxProj = new PBXProject();
_pbxProj.ReadFromString(File.ReadAllText(_projPath));
string _targetGuid = _pbxProj.TargetGuidByName("Unity-iPhone");
_pbxProj.AddFrameworkToProject(_targetGuid, Utf8string("AdSupport.framework"), true);
_pbxProj.AddFrameworkToProject(_targetGuid, Utf8string("CoreTelephony.framework"), true);
_pbxProj.AddFrameworkToProject(_targetGuid, Utf8string("libc++.tbd"), true);
_pbxProj.AddFrameworkToProject(_targetGuid, Utf8string("libz.tbd"), true);
//*******************************添加framework*******************************//
//_pbxProj.AddFrameworkToProject(_targetGuid, "StoreKit.framework", true);
//*******************************添加tbd*******************************//
// _pbxProj.AddFileToBuild(_targetGuid, _pbxProj.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));
//*******************************设置buildsetting*******************************//
//_pbxProj.SetBuildProperty(_targetGuid, "CODE_SIGN_IDENTITY", code_sign_identity);
_pbxProj.SetBuildProperty(_targetGuid, "ENABLE_BITCODE", "YES");
_pbxProj.SetBuildProperty(_targetGuid, "DEVELOPMENT_TEAM", "JK62X52E5W");
_pbxProj.SetBuildProperty(_targetGuid, "ARCHS", "$(ARCHS_STANDARD)");
File.WriteAllText(_projPath, _pbxProj.WriteToString());
}
static void SetPlist(string pathToBuildProject)
{
string _plistPath = pathToBuildProject + "/Info.plist";
PlistDocument _plist = new PlistDocument();
_plist.ReadFromString(File.ReadAllText(_plistPath));
PlistElementDict _rootDic = _plist.root;
//_rootDic.SetString("View controller-based status bar appearance", "NO");
//_rootDic.SetString("CFBundleDisplayName", "StellarSails");
//_rootDic.SetString("CFBundleLocalizations", "en");
//string PlistAdd = @"
// <key>CFBundleLocalizations</key>
// <array>
// <string>en</string>
// <string>zh_CN</string>
// </array>";
//_rootDic.CreateArray("Localizations");
_rootDic.SetString("CFBundleVersion", "1.0");
_rootDic.SetBoolean("Application has localized display name", true);
_rootDic.SetString(Utf8string("NSPhotoLibraryAddUsageDescription"), "保存照片需要相册权限");
_rootDic.SetString(Utf8string("NSPhotoLibraryUsageDescription"), "使用照片需要相册权限");
_rootDic.SetString(Utf8string("NSLocationUsageDescription"), "使用定位权限");
_rootDic.SetString(Utf8string("NSLocationWhenInUseUsageDescription"), "使用定位在应用启动期间权限");
File.WriteAllText(_plistPath, _plist.WriteToString());
}
static string Utf8string(string s)
{
UTF8Encoding.UTF8.GetString(UTF8Encoding.UTF8.GetBytes(s));
return s;
}
}