static void EditInfoPlist(string filePath) { string path = filePath + "/Info.plist"; PlistDocument plistDocument = new PlistDocument(); plistDocument.ReadFromFile(path); PlistElementDict dict = plistDocument.root.AsDict(); PlistElementDict securityDic = dict.CreateDict("NSAppTransportSecurity"); securityDic.SetBoolean("NSAllowsArbitraryLoads", true); dict.SetString("NSLocationAlwaysUsageDescription", "NSLocationAlwaysUsageDescription"); dict.SetString("NSPhotoLibraryUsageDescription", "NSPhotoLibraryUsageDescription"); dict.SetString("NSCameraUsageDescription", "NSCameraUsageDescription"); dict.SetString("NSCalendarsUsageDescription", "NSCalendarsUsageDescription"); plistDocument.WriteToFile(path); }
private static void UpdatePlist() { string plistPath = _path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; rootDict.SetString("NSLocationAlwaysUsageDescription", "We use access to location always responsibly"); rootDict.SetString("NSLocationWhenInUseUsageDescription", "We use access to location when in use responsibly"); rootDict.SetBoolean("UIViewControllerBasedStatusBarAppearance", false); rootDict.CreateArray("UIBackgroundModes").AddString("remote-notification"); rootDict.CreateDict("NSAppTransportSecurity").SetBoolean("NSAllowsArbitraryLoads", true); File.WriteAllText(plistPath, plist.WriteToString()); }
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) { if (buildTarget == BuildTarget.iOS) { //get plist string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); //get root PlistElementDict rootDict = plist.root; rootDict.CreateDict("NSMicrophoneUsageDescription"); rootDict.SetString("NSMicrophoneUsageDescription", "Record you own voice as the beat"); File.WriteAllText(plistPath, plist.WriteToString()); } }
private static T GetOrCreate <T>(this PlistElementDict dict, string key) { var values = dict.values.Where(x => x.Key == key).ToArray(); if (values != null && values.Length != 0) { return((T)Convert.ChangeType(values [0].Value, typeof(T))); } if (typeof(T) == typeof(PlistElementDict)) { return((T)Convert.ChangeType(dict.CreateDict(key), typeof(T))); } if (typeof(T) == typeof(PlistElementArray)) { return((T)Convert.ChangeType(dict.CreateArray(key), typeof(T))); } return(default(T)); }
private static void OnPostprocessBuild(BuildTarget target, string pathToBuildProject) { AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); string _projPath = PBXProject.GetPBXProjectPath(pathToBuildProject); PBXProject project = new PBXProject(); project.ReadFromString(File.ReadAllText(_projPath)); string targetGuid = project.TargetGuidByName("Unity-iPhone"); project.AddFrameworkToProject(targetGuid, "CFNetwork.framework", false); project.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false); project.AddFrameworkToProject(targetGuid, "Security.framework", false); project.AddFrameworkToProject(targetGuid, "SystemConfiguration.framework", false); project.AddFrameworkToProject(targetGuid, "Security.framework", false); project.AddFrameworkToProject(targetGuid, "AdSupport.framework", false); project.AddFrameworkToProject(targetGuid, "CoreLocation.framework", false); project.AddFileToBuild(targetGuid, project.AddFile("usr/lib/libc++.tbd", "libc++.tbd", PBXSourceTree.Sdk)); project.AddFileToBuild(targetGuid, project.AddFile("usr/lib/libsqlite3.0.tbd", "libsqlite3.0.tbd", PBXSourceTree.Sdk)); project.AddFileToBuild(targetGuid, project.AddFile("usr/lib/libz.tbd", "libz.tbd", PBXSourceTree.Sdk)); project.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); project.SetBuildProperty(targetGuid, "LOCATION_UPDATES", "YES"); project.WriteToFile(_projPath); // plist string plistPath = pathToBuildProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; PlistElementDict dictTmp = rootDict.CreateDict("NSAppTransportSecurity"); dictTmp.SetBoolean("NSAllowsArbitraryLoads", true); // 保存plist plist.WriteToFile(plistPath); Log.Debug("完成IOS工程配置"); }
static void SetPlist(string pathToBuildProject) { string _plistPath = pathToBuildProject + "/Info.plist"; MonoBehaviour.print("plist path:" + _plistPath); PlistDocument _plist = new PlistDocument(); _plist.ReadFromString(File.ReadAllText(_plistPath)); PlistElementDict _rootDic = _plist.root; // Add value of NSAppTransportSecurity in Xcode plist var atsKey = "NSAppTransportSecurity"; PlistElementDict dictTmp = _rootDic.CreateDict(atsKey); dictTmp.SetBoolean("NSAllowsArbitraryLoads", true); File.WriteAllText(_plistPath, _plist.WriteToString()); }
private void AddDictionaryData(PlistElementDict elementDict, IDictionary dictionary) { foreach (DictionaryEntry entry in dictionary) { if (entry.Value is ArrayList arrayList) { PlistElementArray elementArray = elementDict.CreateArray(entry.Key.ToString()); AddArrayData(elementArray, arrayList); } else if (entry.Value is IDictionary dic) { PlistElementDict eDict = elementDict.CreateDict(entry.Key.ToString()); AddDictionaryData(eDict, dic); } else { SetDataForKey(entry.Key, entry.Value, elementDict); } } }
static void EditorPlist(string _pathToBuiltProject) { // 修改 plist string plistPath = Path.Combine(_pathToBuiltProject, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; // 一些权限声明 rootDict.SetString("NSCameraUsageDescription", "我们需要使用摄像头权限"); PlistElementDict tempFtxUrl = rootDict.CreateDict("FTXPluginsParams"); tempFtxUrl.SetString("appId", "328"); tempFtxUrl.SetString("channelId", "10066"); tempFtxUrl.SetBoolean("debug", true); File.WriteAllText(plistPath, plist.WriteToString()); }
public static void DisableAllowArbitraryLoads(BuildTarget buildTarget, string pathToBuiltProject) { if (buildTarget == BuildTarget.iOS) { // Get plist string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; PlistElementDict appTransportSecurity = rootDict.CreateDict("NSAppTransportSecurity"); // enable app transport appTransportSecurity.SetBoolean("NSAllowsArbitraryLoads", false); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); } }
public static void OnPostProcessBuild(BuildTarget target, string pathToBuildProject) { if (target == BuildTarget.iOS) { // get plist string plistPath = pathToBuildProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); PlistElementDict allowsDict = plist.root.CreateDict("NSAppTransportSecurity"); allowsDict.SetBoolean("NSAllowsArbitraryLoads", true); PlistElementDict exceptionsDict = allowsDict.CreateDict("NSExceptionDomains"); PlistElementDict domainDict = exceptionsDict.CreateDict("antonkanin.com"); domainDict.SetBoolean("NSExceptionAllowsInsecureHTTPLoads", true); domainDict.SetBoolean("NSIncludesSubdomains", true); // write to file plist.WriteToFile(plistPath); } }
//在info.plist中添加 infoPlistSet private static void AddInfoPlistSet(MOBXCodeEditorModel xcodeModel,PlistElementDict plistElements) { Hashtable infoPlistSets = xcodeModel.infoPlistSet; foreach (string key in infoPlistSets.Keys) { var value = infoPlistSets[key]; if(value.GetType().Equals(typeof(string))) { plistElements.SetString (key,(string)value); } else if(value.GetType().Equals(typeof(Hashtable))) { Hashtable temp = (Hashtable)value; PlistElementDict dict = plistElements.CreateDict (key); foreach (string tempKey in temp.Keys) { //暂时只支持1层dict dict.SetString (tempKey,(string)temp[tempKey]); } } } }
private static void UpdateIOSPlist(string path, Yodo1AdSettings settings) { string plistPath = Path.Combine(path, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); //Get Root PlistElementDict rootDict = plist.root; PlistElementDict transportSecurity = rootDict.CreateDict("NSAppTransportSecurity"); transportSecurity.SetBoolean("NSAllowsArbitraryLoads", true); //Set AppLovinSdkKey rootDict.SetString("AppLovinSdkKey", Yodo1EditorConstants.DEFAULT_APPLOVIN_SDK_KEY); //Set AdMob APP Id if (settings.iOSSettings.GlobalRegion) { rootDict.SetString("GADApplicationIdentifier", settings.iOSSettings.AdmobAppID); } PlistElementString privacy = (PlistElementString)rootDict["NSLocationAlwaysUsageDescription"]; if (privacy == null) { rootDict.SetString("NSLocationAlwaysUsageDescription", "Some ad content may require access to the location for an interactive ad experience."); } PlistElementString privacy1 = (PlistElementString)rootDict["NSLocationWhenInUseUsageDescription"]; if (privacy1 == null) { rootDict.SetString("NSLocationWhenInUseUsageDescription", "Some ad content may require access to the location for an interactive ad experience."); } File.WriteAllText(plistPath, plist.WriteToString()); }
//设置plist private static void SetPlist(PBXProject proj, PlistElementDict node, Hashtable arg) { if (arg != null) { foreach (DictionaryEntry i in arg) { string key = i.Key.ToString(); object val = i.Value; var vType = i.Value.GetType(); if (vType == typeof(string)) { node.SetString(key, (string)val); } else if (vType == typeof(bool)) { node.SetBoolean(key, (bool)val); } else if (vType == typeof(double)) { int v = int.Parse(val.ToString()); node.SetInteger(key, v); } else if (vType == typeof(ArrayList)) { var t = node.CreateArray(key); var array = val as ArrayList; SetPlist(proj, t, array); } else if (vType == typeof(Hashtable)) { var t = node.CreateDict(key); var table = val as Hashtable; SetPlist(proj, t, table); } } } }
private void GenerateIOSAirshipConfig() { string plistPath = Path.Combine(Application.dataPath, "Plugins/iOS/AirshipConfig.plist"); if (File.Exists(plistPath)) { File.Delete(plistPath); } PlistDocument plist = new PlistDocument(); PlistElementDict rootDict = plist.root; if (!String.IsNullOrEmpty(ProductionAppKey) && !String.IsNullOrEmpty(ProductionAppSecret)) { rootDict.SetString("productionAppKey", ProductionAppKey); rootDict.SetString("productionAppSecret", ProductionAppSecret); rootDict.SetInteger("productionLogLevel", IOSLogLevel(ProductionLogLevel)); } if (!String.IsNullOrEmpty(DevelopmentAppKey) && !String.IsNullOrEmpty(DevelopmentAppSecret)) { rootDict.SetString("developmentAppKey", DevelopmentAppKey); rootDict.SetString("developmentAppSecret", DevelopmentAppSecret); rootDict.SetInteger("developmentLogLevel", IOSLogLevel(DevelopmentLogLevel)); } rootDict.SetBoolean("inProduction", InProduction); PlistElementDict customConfig = rootDict.CreateDict("customConfig"); customConfig.SetBoolean("notificationPresentationOptionAlert", NotificationPresentationOptionAlert); customConfig.SetBoolean("notificationPresentationOptionBadge", NotificationPresentationOptionBadge); customConfig.SetBoolean("notificationPresentationOptionSound", NotificationPresentationOptionSound); File.WriteAllText(plistPath, plist.WriteToString()); }
void SetCeliaOverseaSDK() { string path = GetXcodeProjectPath(option.PlayerOption.locationPathName); string projPath = PBXProject.GetPBXProjectPath(path); PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string target = proj.TargetGuidByName("Unity-iPhone"); // BuildSetting修改 proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC"); proj.SetBuildProperty(target, "EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE", "YES"); //FB需要 proj.SetBuildProperty(target, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES"); //FB需要 #region 添加XCode引用的Framework // SDK依赖 --AIHelp proj.AddFrameworkToProject(target, "libsqlite3.tbd", false); proj.AddFrameworkToProject(target, "libresolv.tbd", false); proj.AddFrameworkToProject(target, "WebKit.framework", false); // SDK依赖 --Google proj.AddFrameworkToProject(target, "LocalAuthentication.framework", false); proj.AddFrameworkToProject(target, "SafariServices.framework", false); proj.AddFrameworkToProject(target, "AuthenticationServices.framework", false); proj.AddFrameworkToProject(target, "SystemConfiguration.framework", false); // SDK依赖 --Apple proj.AddFrameworkToProject(target, "storekit.framework", false); proj.AddFrameworkToProject(target, "AuthenticationServices.framework", false); proj.AddFrameworkToProject(target, "gamekit.framework", false); // SDK依赖 --Adjust proj.AddFrameworkToProject(target, "AdSupport.framework", false); proj.AddFrameworkToProject(target, "iAd.framework", false); //EmbedFrameworks --Add to Embedded Binaries string defaultLocationInProj = "Plugins/iOS/SDK"; string[] frameworkNames = { "FaceBookSDK/FBSDKCoreKit.framework", "FaceBookSDK/FBSDKLoginKit.framework", "FaceBookSDK/FBSDKShareKit.framework", "AdjustSDK/AdjustSdk.framework" }; foreach (var str in frameworkNames) { string framework = Path.Combine(defaultLocationInProj, str); string fileGuid = proj.AddFile(framework, "Frameworks/" + framework, PBXSourceTree.Sdk); PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid); } proj.SetBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks"); #endregion 添加XCode引用的Framework string plistPath = Path.Combine(path, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); PlistElementDict rootDict = plist.root; #region 修改Xcode工程Info.plist /* 从iOS9开始所有的app对外http协议默认要求改成https 若需要添加http协议支持需要额外添加*/ // Add value of NSAppTransportSecurity in Xcode plist PlistElementDict dictTmp = rootDict.CreateDict("NSAppTransportSecurity"); dictTmp.SetBoolean("NSAllowsArbitraryLoads", true); //AIHelp-权限配置 rootDict.SetString("NSCameraUsageDescription", "是否允许访问相机?"); rootDict.SetString("NSMicrophoneUsageDescription", "是否允许使用麦克风?"); rootDict.SetString("NSPhotoLibraryAddUsageDescription", "是否允许添加照片?"); rootDict.SetString("NSMicrophoneUsageDescription", "是否允许访问相册?"); rootDict.SetString("NSLocationUsageDescription", "App需要您的同意,才能访问位置"); rootDict.SetString("NSLocationWhenInUseUsageDescription", "App需要您的同意,才能在使用期间访问位置"); rootDict.SetString("NSLocationAlwaysUsageDescription", "App需要您的同意,才能始终访问位置"); rootDict.SetString("CFBundleDevelopmentRegion", "zh_TW"); //rootDict.SetString("CFBundleVersion", "1"); // SDK相关参数设置 rootDict.SetString("FacebookAppID", "949004278872387"); rootDict.SetString("GoogleClientID", "554619719418-0hdrkdprcsksigpldvtr9n5lu2lvt5kn.apps.googleusercontent.com"); rootDict.SetString("FacebookAppDisplayName", "少女的王座"); rootDict.SetString("AIHelpAppID", "elextech_platform_15ce9b10-f784-4ab5-8ee4-45efab40bd6a"); rootDict.SetString("AIHelpAppKey", "ELEXTECH_app_50dd4661c57843778d850769a02f8a09"); rootDict.SetString("AIHelpDomain", "*****@*****.**"); rootDict.SetString("AdjustAppToken", "1k2jm7bpansw"); rootDict.SetString("AdjustAppSecret", "1,750848352-1884995334-181661496-1073918938"); //文件共享 rootDict.SetBoolean("UIFileSharingEnabled", true); // Set encryption usage boolean string encryptKey = "ITSAppUsesNonExemptEncryption"; rootDict.SetBoolean(encryptKey, false); // remove exit on suspend if it exists.ios13新增 string exitsOnSuspendKey = "UIApplicationExitsOnSuspend"; if (rootDict.values.ContainsKey(exitsOnSuspendKey)) { rootDict.values.Remove(exitsOnSuspendKey); } // URL types配置 PlistElementArray URLTypes = rootDict.CreateArray("CFBundleURLTypes"); //Facebook PlistElementDict typeRoleFB = URLTypes.AddDict(); typeRoleFB.SetString("CFBundleTypeRole", "Editor"); PlistElementArray urlSchemeFB = typeRoleFB.CreateArray("CFBundleURLSchemes"); urlSchemeFB.AddString("fb949004278872387"); //Google PlistElementDict typeRole = URLTypes.AddDict(); typeRole.SetString("CFBundleTypeRole", "Editor"); typeRole.SetString("CFBundleURLName", "com.googleusercontent.apps.554619719418-0hdrkdprcsksigpldvtr9n5lu2lvt5kn"); PlistElementArray urlScheme = typeRole.CreateArray("CFBundleURLSchemes"); urlScheme.AddString("com.googleusercontent.apps.554619719418-0hdrkdprcsksigpldvtr9n5lu2lvt5kn"); // LSApplicationQueriesSchemes配置 PlistElementArray LSApplicationQueriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes"); // facebook接入配置 LSApplicationQueriesSchemes.AddString("fbapi"); LSApplicationQueriesSchemes.AddString("fb-messenger-share-api"); LSApplicationQueriesSchemes.AddString("fbauth2"); LSApplicationQueriesSchemes.AddString("fbshareextension"); // Line接入配置 LSApplicationQueriesSchemes.AddString("lineauth"); LSApplicationQueriesSchemes.AddString("line3rdp.$(APP_IDENTIFIER)"); LSApplicationQueriesSchemes.AddString("line"); // 文件追加 var fileName = "GoogleService-Info.plist"; var filePath = Path.Combine("Assets/Plugins/iOS/SDK/FCM/", fileName); File.Copy(filePath, Path.Combine(option.PlayerOption.locationPathName, "GoogleService-Info.plist"), true); proj.AddFileToBuild(target, proj.AddFile(fileName, fileName, PBXSourceTree.Source)); #endregion 修改Xcode工程Info.plist // Capabilitise添加 var entitlementsFileName = "tw.entitlements"; var entitlementsFilePath = Path.Combine("Assets/Plugins/iOS/SDK/", entitlementsFileName); File.Copy(entitlementsFilePath, Path.Combine(option.PlayerOption.locationPathName, entitlementsFileName), true); proj.AddFileToBuild(target, proj.AddFile(entitlementsFileName, entitlementsFileName, PBXSourceTree.Source)); proj.AddCapability(target, PBXCapabilityType.InAppPurchase, entitlementsFileName); proj.AddCapability(target, PBXCapabilityType.GameCenter); proj.AddCapability(target, PBXCapabilityType.PushNotifications, entitlementsFileName); plist.WriteToFile(plistPath); proj.WriteToFile(projPath); File.WriteAllText(projPath, proj.WriteToString()); }
private static void EditPList(string path) { string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; PlistElementArray shortcutItems = rootDict.CreateArray("UIApplicationShortcutItems"); { PlistElementDict item0 = shortcutItems.AddDict(); { item0.SetString("UIApplicationShortcutItemIconType", "UIApplicationShortcutIconTypeUpdate"); item0.SetString("UIApplicationShortcutItemTitle", "查看更新"); item0.SetString("UIApplicationShortcutItemSubtitle", "当前版本号 v0.0.1.0"); item0.SetString("UIApplicationShortcutItemType", "com.shandagames.Demo3DTouch.Update"); PlistElementDict userInfo = item0.CreateDict("UIApplicationShortcutItemUserInfo"); { userInfo.SetString("UnityGameObject", "UnityInterface"); userInfo.SetString("UnityMethod", "VisitWebsite"); userInfo.SetString("UnityParam", "https://itunes.apple.com/cn/app/%E7%A5%9E%E6%97%A0%E6%9C%88-%E4%B8%8E%E5%88%9D%E9%9F%B3%E6%9C%AA%E6%9D%A5%E4%B8%80%E8%B5%B7%E5%86%92%E9%99%A9%E5%90%A7/id1248272294?mt=8"); } } PlistElementDict item1 = shortcutItems.AddDict(); { item1.SetString("UIApplicationShortcutItemIconType", "UIApplicationShortcutIconTypeShare"); item1.SetString("UIApplicationShortcutItemTitle", "分享游戏"); item1.SetString("UIApplicationShortcutItemSubtitle", "与好友一起享受快乐"); item1.SetString("UIApplicationShortcutItemType", "com.shandagames.Demo3DTouch.Share"); PlistElementDict userInfo = item1.CreateDict("UIApplicationShortcutItemUserInfo"); { userInfo.SetString("UnityGameObject", "UnityInterface"); userInfo.SetString("UnityMethod", "ShareGame"); userInfo.SetString("UnityParam", "123"); } } PlistElementDict item2 = shortcutItems.AddDict(); { item2.SetString("UIApplicationShortcutItemIconType", "UIApplicationShortcutIconTypePlay"); item2.SetString("UIApplicationShortcutItemTitle", "快速游戏"); item2.SetString("UIApplicationShortcutItemSubtitle", "与其他玩家一较高下"); item2.SetString("UIApplicationShortcutItemType", "com.shandagames.Demo3DTouch.Play"); PlistElementDict userInfo = item2.CreateDict("UIApplicationShortcutItemUserInfo"); { userInfo.SetString("UnityGameObject", "UnityInterface"); userInfo.SetString("UnityMethod", "LoadScene"); userInfo.SetString("UnityParam", "QuickGame"); } } PlistElementDict item3 = shortcutItems.AddDict(); { item3.SetString("UIApplicationShortcutItemIconType", "UIApplicationShortcutIconTypeHome"); item3.SetString("UIApplicationShortcutItemTitle", "打开游戏官网"); item3.SetString("UIApplicationShortcutItemSubtitle", "moon.sdo.com"); item3.SetString("UIApplicationShortcutItemType", "com.shandagames.Demo3DTouch.Home"); PlistElementDict userInfo = item3.CreateDict("UIApplicationShortcutItemUserInfo"); { userInfo.SetString("UnityGameObject", "UnityInterface"); userInfo.SetString("UnityMethod", "VisitWebsite"); userInfo.SetString("UnityParam", "http://moon.sdo.com/"); } } } var urlTypes = rootDict.CreateArray("CFBundleURLTypes"); var urlDict = urlTypes.AddDict(); urlDict.SetString("CFBundleTypeRole", "Editor"); var urlInnerArray = urlDict.CreateArray("CFBundleURLSchemes"); urlInnerArray.AddString("sdgExtension"); File.WriteAllText(plistPath, plist.WriteToString()); }
private static void ChangeInfoPlist(BuildTarget buildTarget, string pathToBuiltProject) { // Get plist string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; PlistElementArray arrayDeviceCapabilities = rootDict.CreateArray("UIRequiredDeviceCapabilities"); arrayDeviceCapabilities.AddString("armv7"); rootDict.SetString("CFBundleIdentifier", Application.bundleIdentifier); rootDict.SetString("NSCameraUsageDescription", "${PRODUCT_NAME} would like to access your camera."); rootDict.SetString("NSPhotoLibraryUsageDescription", "${PRODUCT_NAME} would like to access your photos."); rootDict.SetString("FacebookDisplayName", "Bake Shop Blast"); //rootDict.SetString("FacebookAppID", BFGSettings.FacebookAppID); rootDict.SetString("CFBundleName", "Bake Shop Blast"); rootDict.SetString("BFGEnviron", "Test"); PlistElementArray urlArray = rootDict.CreateArray("CFBundleURLTypes"); PlistElementDict itemDic = urlArray.AddDict(); itemDic.SetString("CFBundleURLName", "$(PRODUCT_BUNDLE_IDENTIFIER)"); PlistElementArray itemsArray = itemDic.CreateArray("CFBundleURLSchemes"); //itemsArray.AddString("fb" + BFGSettings.FacebookAppID); itemsArray.AddString("$(PRODUCT_BUNDLE_IDENTIFIER)"); //itemsArray.AddString("com.bigfishgames.bakeshopblastuniversalf2p://"); //rootDict.SetString("UpsightAppToken", BFGSettings.UpsightAppToken); //rootDict.SetString("UpsightPublicKey", BFGSettings.UpsightPublicKey); PlistElementArray array = rootDict.CreateArray("LSApplicationQueriesSchemes"); array.AddString("com.bigfishgames.gamefinder"); array.AddString("fbauth2"); array.AddString("fb-messenger-api"); array.AddString("fbapi"); array.AddString("fbshareextension"); array.AddString("${PRODUCT_BUNDLE_IDENTIFIER}" + "://"); //crashlitics //PlistElementDict fabric = rootDict.CreateDict("Fabric"); //fabric.SetString("APIKey", BFGSettings.Fabric_APIKey); //PlistElementArray arrayKits = fabric.CreateArray("Kits"); //PlistElementDict kitInfo = arrayKits.AddDict(); //kitInfo = kitInfo.CreateDict("KitInfo"); //kitInfo.SetString("KitName","Crashlytics"); PlistElementDict transportSecurityDict = rootDict.CreateDict("NSAppTransportSecurity"); transportSecurityDict.SetBoolean("NSAllowsArbitraryLoads", true); PlistElementDict exceptionDomainsDict = transportSecurityDict.CreateDict("NSExceptionDomains"); PlistElementDict mediaDict = exceptionDomainsDict.CreateDict("media.playhaven.com"); mediaDict.SetBoolean("NSThirdPartyExceptionAllowsInsecureHTTPLoads", true); PlistElementDict upsightDict = exceptionDomainsDict.CreateDict("upsight.com"); upsightDict.SetBoolean("NSExceptionRequiresForwardSecrecy", false); upsightDict.SetBoolean("NSIncludesSubdomains", true); PlistElementDict upsightApiDict = exceptionDomainsDict.CreateDict("upsight-api.com"); upsightApiDict.SetBoolean("NSExceptionRequiresForwardSecrecy", false); upsightApiDict.SetBoolean("NSIncludesSubdomains", true); PlistElementDict akamaihdDict = exceptionDomainsDict.CreateDict("akamaihd.net"); akamaihdDict.SetBoolean("NSExceptionRequiresForwardSecrecy", false); akamaihdDict.SetBoolean("NSIncludesSubdomains", true); PlistElementDict mobileapptrackingDict = exceptionDomainsDict.CreateDict("mobileapptracking.com"); mobileapptrackingDict.SetBoolean("NSThirdPartyExceptionRequiresForwardSecrecy", false); mobileapptrackingDict.SetBoolean("NSIncludesSubdomains", true); PlistElementDict kontagentDict = exceptionDomainsDict.CreateDict("kontagent.net"); kontagentDict.SetBoolean("NSThirdPartyExceptionRequiresForwardSecrecy", false); kontagentDict.SetBoolean("NSIncludesSubdomains", true); // PlistElementDict facebookGraph = exceptionDomainsDict.CreateDict("graph.facebook.com"); // facebookGraph.SetBoolean("NSThirdPartyExceptionRequiresForwardSecrecy", false); // facebookGraph.SetBoolean("NSIncludesSubdomains", true); // PlistElementDict amazon = exceptionDomainsDict.CreateDict("rave-prod-users.s3.amazonaws.com"); // amazon.SetBoolean("NSThirdPartyExceptionRequiresForwardSecrecy", false); // amazon.SetBoolean("NSIncludesSubdomains", true); PlistElementDict kochavaDict = exceptionDomainsDict.CreateDict("kochava.com"); kochavaDict.SetBoolean("NSThirdPartyExceptionRequiresForwardSecrecy", false); kochavaDict.SetBoolean("NSIncludesSubdomains", true); PlistElementDict kontagentComDict = exceptionDomainsDict.CreateDict("kontagent.com"); kontagentComDict.SetBoolean("NSThirdPartyExceptionRequiresForwardSecrecy", false); kontagentComDict.SetBoolean("NSIncludesSubdomains", true); kontagentComDict.SetString("NSThirdPartyExceptionMinimumTLSVersion", "TLSv1.0"); PlistElementDict bigfishgamesDict = exceptionDomainsDict.CreateDict("bigfishgames.com"); bigfishgamesDict.SetBoolean("NSExceptionRequiresForwardSecrecy", false); bigfishgamesDict.SetBoolean("NSIncludesSubdomains", true); PlistElementDict apiKontagentDict = exceptionDomainsDict.CreateDict("api.geo.kontagent.net"); apiKontagentDict.SetBoolean("NSExceptionRequiresForwardSecrecy", false); apiKontagentDict.SetBoolean("NSIncludesSubdomains", true); apiKontagentDict.SetBoolean("NSExceptionAllowsInsecureHTTPLoads", true); PlistElementDict testServerDict = exceptionDomainsDict.CreateDict("test-server.upsight.com"); testServerDict.SetBoolean("NSExceptionRequiresForwardSecrecy", false); testServerDict.SetBoolean("NSIncludesSubdomains", true); testServerDict.SetBoolean("NSExceptionAllowsInsecureHTTPLoads", true); PlistElementDict testServerKontagentDict = exceptionDomainsDict.CreateDict("test-server.kontagent.com"); testServerKontagentDict.SetBoolean("NSExceptionRequiresForwardSecrecy", false); testServerKontagentDict.SetBoolean("NSIncludesSubdomains", true); testServerKontagentDict.SetBoolean("NSExceptionAllowsInsecureHTTPLoads", true); PlistElementDict jquerryDict = exceptionDomainsDict.CreateDict("code.jquery.com"); jquerryDict.SetBoolean("NSExceptionRequiresForwardSecrecy", false); jquerryDict.SetBoolean("NSIncludesSubdomains", true); jquerryDict.SetBoolean("NSExceptionAllowsInsecureHTTPLoads", true); PlistElementDict mobileApi = exceptionDomainsDict.CreateDict("mobile-api.geo.kontagent.net"); mobileApi.SetBoolean("NSExceptionRequiresForwardSecrecy", false); mobileApi.SetBoolean("NSIncludesSubdomains", true); mobileApi.SetBoolean("NSExceptionAllowsInsecureHTTPLoads", true); PlistElementDict apiFB = exceptionDomainsDict.CreateDict("facebook.com"); apiFB.SetBoolean("NSExceptionRequiresForwardSecrecy", false); apiFB.SetBoolean("NSIncludesSubdomains", true); apiFB.SetBoolean("NSExceptionAllowsInsecureHTTPLoads", true); PlistElementDict apiRaveIcon = exceptionDomainsDict.CreateDict("rave-prod-users.s3.amazonaws.com"); apiRaveIcon.SetBoolean("NSExceptionRequiresForwardSecrecy", false); apiRaveIcon.SetBoolean("NSIncludesSubdomains", true); apiRaveIcon.SetBoolean("NSExceptionAllowsInsecureHTTPLoads", true); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); }
static void ModifyPlist(string path) { // Info.plist string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(path: plistPath)); // ROOT PlistElementDict rootDict = plist.root; PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes"); // Add URLScheme For Wechat PlistElementDict wxUrl = urlTypes.AddDict(); wxUrl.SetString("CFBundleTypeRole", "Editor"); wxUrl.SetString("CFBundleURLName", "weixin"); wxUrl.SetString("CFBundleURLSchemes", val: Config.wechatAppId); PlistElementArray wxUrlScheme = wxUrl.CreateArray("CFBundleURLSchemes"); wxUrlScheme.AddString(val: Config.wechatAppId); // Add URLScheme For jiguang PlistElementDict jgUrl = urlTypes.AddDict(); jgUrl.SetString("CFBundleTypeRole", "Editor"); jgUrl.SetString("CFBundleURLName", "jiguang"); jgUrl.SetString("CFBundleURLSchemes", val: "jiguang-" + Config.jgAppKey); PlistElementArray jgUrlScheme = jgUrl.CreateArray("CFBundleURLSchemes"); jgUrlScheme.AddString(val: "jiguang-" + Config.jgAppKey); // Add URLScheme For unityconnect PlistElementDict appUrl = urlTypes.AddDict(); appUrl.SetString("CFBundleTypeRole", "Editor"); appUrl.SetString("CFBundleURLName", ""); appUrl.SetString("CFBundleURLSchemes", val: "unityconnect"); PlistElementArray appUrlScheme = appUrl.CreateArray("CFBundleURLSchemes"); appUrlScheme.AddString(val: "unityconnect"); // 白名单 for wechat PlistElementArray queriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes"); queriesSchemes.AddString("wechat"); queriesSchemes.AddString("weixin"); queriesSchemes.AddString(val: Config.wechatAppId); // HTTP 设置 const string atsKey = "NSAppTransportSecurity"; PlistElementDict dictTmp = rootDict.CreateDict(key: atsKey); dictTmp.SetBoolean("NSAllowsArbitraryLoads", true); PlistElementArray backModes = rootDict.CreateArray("UIBackgroundModes"); backModes.AddString("remote-notification"); // 出口合规信息 rootDict.SetBoolean("ITSAppUsesNonExemptEncryption", false); // remove exit on suspend if it exists. string exitsOnSuspendKey = "UIApplicationExitsOnSuspend"; if (rootDict.values.ContainsKey(exitsOnSuspendKey)) { rootDict.values.Remove(exitsOnSuspendKey); } // 写入 File.WriteAllText(path: plistPath, plist.WriteToString()); }
private static void ModifyPlist(string plistPath) { // Create PlistDocument PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; // Clear existing Appboy Unity dictionary if (rootDict["Appboy"] != null) { rootDict["Appboy"]["Unity"] = null; } // Add Appboy Unity keys to Plist if (AppboyConfig.IOSAutomatesIntegration) { // The Appboy Unity dictionary PlistElementDict appboyUnityDict = (rootDict["Appboy"] == null) ? rootDict.CreateDict("Appboy").CreateDict("Unity") : rootDict["Appboy"].AsDict().CreateDict("Unity"); // Add iOS automated integration build keys to Plist if (ValidateField(ABKUnityApiKey, AppboyConfig.ApiKey, "Appboy will not be initialized.")) { appboyUnityDict.SetString(ABKUnityApiKey, AppboyConfig.ApiKey.Trim()); } appboyUnityDict.SetBoolean(ABKUnityAutomaticPushIntegrationKey, AppboyConfig.IOSIntegratesPush); appboyUnityDict.SetBoolean(ABKUnityDisableAutomaticPushRegistrationKey, AppboyConfig.IOSDisableAutomaticPushRegistration); if (AppboyConfig.IOSPushIsBackgroundEnabled) { PlistElementArray backgroundModes = (rootDict["UIBackgroundModes"] == null) ? rootDict.CreateArray("UIBackgroundModes") : rootDict["UIBackgroundModes"].AsArray(); backgroundModes.AddString("remote-notification"); } // Set push listeners if (ValidateListenerFields(ABKUnityPushReceivedGameObjectKey, AppboyConfig.IOSPushReceivedGameObjectName, ABKUnityPushReceivedCallbackKey, AppboyConfig.IOSPushReceivedCallbackMethodName)) { appboyUnityDict.SetString(ABKUnityPushReceivedGameObjectKey, AppboyConfig.IOSPushReceivedGameObjectName.Trim()); appboyUnityDict.SetString(ABKUnityPushReceivedCallbackKey, AppboyConfig.IOSPushReceivedCallbackMethodName.Trim()); } if (ValidateListenerFields(ABKUnityPushOpenedGameObjectKey, AppboyConfig.IOSPushOpenedGameObjectName, ABKUnityPushOpenedCallbackKey, AppboyConfig.IOSPushOpenedCallbackMethodName)) { appboyUnityDict.SetString(ABKUnityPushOpenedGameObjectKey, AppboyConfig.IOSPushOpenedGameObjectName.Trim()); appboyUnityDict.SetString(ABKUnityPushOpenedCallbackKey, AppboyConfig.IOSPushOpenedCallbackMethodName.Trim()); } // Set in-app message listener if (ValidateListenerFields(ABKUnityInAppMessageGameObjectKey, AppboyConfig.IOSInAppMessageGameObjectName, ABKUnityInAppMessageCallbackKey, AppboyConfig.IOSInAppMessageCallbackMethodName)) { appboyUnityDict.SetString(ABKUnityInAppMessageGameObjectKey, AppboyConfig.IOSInAppMessageGameObjectName.Trim()); appboyUnityDict.SetString(ABKUnityInAppMessageCallbackKey, AppboyConfig.IOSInAppMessageCallbackMethodName.Trim()); appboyUnityDict.SetBoolean(ABKUnityHandleInAppMessageDisplayKey, AppboyConfig.IOSDisplayInAppMessages); } // Set feed listener if (ValidateListenerFields(ABKUnityFeedGameObjectKey, AppboyConfig.IOSFeedGameObjectName, ABKUnityFeedCallbackKey, AppboyConfig.IOSFeedCallbackMethodName)) { appboyUnityDict.SetString(ABKUnityFeedGameObjectKey, AppboyConfig.IOSFeedGameObjectName.Trim()); appboyUnityDict.SetString(ABKUnityFeedCallbackKey, AppboyConfig.IOSFeedCallbackMethodName.Trim()); } } // Write changes to XCode project and Info.plist File.WriteAllText(plistPath, plist.WriteToString()); }
private static void UpdateIOSPlist(string path, Yodo1AdSettings settings) { string plistPath = Path.Combine(path, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); //Get Root PlistElementDict rootDict = plist.root; PlistElementDict transportSecurity = rootDict.CreateDict("NSAppTransportSecurity"); transportSecurity.SetBoolean("NSAllowsArbitraryLoads", true); //Set SKAdNetwork PlistElementArray skItem = rootDict.CreateArray("SKAdNetworkItems"); foreach (string sk in mSKAdNetworkId) { PlistElementDict skDic = skItem.AddDict(); skDic.SetString("SKAdNetworkIdentifier", sk); } //Set AppLovinSdkKey rootDict.SetString("AppLovinSdkKey", Yodo1EditorConstants.DEFAULT_APPLOVIN_SDK_KEY); //Set AdMob APP Id if (settings.iOSSettings.GlobalRegion) { rootDict.SetString("GADApplicationIdentifier", settings.iOSSettings.AdmobAppID); } PlistElementString privacy = (PlistElementString)rootDict["NSLocationAlwaysUsageDescription"]; if (privacy == null) { rootDict.SetString("NSLocationAlwaysUsageDescription", "Some ad content may require access to the location for an interactive ad experience."); } PlistElementString privacy1 = (PlistElementString)rootDict["NSLocationWhenInUseUsageDescription"]; if (privacy1 == null) { rootDict.SetString("NSLocationWhenInUseUsageDescription", "Some ad content may require access to the location for an interactive ad experience."); } PlistElementString attPrivacy = (PlistElementString)rootDict["NSUserTrackingUsageDescription"]; if (attPrivacy == null) { rootDict.SetString("NSUserTrackingUsageDescription", "This identifier will be used to deliver personalized ads to you."); } PlistElementString calendarsPrivacy = (PlistElementString)rootDict["NSCalendarsUsageDescription"]; if (calendarsPrivacy == null) { rootDict.SetString("NSCalendarsUsageDescription", "The application wants to use your calendar. Is that allowed?"); } File.WriteAllText(plistPath, plist.WriteToString()); }
static void ChangePlist(string pathToBuildProject) { string path = string.Format("{0}/Info.plist", pathToBuildProject); PlistDocument doc = new PlistDocument(); doc.ReadFromString(File.ReadAllText(path)); PlistElementDict root = doc.root; root.SetBoolean("IS_CHINA_MAINLAND", ConfigDataHelper.ChinaMainland); root.SetBoolean("IS_RELEASE", ConfigDataHelper.isRelease); // 对iOS9的影响 { PlistElementDict security = root.CreateDict("NSAppTransportSecurity"); security.SetBoolean("NSAllowsArbitraryLoads", true); } // 合规证明 { root.SetBoolean("ITSAppUsesNonExemptEncryption", false); } // GameCenter { PlistElementArray capabilities = root.CreateArray("UIRequiredDeviceCapabilities"); capabilities.AddString("armv7"); capabilities.AddString("gamekit"); } // 添加Scheme白名单 { PlistElementArray schemes = root.CreateArray("LSApplicationQueriesSchemes"); schemes.AddString("fbapi"); schemes.AddString("fbauth2"); schemes.AddString("fb-messenger-api"); } // fb { string idFacebook = "000"; //ConfigDataHelper.FacebookAppID; root.SetString("FacebookAppID", idFacebook); root.SetString("FacebookDisplayName", PlayerSettings.productName); PlistElementArray types = root.CreateArray("CFBundleURLTypes"); PlistElementDict dict = types.AddDict(); dict.SetString("CFBundleTypeRole", "Editor"); PlistElementArray schemes = dict.CreateArray("CFBundleURLSchemes"); schemes.AddString("fb" + idFacebook); } // 权限 { root.SetString("NSPhotoLibraryUsageDescription", "使用相册"); root.SetString("NSCameraUsageDescription", "使用相机"); } File.WriteAllText(path, doc.WriteToString()); }
private static void ProcessPlist(string path) { string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; //PlayerSettings.bundleIdentifier rootDict.SetString("CFBundleName", "${PRODUCT_NAME}"); rootDict.SetString("CFBundleDisplayName", "${PRODUCT_NAME}"); rootDict.SetString("CFBundleIdentifier", "$(PRODUCT_BUNDLE_IDENTIFIER)"); rootDict.SetString("CFBundleDevelopmentRegion", "China"); rootDict.SetString("CFBundleInfoDictionaryVersion", "6.0"); rootDict.SetString("CFBundleShortVersionString", "1.0.0"); rootDict.SetString("CFBundleVersion", "1.0.0"); //NSAppTransportSecurity var transportSecurity = rootDict.CreateDict("NSAppTransportSecurity"); transportSecurity.SetBoolean("NSAllowsArbitraryLoads", true); //UISupportedInterfaceOrientations var orientation = rootDict.CreateArray("UISupportedInterfaceOrientations"); orientation.AddString("UIInterfaceOrientationLandscapeRight"); orientation.AddString("UIInterfaceOrientationLandscapeLeft"); //直播所需要的声明,iOS10必须 rootDict.SetString("NSContactsUsageDescription", "App需要您的同意,才能访问通讯录"); rootDict.SetString("NSCalendarsUsageDescription", "App需要您的同意,才能访问日历"); rootDict.SetString("NSCameraUsageDescription", "App需要您的同意,才能使用相机"); rootDict.SetString("NSLocationUsageDescription", "App需要您的同意,才能访问位置"); rootDict.SetString("NSLocationWhenInUseUsageDescription", "App需要您的同意,才能在使用期间访问位置"); rootDict.SetString("NSLocationAlwaysUsageDescription", "App需要您的同意,才能始终访问位置"); rootDict.SetString("NSMicrophoneUsageDescription", "App需要您的同意,才能使用麦克风"); rootDict.SetString("NSPhotoLibraryUsageDescription", "App需要您的同意,才能访问相册"); // LSApplicationQueriesSchemes var queriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes"); queriesSchemes.AddString("mqqapi"); queriesSchemes.AddString("mqqopensdkapiV4"); queriesSchemes.AddString("mqqopensdkapiV3"); queriesSchemes.AddString("mqqopensdkapiV2"); queriesSchemes.AddString("mqqapiwallet"); queriesSchemes.AddString("mqqwpa"); queriesSchemes.AddString("mqqbrowser"); queriesSchemes.AddString("weixin"); queriesSchemes.AddString("wechat"); queriesSchemes.AddString("mqqOpensdkSSoLogin"); queriesSchemes.AddString("mqzone"); queriesSchemes.AddString("sinaweibo"); queriesSchemes.AddString("sinaweibohd"); queriesSchemes.AddString("sinaweibo"); queriesSchemes.AddString("weibosdk"); queriesSchemes.AddString("weibosdk2.5"); queriesSchemes.AddString("mqq"); queriesSchemes.AddString("mqzoneopensdk"); //CFBundleURLTypes var urlTypes = rootDict.CreateArray("CFBundleURLTypes"); //weibo var dictWeibo = urlTypes.AddDict(); dictWeibo.SetString("CFBundleTypeRole", "Editor"); dictWeibo.SetString("CFBundleURLName", "com.weibo"); var dictWeiboDic = dictWeibo.CreateArray("CFBundleURLSchemes"); dictWeiboDic.AddString("wb639535745"); //weixin var dictWeiXin = urlTypes.AddDict(); dictWeiXin.SetString("CFBundleTypeRole", "Editor"); dictWeiXin.SetString("CFBundleURLName", ""); var dictWeiXinDic = dictWeiXin.CreateArray("CFBundleURLSchemes"); dictWeiXinDic.AddString("wxb80d3faba4d24a1c"); //qq var dictQQ1 = urlTypes.AddDict(); dictQQ1.SetString("CFBundleTypeRole", "Editor"); dictQQ1.SetString("CFBundleURLName", ""); var dictQQDic1 = dictQQ1.CreateArray("CFBundleURLSchemes"); dictQQDic1.AddString("tencent1105220627"); var dictQQ2 = urlTypes.AddDict(); dictQQ2.SetString("CFBundleTypeRole", "Editor"); dictQQ2.SetString("CFBundleURLName", ""); var dictQQDic2 = dictQQ2.CreateArray("CFBundleURLSchemes"); dictQQDic2.AddString("QQ1105220627"); // 保存plist plist.WriteToFile(plistPath); }
static void ModifyPlist(string path) { // Info.plist string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(path: plistPath)); // ROOT PlistElementDict rootDict = plist.root; PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes"); // Add URLScheme For Wechat PlistElementDict wxUrl = urlTypes.AddDict(); wxUrl.SetString("CFBundleTypeRole", "Editor"); wxUrl.SetString("CFBundleURLName", "weixin"); wxUrl.SetString("CFBundleURLSchemes", val: Config.wechatAppId); PlistElementArray wxUrlScheme = wxUrl.CreateArray("CFBundleURLSchemes"); wxUrlScheme.AddString(val: Config.wechatAppId); // Add URLScheme For jiguang // 暂时注释 https://community.jiguang.cn/t/topic/33910 // PlistElementDict jgUrl = urlTypes.AddDict(); // jgUrl.SetString("CFBundleTypeRole", "Editor"); // jgUrl.SetString("CFBundleURLName", "jiguang"); // jgUrl.SetString("CFBundleURLSchemes", val: "jiguang-" + Config.jgAppKey); // PlistElementArray jgUrlScheme = jgUrl.CreateArray("CFBundleURLSchemes"); // jgUrlScheme.AddString(val: "jiguang-" + Config.jgAppKey); // Add URLScheme For unityconnect PlistElementDict appUrl = urlTypes.AddDict(); appUrl.SetString("CFBundleTypeRole", "Editor"); appUrl.SetString("CFBundleURLName", ""); appUrl.SetString("CFBundleURLSchemes", val: "unityconnect"); PlistElementArray appUrlScheme = appUrl.CreateArray("CFBundleURLSchemes"); appUrlScheme.AddString(val: "unityconnect"); // 白名单 for wechat PlistElementArray queriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes"); queriesSchemes.AddString("wechat"); queriesSchemes.AddString("weixin"); queriesSchemes.AddString(val: Config.wechatAppId); // HTTP 设置 const string atsKey = "NSAppTransportSecurity"; PlistElementDict dictTmp = rootDict.CreateDict(key: atsKey); dictTmp.SetBoolean("NSAllowsArbitraryLoads", true); PlistElementArray backModes = rootDict.CreateArray("UIBackgroundModes"); backModes.AddString("remote-notification"); // 出口合规信息 rootDict.SetBoolean("ITSAppUsesNonExemptEncryption", false); rootDict.SetString("NSCameraUsageDescription", "我们需要访问您的相机,以便您正常使用修改头像、发送图片、扫一扫等功能"); rootDict.SetString("NSPhotoLibraryUsageDescription", "我们需要访问您的相册,以便您正常使用修改头像、发送图片或者视频等功能"); rootDict.SetString("NSPhotoLibraryAddUsageDescription", "我们需要访问您的相册,以便您正常使用保存图片功能"); // rootDict.SetString("NSMicrophoneUsageDescription", "需要录制音频,是否允许此App打开麦克风?"); // remove exit on suspend if it exists. string exitsOnSuspendKey = "UIApplicationExitsOnSuspend"; if (rootDict.values.ContainsKey(exitsOnSuspendKey)) { rootDict.values.Remove(exitsOnSuspendKey); } // 写入 File.WriteAllText(plistPath, plist.WriteToString()); }
public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { if (buildTarget != BuildTarget.iOS) { Debug.LogWarning("Target is not IOS. XCodePostProcess will not run"); return; } // Create a new project object from build target string projPath = PBXProject.GetPBXProjectPath(path); PBXProject project = new PBXProject(); project.ReadFromString(File.ReadAllText(projPath)); string target = project.TargetGuidByName("Unity-iPhone"); project.AddFrameworkToProject(target, "libstdc++.6.0.9.tbd", false); project.AddFrameworkToProject(target, "libz.tbd", false); project.AddFrameworkToProject(target, "libsqlite3.tbd", false); project.AddFrameworkToProject(target, "StoreKit.framework", false); project.AddFrameworkToProject(target, "SystemConfiguration.framework", false); project.AddFrameworkToProject(target, "CoreTelephony.framework", false); project.AddFrameworkToProject(target, "QuartzCore.framework", false); project.AddFrameworkToProject(target, "Security.framework", false); // 对所有的编译配置设置选项 project.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); project.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC"); // 保存工程 project.WriteToFile(projPath); // 修改plist string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); //添加app信息到info.plist PlistElementDict rootDict = plist.root; PlistElementDict SDKDic = rootDict.CreateDict("KSSDK"); SDKDic.SetString("APPID", "100000022"); //CP填自己的appid SDKDic.SetString("APPKey", "c824619ea987f124ebbb75ef79d85196"); //CP填自己的appkey //添加分享的信息 PlistElementArray array = rootDict.CreateArray("CFBundleURLTypes"); /* * // 微信分享信息 * PlistElementDict dictWechat = array.AddDict(); * dictWechat.SetString("CFBundleURLName", "weixin"); * PlistElementArray arrayWechat = dictWechat.CreateArray("CFBundleURLSchemes"); * arrayWechat.AddString("wx21662a277bfda3a2"); //CP填自己的wxappid * * // QQ分享信息 * PlistElementDict dictQQ = array.AddDict (); * dictQQ.SetString ("CFBundleURLName", "tecnet"); * PlistElementArray arrayQQ = dictQQ.CreateArray("CFBundleURLSchemes"); * arrayQQ.AddString ("tecent222222"); //CP填自己的QQ id * * // 微博分享 * PlistElementDict dictWeibo = array.AddDict(); * dictWeibo.SetString("CFBundleURLName","weibo"); * PlistElementArray arrayWeibo = dictWeibo.CreateArray("CFBundleURLSchemes"); * arrayWeibo.AddString("wb2980459460"); //CP填写自己的微博id * * //银联信息 * PlistElementDict dictUP = array.AddDict(); * PlistElementArray arrayUP = dictUP.CreateArray ("CFBundleURLSchemes"); * arrayUP.AddString("KSUPPay"); //此值可以为任意值,但必须唯一 */ array = rootDict.CreateArray("LSApplicationQueriesSchemes"); array.AddString("weixin"); array.AddString("wechat"); array.AddString("weibosdk2.5"); array.AddString("weibosdk"); array.AddString("sinaweibo"); array.AddString("sinaweibohd"); array.AddString("mqq"); array.AddString("mqqapi"); array.AddString("mqqopensdkapiV2"); array.AddString("mqqbrowser"); // 下面字段为自有支付相关 array.AddString("uppayx1"); array.AddString("uppayx2"); array.AddString("uppayx3"); array.AddString("uppaywallet"); array.AddString("uppaysdk"); // 语音所需要的声明 rootDict.SetString("NSMicrophoneUsageDescription", "通过麦克风和其他玩家语音聊天"); // 相册所需权限 rootDict.SetString("NSPhotoLibraryAddUsageDescription", "将账号密码保存至相册中"); rootDict.SetString("Privacy - Photo Library Usage Description", "将账号密码保存至相册中"); //添加允许http访问 PlistElementDict dict3 = rootDict.CreateDict("NSAppTransportSecurity"); dict3.SetBoolean("NSAllowsArbitraryLoads", true); // save info.plist plist.WriteToFile(plistPath); EditUnityAppController(path); Debug.Log("Xcode修改完毕"); }
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { XmlNode root; XmlNodeList nodes; XmlDocument xmlDoc; XmlTextReader reader; TextWriter mfWriter; if (target == BuildTarget.WSAPlayer) { XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable()); namespaceManager.AddNamespace("x", xNameSpaceURI); namespaceManager.AddNamespace("uap", uapNameSpaceURI); namespaceManager.AddNamespace("m3", m3NameSpaceURI); // O - Checking configuration if (EngagementConfiguration.WINDOWS_CONNECTION_STRING == null) { Debug.LogError("Missing WINDOWS_CONNECTION_STRING in EngagementConfiguration"); return; } if (EditorUserBuildSettings.wsaSDK != WSASDK.UWP && EditorUserBuildSettings.wsaSDK != WSASDK.PhoneSDK81) { Debug.LogError("Only Phone8.1 and Universal10 SDKs are supported"); return; } Boolean isWP81 = (EditorUserBuildSettings.wsaSDK == WSASDK.UniversalSDK81 || EditorUserBuildSettings.wsaSDK == WSASDK.PhoneSDK81); string PackageManifest = getWP10Directory(pathToBuiltProject) + "/Package.appxmanifest"; updateAppXManifest(PackageManifest, namespaceManager, isWP81); // 2 - Patching App.Xaml.CS string appcspath = getWP10Directory(pathToBuiltProject); appcspath += "/App.xaml.cs"; string appcsString = System.IO.File.ReadAllText(appcspath); // 2-1 - Remove former patch appcsString = removeEngagementCode(appcsString); Regex rgx2 = new Regex("OnLaunched\\(.*\\)\\s*\\{(\\s*)", RegexOptions.IgnoreCase); Match match2 = rgx2.Match(appcsString); if (!match2.Success) { Debug.LogError("could not find OnLaunched in App.xaml.cs"); } // 2-2 Add initEngagement OnLaunched string r = "OnLaunched(LaunchActivatedEventArgs args)\n"; r += "\t\t{\n"; r += "\t\t\t// BEGIN_ENGAGEMENT\n"; r += "\t\t\tMicrosoft.Azure.Engagement.Unity.EngagementAgent.initEngagement(args);\n"; r += "\t\t\t// END_ENGAGEMENT\n"; appcsString = rgx2.Replace(appcsString, r); // 2-3 Add initEngagement OnActivated rgx2 = new Regex("OnActivated\\(.*\\)\\s*\\{", RegexOptions.IgnoreCase); match2 = rgx2.Match(appcsString); if (!match2.Success) { Debug.LogError("could not find OnActivated in App.xaml.cs"); } r = "OnActivated(IActivatedEventArgs args)\n"; r += "\t\t{\n"; r += "\t\t\t// BEGIN_ENGAGEMENT\n"; r += "\t\t\tMicrosoft.Azure.Engagement.Unity.EngagementAgent.initEngagementOnActivated(args);\n"; r += "\t\t\t// END_ENGAGEMENT\n"; appcsString = rgx2.Replace(appcsString, r); System.IO.File.WriteAllText(appcspath, appcsString); Debug.Log("Patching " + appcspath); string unzipResourcesDirectoryWP10 = getWP10Directory(pathToBuiltProject); string vsProjectWP10 = PlayerSettings.productName + ".csproj"; addResourcesToProject(unzipResourcesDirectoryWP10, vsProjectWP10); // 4 Patching MainPage.Xaml string mainpagexamlPath = getWP10Directory(pathToBuiltProject); mainpagexamlPath += "/MainPage.xaml"; Debug.Log("Patching " + mainpagexamlPath); reader = new XmlTextReader(mainpagexamlPath); reader.Namespaces = false; xmlDoc = new XmlDocument(); xmlDoc.Load(reader); reader.Close(); // 4-0 - Remove webview root = xmlDoc.DocumentElement; removeEngagementComments(root); // 4-1 - Create Grid as a placeholder for the webview XmlNode grid = root.SelectSingleNode("Grid"); if (grid == null) { grid = xmlDoc.CreateNode(XmlNodeType.Element, "Grid", root.NamespaceURI); grid.Attributes.Append(xmlDoc.CreateAttribute("x", "Name", xNameSpaceURI)).Value = "engagementGrid"; foreach (XmlNode c in root.ChildNodes) { grid.AppendChild(c); } root.AppendChild(grid); } else { XmlNode attr = grid.Attributes.GetNamedItem("x:Name"); if (attr == null) { grid.Attributes.Append(xmlDoc.CreateAttribute("x", "Name", xNameSpaceURI)).Value = "engagementGrid"; } } // 4-2 Adding the webview if (EngagementConfiguration.ENABLE_REACH == true) { XmlNode webviewNode = xmlDoc.CreateNode(XmlNodeType.Element, "WebView", root.NamespaceURI); webviewNode.Attributes.Append(xmlDoc.CreateAttribute("x", "Name", xNameSpaceURI)).Value = "engagement_notification_content"; webviewNode.Attributes.Append(xmlDoc.CreateAttribute("Visibility")).Value = "Collapsed"; webviewNode.Attributes.Append(xmlDoc.CreateAttribute("Height")).Value = "80"; webviewNode.Attributes.Append(xmlDoc.CreateAttribute("HorizontalAlignment")).Value = "Stretch"; webviewNode.Attributes.Append(xmlDoc.CreateAttribute("VerticalAlignment")).Value = "Top"; appendChildWithEngagementComment(xmlDoc, grid, webviewNode); webviewNode = xmlDoc.CreateNode(XmlNodeType.Element, "WebView", root.NamespaceURI); webviewNode.Attributes.Append(xmlDoc.CreateAttribute("x", "Name", xNameSpaceURI)).Value = "engagement_announcement_content"; webviewNode.Attributes.Append(xmlDoc.CreateAttribute("Visibility")).Value = "Collapsed"; webviewNode.Attributes.Append(xmlDoc.CreateAttribute("HorizontalAlignment")).Value = "Stretch"; webviewNode.Attributes.Append(xmlDoc.CreateAttribute("VerticalAlignment")).Value = "Stretch"; grid.AppendChild(webviewNode); appendChildWithEngagementComment(xmlDoc, grid, webviewNode); } // 4-3 Write page mfWriter = new StreamWriter(mainpagexamlPath); xmlDoc.Save(mfWriter); mfWriter.Close(); } else if (target == BuildTarget.iOS) { #if ENABLE_IOS_SUPPORT string bundleId = PlayerSettings.bundleIdentifier; // 0 - Configuration Check string connectionString = EngagementConfiguration.IOS_CONNECTION_STRING; if (string.IsNullOrEmpty(connectionString)) { throw new ArgumentException("IOS_CONNECTION_STRING cannot be null when building on iOS project"); } string projectFile = PBXProject.GetPBXProjectPath(pathToBuiltProject); // 1 - Update Project PBXProject pbx = new PBXProject(); pbx.ReadFromFile(projectFile); string targetUID = pbx.TargetGuidByName(PBXProject.GetUnityTargetName() /*"Unity-iPhone"*/); string CTFramework = "CoreTelephony.framework"; Debug.Log("Adding " + CTFramework + " to XCode Project"); pbx.AddFrameworkToProject(targetUID, CTFramework, true); const string disableAll = "ENGAGEMENT_UNITY=1,ENGAGEMENT_DISABLE_IDFA=1"; const string enableIDFA = "ENGAGEMENT_UNITY=1,ENGAGEMENT_DISABLE_IDFA=1"; const string disableIDFA = "ENGAGEMENT_UNITY=1"; if (EngagementConfiguration.IOS_DISABLE_IDFA == true) { pbx.UpdateBuildProperty(targetUID, "GCC_PREPROCESSOR_DEFINITIONS", enableIDFA.Split(','), disableAll.Split(',')); } else { pbx.UpdateBuildProperty(targetUID, "GCC_PREPROCESSOR_DEFINITIONS", disableIDFA.Split(','), disableAll.Split(',')); } string[] paths = new string[] { EngagementConfiguration.IOS_REACH_ICON, "EngagementPlugin/iOS/res/close.png" }; // 3 - Add files to project foreach (string path in paths) { if (string.IsNullOrEmpty(path)) { continue; } string fullpath = Application.dataPath + "/" + path; string file = Path.GetFileName(fullpath); string fileUID = pbx.AddFile(file, file); Debug.Log("Adding " + file + " to XCode Project"); pbx.AddFileToBuild(targetUID, fileUID); string xcodePath = pathToBuiltProject + "/" + file; if (File.Exists(xcodePath) == false) { Debug.Log("Copy from " + fullpath + " to " + xcodePath); File.Copy(fullpath, xcodePath); } } pbx.WriteToFile(projectFile); // 4 - Modify .PLIST string plistPath = pathToBuiltProject + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; if (EngagementConfiguration.ENABLE_REACH == true) { PlistElementArray UIBackgroundModes = rootDict.CreateArray("UIBackgroundModes"); UIBackgroundModes.AddString("remote-notification"); PlistElementArray CFBundleURLTypes = rootDict.CreateArray("CFBundleURLTypes"); PlistElementDict dict = CFBundleURLTypes.AddDict(); dict.SetString("CFBundleTypeRole", "None"); dict.SetString("CFBundleURLName", bundleId + ".redirect"); PlistElementArray schemes = dict.CreateArray("CFBundleURLSchemes"); schemes.AddString(EngagementConfiguration.ACTION_URL_SCHEME); } // Required on iOS8 string reportingDesc = EngagementConfiguration.LOCATION_REPORTING_DESCRIPTION; if (reportingDesc == null) { reportingDesc = PlayerSettings.productName + " reports your location for analytics purposes"; } if (EngagementConfiguration.LOCATION_REPORTING_MODE == LocationReportingMode.BACKGROUND) { rootDict.SetString("NSLocationAlwaysUsageDescription", reportingDesc); } else if (EngagementConfiguration.LOCATION_REPORTING_MODE == LocationReportingMode.FOREGROUND) { rootDict.SetString("NSLocationWhenInUseUsageDescription", reportingDesc); } string icon = EngagementConfiguration.IOS_REACH_ICON; PlistElementDict engagementDict = rootDict.CreateDict("Engagement"); engagementDict.SetString("IOS_CONNECTION_STRING", EngagementConfiguration.IOS_CONNECTION_STRING); engagementDict.SetString("IOS_REACH_ICON", icon); engagementDict.SetBoolean("ENABLE_NATIVE_LOG", EngagementConfiguration.ENABLE_NATIVE_LOG); engagementDict.SetBoolean("ENABLE_PLUGIN_LOG", EngagementConfiguration.ENABLE_PLUGIN_LOG); engagementDict.SetBoolean("ENABLE_REACH", EngagementConfiguration.ENABLE_REACH); engagementDict.SetInteger("LOCATION_REPORTING_MODE", Convert.ToInt32(EngagementConfiguration.LOCATION_REPORTING_MODE)); engagementDict.SetInteger("LOCATION_REPORTING_TYPE", Convert.ToInt32(EngagementConfiguration.LOCATION_REPORTING_TYPE)); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); #else Debug.LogError("You need to active ENABLE_IOS_SUPPORT to build for IOS"); #endif } if (target == BuildTarget.Android) { string bundleId = PlayerSettings.bundleIdentifier; string productName = PlayerSettings.productName; int chk = generateAndroidChecksum(); // 0 - Configuration check string connectionString = EngagementConfiguration.ANDROID_CONNECTION_STRING; if (string.IsNullOrEmpty(connectionString)) { throw new ArgumentException("ANDROID_CONNECTION_STRING cannot be null when building on Android project"); } if (EngagementConfiguration.ENABLE_REACH == true) { string projectNumber = EngagementConfiguration.ANDROID_GOOGLE_PROJECT_NUMBER; if (string.IsNullOrEmpty(projectNumber)) { throw new ArgumentException("ANDROID_GOOGLE_PROJECT_NUMBER cannot be null when Reach is enabled"); } } string manifestPath = pathToBuiltProject + "/" + productName + "/AndroidManifest.xml"; string androidPath = Application.dataPath + "/Plugins/Android"; string mfFilepath = androidPath + "/AndroidManifest.xml"; XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable()); namespaceManager.AddNamespace("android", EngagementPostBuild.androidNS); // Test Export vs Build if (File.Exists(manifestPath) == false) { // Check that Manifest exists if (File.Exists(mfFilepath) == false) { Debug.LogError("Missing AndroidManifest.xml in Plugins/Android : execute 'File/Engagement/Generate Android Manifest'"); return; } // Check that it contains Engagement tags xmlDoc = new XmlDocument(); xmlDoc.XmlResolver = null; // Create the reader. reader = new XmlTextReader(mfFilepath); xmlDoc.Load(reader); reader.Close(); root = xmlDoc.DocumentElement; nodes = root.SelectNodes("//*[@tag='" + tagName + "']", namespaceManager); if (nodes.Count == 0) { Debug.LogError("Android manifest in Plugins/Android does not contain Engagement extensions : execute 'File/Engagement/Generate Android Manifest'"); } // Checking the version XmlNode versionNode = root.SelectSingleNode("/manifest/application/meta-data[@android:name='engagement:unity:version']", namespaceManager); if (versionNode != null) { string ver = versionNode.Attributes["android:value"].Value; if (ver != EngagementAgent.PLUGIN_VERSION.ToString()) { versionNode = null; } } if (versionNode == null) { Debug.LogError("EngagementPlugin has been updated : you need to execute 'File/Engagement/Generate Android Manifest' to update your application Manifest first"); } // Checking the checksum XmlNode chkNode = root.SelectSingleNode("/manifest/application/meta-data[@android:name='engagement:unity:checksum']", namespaceManager); if (chkNode != null) { string mfchk = chkNode.Attributes["android:value"].Value; if (mfchk != chk.ToString()) { chkNode = null; } } if (chkNode == null) { Debug.LogError("Configuration file has changed : you need to execute 'File/Engagement/Generate Android Manifest' to update your application Manifest"); } // Manifest already processed : nothing to do return; } Directory.CreateDirectory(androidPath); xmlDoc = new XmlDocument(); xmlDoc.XmlResolver = null; reader = new XmlTextReader(manifestPath); xmlDoc.Load(reader); reader.Close(); root = xmlDoc.DocumentElement; // Delete all the former tags nodes = root.SelectNodes("//*[@tag='" + tagName + "']", namespaceManager); foreach (XmlNode node in nodes) { node.ParentNode.RemoveChild(node); } XmlNode manifestNode = root.SelectSingleNode("/manifest", namespaceManager); XmlNode applicationNode = root.SelectSingleNode("/manifest/application", namespaceManager); XmlNode activityNode = root.SelectSingleNode("/manifest/application/activity[@android:label='@string/app_name']", namespaceManager); string activity = EngagementConfiguration.ANDROID_UNITY3D_ACTIVITY; if (activity == null || activity == "") { activity = "com.unity3d.player.UnityPlayerActivity"; } // Already in the Unity Default Manifest // EngagementPostBuild.addUsesPermission(xmlDoc,manifestNode,namespaceManager,"android.permission.INTERNET"); EngagementPostBuild.addUsesPermission(xmlDoc, manifestNode, namespaceManager, "android.permission.ACCESS_NETWORK_STATE"); EngagementPostBuild.addMetaData(xmlDoc, applicationNode, namespaceManager, "engagement:log:test", XmlConvert.ToString(EngagementConfiguration.ENABLE_NATIVE_LOG)); EngagementPostBuild.addMetaData(xmlDoc, applicationNode, namespaceManager, "engagement:unity:version", EngagementAgent.PLUGIN_VERSION); EngagementPostBuild.addMetaData(xmlDoc, applicationNode, namespaceManager, "engagement:unity:checksum", chk.ToString()); XmlNode service = xmlDoc.CreateNode(XmlNodeType.Element, "service", null); service.Attributes.Append(xmlDoc.CreateAttribute("tag")).Value = tagName; service.Attributes.Append(xmlDoc.CreateAttribute("android", "exported", EngagementPostBuild.androidNS)).Value = "false"; service.Attributes.Append(xmlDoc.CreateAttribute("android", "label", EngagementPostBuild.androidNS)).Value = productName + "Service"; service.Attributes.Append(xmlDoc.CreateAttribute("android", "name", EngagementPostBuild.androidNS)).Value = "com.microsoft.azure.engagement.service.EngagementService"; service.Attributes.Append(xmlDoc.CreateAttribute("android", "process", EngagementPostBuild.androidNS)).Value = ":Engagement"; applicationNode.AppendChild(service); string targetAARPath = Application.dataPath + "/Plugins/Android/engagement_notification_icon.aar"; File.Delete(targetAARPath); File.Delete(targetAARPath + ".meta"); if (EngagementConfiguration.ENABLE_REACH == true) { EngagementPostBuild.addActivity(xmlDoc, applicationNode, namespaceManager, "EngagementWebAnnouncementActivity", "ANNOUNCEMENT", "Light", "text/html"); EngagementPostBuild.addActivity(xmlDoc, applicationNode, namespaceManager, "EngagementTextAnnouncementActivity", "ANNOUNCEMENT", "Light", "text/plain"); EngagementPostBuild.addActivity(xmlDoc, applicationNode, namespaceManager, "EngagementPollActivity", "POLL", "Light", null); EngagementPostBuild.addActivity(xmlDoc, applicationNode, namespaceManager, "EngagementLoadingActivity", "LOADING", "Dialog", null); const string reachActions = "android.intent.action.BOOT_COMPLETED," + "com.microsoft.azure.engagement.intent.action.AGENT_CREATED," + "com.microsoft.azure.engagement.intent.action.MESSAGE," + "com.microsoft.azure.engagement.reach.intent.action.ACTION_NOTIFICATION," + "com.microsoft.azure.engagement.reach.intent.action.EXIT_NOTIFICATION," + "com.microsoft.azure.engagement.reach.intent.action.DOWNLOAD_TIMEOUT"; EngagementPostBuild.addReceiver(xmlDoc, applicationNode, namespaceManager, "reach.EngagementReachReceiver", reachActions.Split(',')); const string downloadActions = "android.intent.action.DOWNLOAD_COMPLETE"; EngagementPostBuild.addReceiver(xmlDoc, applicationNode, namespaceManager, "reach.EngagementReachDownloadReceiver", downloadActions.Split(',')); // Add GCM Support if (string.IsNullOrEmpty(EngagementConfiguration.ANDROID_GOOGLE_PROJECT_NUMBER) == false) { EngagementPostBuild.addMetaData(xmlDoc, applicationNode, namespaceManager, "engagement:gcm:sender", EngagementConfiguration.ANDROID_GOOGLE_PROJECT_NUMBER + "\\n"); const string gcmActions = "com.microsoft.azure.engagement.intent.action.APPID_GOT"; EngagementPostBuild.addReceiver(xmlDoc, applicationNode, namespaceManager, "gcm.EngagementGCMEnabler", gcmActions.Split(',')); XmlNode receiver = xmlDoc.CreateNode(XmlNodeType.Element, "receiver", null); receiver.Attributes.Append(xmlDoc.CreateAttribute("tag")).Value = tagName; receiver.Attributes.Append(xmlDoc.CreateAttribute("android", "name", EngagementPostBuild.androidNS)).Value = "com.microsoft.azure.engagement.gcm.EngagementGCMReceiver"; receiver.Attributes.Append(xmlDoc.CreateAttribute("android", "permission", EngagementPostBuild.androidNS)).Value = "com.google.android.c2dm.permission.SEND"; XmlNode intentReceiver = xmlDoc.CreateNode(XmlNodeType.Element, "intent-filter", null); receiver.AppendChild(intentReceiver); intentReceiver.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "action", null)) .Attributes.Append(xmlDoc.CreateAttribute("android", "name", EngagementPostBuild.androidNS)).Value = "com.google.android.c2dm.intent.REGISTRATION"; intentReceiver.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "action", null)) .Attributes.Append(xmlDoc.CreateAttribute("android", "name", EngagementPostBuild.androidNS)).Value = "com.google.android.c2dm.intent.RECEIVE"; intentReceiver.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "category", null)) .Attributes.Append(xmlDoc.CreateAttribute("android", "name", EngagementPostBuild.androidNS)).Value = bundleId; applicationNode.AppendChild(receiver); string permissionPackage = bundleId + ".permission.C2D_MESSAGE"; EngagementPostBuild.addUsesPermission(xmlDoc, manifestNode, namespaceManager, permissionPackage); XmlNode permission = xmlDoc.CreateNode(XmlNodeType.Element, "permission", null); permission.Attributes.Append(xmlDoc.CreateAttribute("tag")).Value = tagName; permission.Attributes.Append(xmlDoc.CreateAttribute("android", "name", EngagementPostBuild.androidNS)).Value = permissionPackage; permission.Attributes.Append(xmlDoc.CreateAttribute("android", "protectionLevel", EngagementPostBuild.androidNS)).Value = "signature"; manifestNode.AppendChild(permission); } const string datapushActions = "com.microsoft.azure.engagement.reach.intent.action.DATA_PUSH"; EngagementPostBuild.addReceiver(xmlDoc, applicationNode, namespaceManager, "shared.EngagementDataPushReceiver", datapushActions.Split(',')); EngagementPostBuild.addUsesPermission(xmlDoc, manifestNode, namespaceManager, "android.permission.WRITE_EXTERNAL_STORAGE"); EngagementPostBuild.addUsesPermission(xmlDoc, manifestNode, namespaceManager, "android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"); EngagementPostBuild.addUsesPermission(xmlDoc, manifestNode, namespaceManager, "android.permission.VIBRATE"); EngagementPostBuild.addUsesPermission(xmlDoc, manifestNode, namespaceManager, "com.google.android.c2dm.permission.RECEIVE"); string icon = "app_icon"; // using Application icon as default if (string.IsNullOrEmpty(EngagementConfiguration.ANDROID_REACH_ICON) == false) { // The only way to add resources to the APK is through a AAR library : let just create one with the icon icon = "engagement_notification_icon"; string srcAARPath = Application.dataPath + "/EngagementPlugin/Editor/engagement_notification_icon.zip"; string iconPath = Application.dataPath + "/" + EngagementConfiguration.ANDROID_REACH_ICON; File.Copy(srcAARPath, targetAARPath, true); ZipFile zip = ZipFile.Read(targetAARPath); zip.AddFile(iconPath).FileName = "res/drawable/" + icon + ".png"; zip.Save(); } EngagementPostBuild.addMetaData(xmlDoc, applicationNode, namespaceManager, "engagement:reach:notification:icon", icon); XmlNode catcherActivity = xmlDoc.CreateNode(XmlNodeType.Element, "activity", null); catcherActivity.Attributes.Append(xmlDoc.CreateAttribute("tag")).Value = "Engagement"; catcherActivity.Attributes.Append(xmlDoc.CreateAttribute("android", "label", EngagementPostBuild.androidNS)).Value = "@string/app_name"; catcherActivity.Attributes.Append(xmlDoc.CreateAttribute("android", "name", EngagementPostBuild.androidNS)).Value = "com.microsoft.azure.engagement.unity.IntentCatcherActivity"; XmlNode intent = xmlDoc.CreateNode(XmlNodeType.Element, "intent-filter", null); intent.Attributes.Append(xmlDoc.CreateAttribute("tag")).Value = tagName; intent.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "action", null)) .Attributes.Append(xmlDoc.CreateAttribute("android", "name", EngagementPostBuild.androidNS)).Value = "android.intent.action.VIEW"; intent.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "category", null)) .Attributes.Append(xmlDoc.CreateAttribute("android", "name", EngagementPostBuild.androidNS)).Value = "android.intent.category.DEFAULT"; intent.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "category", null)) .Attributes.Append(xmlDoc.CreateAttribute("android", "name", EngagementPostBuild.androidNS)).Value = "android.intent.category.BROWSABLE"; intent.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "data", null)) .Attributes.Append(xmlDoc.CreateAttribute("android", "scheme", EngagementPostBuild.androidNS)).Value = EngagementConfiguration.ACTION_URL_SCHEME; catcherActivity.AppendChild(intent); applicationNode.AppendChild(catcherActivity); EngagementPostBuild.addMetaData(xmlDoc, applicationNode, namespaceManager, "engagement:unity:activityname", activity); } if (EngagementConfiguration.LOCATION_REPORTING_MODE == LocationReportingMode.BACKGROUND) { string bootReceiverActions = "android.intent.action.BOOT_COMPLETED"; EngagementPostBuild.addReceiver(xmlDoc, applicationNode, namespaceManager, "EngagementLocationBootReceiver", bootReceiverActions.Split(',')); } if (EngagementConfiguration.LOCATION_REPORTING_TYPE == LocationReportingType.LAZY || EngagementConfiguration.LOCATION_REPORTING_TYPE == LocationReportingType.REALTIME) { EngagementPostBuild.addUsesPermission(xmlDoc, manifestNode, namespaceManager, "android.permission.ACCESS_COARSE_LOCATION"); } else if (EngagementConfiguration.LOCATION_REPORTING_TYPE == LocationReportingType.FINEREALTIME) { EngagementPostBuild.addUsesPermission(xmlDoc, manifestNode, namespaceManager, "android.permission.ACCESS_FINE_LOCATION"); } if (EngagementConfiguration.LOCATION_REPORTING_MODE == LocationReportingMode.BACKGROUND || EngagementConfiguration.ENABLE_REACH == true) { EngagementPostBuild.addUsesPermission(xmlDoc, manifestNode, namespaceManager, "android.permission.RECEIVE_BOOT_COMPLETED"); } // Update the manifest TextWriter textWriter = new StreamWriter(manifestPath); xmlDoc.Save(textWriter); textWriter.Close(); // revert the bundle id activityNode.Attributes.Append(xmlDoc.CreateAttribute("android", "name", EngagementPostBuild.androidNS)).Value = activity; Debug.Log("Generating :" + mfFilepath); mfWriter = new StreamWriter(mfFilepath); xmlDoc.Save(mfWriter); mfWriter.Close(); } }
public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { if (buildTarget != BuildTarget.iOS) { Debug.Log("这不是IOS平台,不执行操作"); return; } string projPath = PBXProject.GetPBXProjectPath(path); PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string target = proj.TargetGuidByName("Unity-iPhone"); //广告依赖库 List <string> frameworks = new List <string>(); frameworks.Add("AppcoachsSDK.framework"); frameworks.Add("GoogleMobileAds.framework"); frameworks.Add("InMobiSDK.framework"); frameworks.Add("MVSDK.framework"); frameworks.Add("MVSDKAppWall.framework"); frameworks.Add("MVSDKInterstitial.framework"); frameworks.Add("MVSDKOfferWall.framework"); frameworks.Add("MVSDKReward.framework"); frameworks.Add("UnityAds.framework"); frameworks.Add("VungleSDK.framework"); //添加依赖库到工程中 foreach (string framework in frameworks) { CopyAndReplaceDirectory("Assets/ADFlyHiSDK/Plugins/iOS/frameworks/" + framework, Path.Combine(path, "ADFlyHiSDK/Plugins/iOS/frameworks/" + framework)); string fileGuid = proj.FindFileGuidByProjectPath("Frameworks/ADFlyHiSDK/Plugins/iOS/frameworks/" + framework); proj.RemoveFileFromBuild(target, fileGuid); proj.RemoveFile(fileGuid); string name = proj.AddFile("ADFlyHiSDK/Plugins/iOS/frameworks/" + framework, "ADFlyHiSDK/Plugins/iOS/frameworks/" + framework, PBXSourceTree.Source); proj.AddFileToBuild(target, name); } DirectoryInfo di = new DirectoryInfo(Path.Combine(path, "Frameworks/ADFlyHiSDK/")); di.Delete(true); List <string> bundles = new List <string>(); bundles.Add("appcoachsSDK.bundle"); bundles.Add("ChanceAdRes.bundle"); foreach (string bundle in bundles) { CopyAndReplaceDirectory("Assets/ADFlyHiSDK/Plugins/iOS/resources/" + bundle, Path.Combine(path, "ADFlyHiSDK/Plugins/iOS/frameworks/" + bundle)); string name = proj.AddFile("ADFlyHiSDK/Plugins/iOS/frameworks/" + bundle, "ADFlyHiSDK/Plugins/iOS/frameworks/" + bundle, PBXSourceTree.Source); proj.AddFileToBuild(target, name); } //tbd依赖包 List <string> tbds = new List <string>(); tbds.Add("libsqlite3.tbd"); tbds.Add("libz.tbd"); tbds.Add("libz.1.2.5.tbd"); tbds.Add("libc++.tbd"); tbds.Add("libxml2.tbd"); //添加tbd依赖包 foreach (string tbd in tbds) { string name = proj.AddFile("usr/lib/" + tbd, "Frameworks/" + tbd, PBXSourceTree.Sdk); proj.AddFileToBuild(target, name); } Debug.Log("添加其他资源"); File.Copy("Assets/ADFlyHiSDK/Plugins/iOS/resources/[email protected]", Path.Combine(path, "ADFlyHiSDK/Plugins/iOS/frameworks/[email protected]")); proj.AddFile("ADFlyHiSDK/Plugins/iOS/frameworks/[email protected]", "ADFlyHiSDK/Plugins/iOS/frameworks/[email protected]", PBXSourceTree.Source); File.Copy("Assets/ADFlyHiSDK/Plugins/iOS/resources/[email protected]", Path.Combine(path, "ADFlyHiSDK/Plugins/iOS/frameworks/[email protected]")); proj.AddFile("ADFlyHiSDK/Plugins/iOS/frameworks/[email protected]", "ADFlyHiSDK/Plugins/iOS/frameworks/[email protected]", PBXSourceTree.Source); //设置buildsetting Debug.Log("设置buildsetting"); proj.SetBuildProperty(target, "OTHER_LDFLAGS", "-ObjC"); proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); proj.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)"); proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/ADFlyHiSDK/Plugins/iOS/frameworks/"); proj.WriteToFile(projPath); //修改Info.plist Debug.Log("修改info.plist"); string plistPath = path + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDic = plist.root.AsDict(); rootDic.CreateDict("NSAppTransportSecurity").SetBoolean("NSAllowsArbitraryLoads", true); rootDic.SetBoolean("UIStatusBarHidden", true); rootDic.SetBoolean("UIViewControllerBasedStatusBarAppearance", false); rootDic.SetString("NSLocationWhenInUseUsageDescription", ""); plist.WriteToFile(plistPath); }
public static void OnPostprocessBuild(BuildTarget target, string buildPath) { // Add declared custom types to Info.plist if (target == BuildTarget.iOS) { NativeFilePickerCustomTypes.TypeHolder[] customTypes = NativeFilePickerCustomTypes.GetCustomTypes(); if (customTypes != null) { string plistPath = Path.Combine(buildPath, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; for (int i = 0; i < customTypes.Length; i++) { NativeFilePickerCustomTypes.TypeHolder customType = customTypes[i]; PlistElementArray customTypesArray = GetCustomTypesArray(rootDict, customType.isExported); // Don't allow duplicate entries RemoveCustomTypeIfExists(customTypesArray, customType.identifier); PlistElementDict customTypeDict = customTypesArray.AddDict(); customTypeDict.SetString("UTTypeIdentifier", customType.identifier); customTypeDict.SetString("UTTypeDescription", customType.description); PlistElementArray conformsTo = customTypeDict.CreateArray("UTTypeConformsTo"); for (int j = 0; j < customType.conformsTo.Length; j++) { conformsTo.AddString(customType.conformsTo[j]); } PlistElementDict tagSpecification = customTypeDict.CreateDict("UTTypeTagSpecification"); PlistElementArray tagExtensions = tagSpecification.CreateArray("public.filename-extension"); for (int j = 0; j < customType.extensions.Length; j++) { tagExtensions.AddString(customType.extensions[j]); } } File.WriteAllText(plistPath, plist.WriteToString()); } } // Rest of the function shouldn't execute unless build post-processing is enabled if (!AUTO_SETUP_FRAMEWORKS && !AUTO_SETUP_ICLOUD) { return; } if (target == BuildTarget.iOS) { string pbxProjectPath = PBXProject.GetPBXProjectPath(buildPath); PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromFile(pbxProjectPath); #if UNITY_2019_3_OR_NEWER string targetGUID = pbxProject.GetUnityFrameworkTargetGuid(); #else string targetGUID = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName()); #endif if (AUTO_SETUP_FRAMEWORKS) { pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework MobileCoreServices"); pbxProject.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-framework CloudKit"); } #if !UNITY_2017_1_OR_NEWER if (AUTO_SETUP_ICLOUD) { // Add iCloud capability without Cloud Build support on 5.6 or earlier string entitlementsPath = Path.Combine(buildPath, "iCloud.entitlements"); File.WriteAllText(entitlementsPath, ICLOUD_ENTITLEMENTS); pbxProject.AddFile(entitlementsPath, Path.GetFileName(entitlementsPath)); pbxProject.AddBuildProperty(targetGUID, "CODE_SIGN_ENTITLEMENTS", entitlementsPath); } #endif File.WriteAllText(pbxProjectPath, pbxProject.WriteToString()); #if UNITY_2017_1_OR_NEWER if (AUTO_SETUP_ICLOUD) { // Add iCloud capability with Cloud Build support on 2017.1+ #if UNITY_2019_3_OR_NEWER ProjectCapabilityManager manager = new ProjectCapabilityManager(pbxProjectPath, "iCloud.entitlements", "Unity-iPhone"); #else ProjectCapabilityManager manager = new ProjectCapabilityManager(pbxProjectPath, "iCloud.entitlements", PBXProject.GetUnityTargetName()); #endif #if UNITY_2018_3_OR_NEWER manager.AddiCloud(false, true, false, true, null); #else manager.AddiCloud(false, true, true, null); #endif manager.WriteToFile(); } #endif } }
public static void NewIOSXcodeSettings() { //添加XCode引用的Framework string projPath = PBXProject.GetPBXProjectPath(Otherpath); PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string target = proj.TargetGuidByName("Unity-iPhone"); // BuildSetting修改 proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); //这个好像是bugly需要的 proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC"); //这个google等其他sdk非常需要的 //proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-all_load"); #region 添加XCode引用的Framework // SDK依赖 --AIHelp proj.AddFrameworkToProject(target, "libsqlite3.tbd", false); proj.AddFrameworkToProject(target, "libresolv.tbd", false); proj.AddFrameworkToProject(target, "WebKit.framework", false); // SDK依赖 --Google proj.AddFrameworkToProject(target, "LocalAuthentication.framework", false); proj.AddFrameworkToProject(target, "SafariServices.framework", false); proj.AddFrameworkToProject(target, "AuthenticationServices.framework", false); proj.AddFrameworkToProject(target, "SystemConfiguration.framework", false); // SDK依赖 --Apple proj.AddFrameworkToProject(target, "storekit.framework", false); proj.AddFrameworkToProject(target, "AuthenticationServices.framework", false); proj.AddFrameworkToProject(target, "gamekit.framework", false); #endregion string plistPath = Path.Combine(Otherpath, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); PlistElementDict rootDict = plist.root; #region 修改Xcode工程Info.plist /* iOS9所有的app对外http协议默认要求改成https */ // Add value of NSAppTransportSecurity in Xcode plist PlistElementDict dictTmp = rootDict.CreateDict("NSAppTransportSecurity"); dictTmp.SetBoolean("NSAllowsArbitraryLoads", true); //AIHelp-权限配置 rootDict.SetString("NSCameraUsageDescription", "是否允许访问相机?"); rootDict.SetString("NSMicrophoneUsageDescription", "是否允许使用麦克风?"); rootDict.SetString("NSPhotoLibraryAddUsageDescription", "是否允许添加照片?"); rootDict.SetString("NSMicrophoneUsageDescription", "是否允许访问相册?"); rootDict.SetString("CFBundleDevelopmentRegion", "zh_TW"); rootDict.SetString("CFBundleVersion", "1"); // SDK相关参数设置 rootDict.SetString("FacebookAppID", "949004278872387"); rootDict.SetString("GoogleClientID", "554619719418-0hdrkdprcsksigpldvtr9n5lu2lvt5kn.apps.googleusercontent.com"); rootDict.SetString("FacebookAppDisplayName", "少女的王座"); rootDict.SetString("AIHelpAppID", "elextech_platform_15ce9b10-f784-4ab5-8ee4-45efab40bd6a"); rootDict.SetString("AIHelpAppKey", "ELEXTECH_app_50dd4661c57843778d850769a02f8a09"); rootDict.SetString("AIHelpDomain", "*****@*****.**"); rootDict.SetString("AdjustAppToken", "1k2jm7bpansw"); rootDict.SetString("AdjustAppSecret", "1,750848352-1884995334-181661496-1073918938"); // Set encryption usage boolean string encryptKey = "ITSAppUsesNonExemptEncryption"; rootDict.SetBoolean(encryptKey, false); // remove exit on suspend if it exists.ios13新增 string exitsOnSuspendKey = "UIApplicationExitsOnSuspend"; if (rootDict.values.ContainsKey(exitsOnSuspendKey)) { rootDict.values.Remove(exitsOnSuspendKey); } // URL types配置 PlistElementArray URLTypes = rootDict.CreateArray("CFBundleURLTypes"); //Facebook PlistElementDict typeRoleFB = URLTypes.AddDict(); typeRoleFB.SetString("CFBundleTypeRole", "Editor"); PlistElementArray urlSchemeFB = typeRoleFB.CreateArray("CFBundleURLSchemes"); urlSchemeFB.AddString("fb949004278872387"); //Google PlistElementDict typeRole = URLTypes.AddDict(); typeRole.SetString("CFBundleTypeRole", "Editor"); typeRole.SetString("CFBundleURLName", "com.googleusercontent.apps.554619719418-0hdrkdprcsksigpldvtr9n5lu2lvt5kn"); PlistElementArray urlScheme = typeRole.CreateArray("CFBundleURLSchemes"); urlScheme.AddString("com.googleusercontent.apps.554619719418-0hdrkdprcsksigpldvtr9n5lu2lvt5kn"); // LSApplicationQueriesSchemes配置 PlistElementArray LSApplicationQueriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes"); // facebook接入配置 LSApplicationQueriesSchemes.AddString("fbapi"); LSApplicationQueriesSchemes.AddString("fb-messenger-share-api"); LSApplicationQueriesSchemes.AddString("fbauth2"); LSApplicationQueriesSchemes.AddString("fbshareextension"); // Line接入配置 LSApplicationQueriesSchemes.AddString("lineauth"); LSApplicationQueriesSchemes.AddString("line3rdp.$(APP_IDENTIFIER)"); LSApplicationQueriesSchemes.AddString("line"); #endregion ProjectCapabilityManager projectCapabilityManager = new ProjectCapabilityManager(projPath, "tw.entitlements", PBXProject.GetUnityTargetName()); projectCapabilityManager.AddGameCenter(); projectCapabilityManager.AddInAppPurchase(); plist.WriteToFile(plistPath); proj.WriteToFile(projPath); Debug.Log("--**--4.IOSXcodeSettings--**--"); }