Unity 打xcode包,自动添加权限,依赖库。。。

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;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值