/// <summary> /// 修改pbxproj文件 /// </summary> private void ModifyPbxproj() { var pbxprojPath = PBXProject.GetPBXProjectPath(pathToBuiltProject); var pbxProject = new PBXProject(); pbxProject.ReadFromFile(pbxprojPath); var frameworkTarget = pbxProject.GetUnityFrameworkTargetGuid(); if (!config.ios.bitCode) { CloseBitCode(pbxProject, frameworkTarget); } var prejectTarget = pbxProject.GetUnityMainTargetGuid(); pbxProject.AddCapability(prejectTarget, PBXCapabilityType.InAppPurchase, "ios.entitlements"); var capManager = new ProjectCapabilityManager(pbxprojPath, "ios.entitlements", null, prejectTarget); AddCapability(capManager); pbxProject.WriteToFile(pbxprojPath); }
/// <summary> /// 设置iOS Capability /// </summary> private static void AddCapability(PBXProject pbxProject, string targetGuid, string path) { var product = string.Empty; #if UNITY_2019_3_OR_NEWER product = UnityEngine.Application.identifier; var index = product.LastIndexOf('.'); product = product.Substring(index + 1); #else product = pbxProject.GetBuildPropertyForAnyConfig(targetGuid, "PRODUCT_NAME"); #endif var rentitlementFilePath = $"Unity-iPhone/{product}.entitlements"; var fullPath = Path.Combine(path, rentitlementFilePath); var doc = new PlistDocument(); doc.root.SetBoolean("com.apple.developer.networking.wifi-info", true); doc.WriteToFile(fullPath); pbxProject.AddCapability(targetGuid, PBXCapabilityType.AccessWiFiInformation, rentitlementFilePath); }
static void OnPostProcessBuild(BuildTarget target, string path) { if (target != BuildTarget.iOS) { return; } // PBXProject string projectPath = PBXProject.GetPBXProjectPath(path); var project = new PBXProject(); project.ReadFromFile(projectPath); string targetGuid = project.TargetGuidByName(PBXProject.GetUnityTargetName()); project.AddCapability(targetGuid, PBXCapabilityType.BackgroundModes); project.SetBuildProperty(targetGuid, "SWIFT_OBJC_INTERFACE_HEADER_NAME", "Unity-Swift.h"); project.SetBuildProperty(targetGuid, "SWIFT_VERSION", "4.0"); project.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks"); project.WriteToFile(projectPath); // Info.plist string plistPath = Path.Combine(path, "Info.plist"); var plist = new PlistDocument(); plist.ReadFromFile(plistPath); plist.root.SetString("NSBluetoothPeripheralUsageDescription", "To ad-hoc communicating"); plist.root.SetString("NSBluetoothAlwaysUsageDescription", "To ad-hoc communicating"); var backgroundModes = plist.root.CreateArray("UIBackgroundModes"); backgroundModes.AddString("bluetooth-central"); backgroundModes.AddString("bluetooth-peripheral"); plist.WriteToFile(plistPath); }
public static void OnPostProcessBuild(BuildTarget buildTarget, string path) { string projectPath = PBXProject.GetPBXProjectPath(path); PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromFile(projectPath); string target = pbxProject.TargetGuidByName("Unity-iPhone"); pbxProject.AddCapability(target, PBXCapabilityType.InAppPurchase); // Plistの設定のための初期化 var plistPath = Path.Combine(path, "Info.plist"); var plist = new PlistDocument(); plist.ReadFromFile(plistPath); //日付とか string dateName = DateTime.Today.Month.ToString("D2") + DateTime.Today.Day.ToString("D2"); string timeName = DateTime.Now.Hour.ToString("D2") + DateTime.Now.Minute.ToString("D2"); if (Debug.isDebugBuild) { //アプリ名 plist.root.SetString("CFBundleDisplayName", $"{dateName}_debug"); //bundleId pbxProject.SetBuildProperty(target, "PRODUCT_BUNDLE_IDENTIFIER", Application.identifier + ".dev"); } //ipa名 string buildMode = Debug.isDebugBuild ? "debug" : "release"; string name = $"{Application.productName}_{buildMode}_ver{Application.version}_{dateName}_{timeName}"; Debug.Log($"~~~~~~~~~~~~~~~\n{name}\n~~~~~~~~~~~~~~~"); plist.WriteToFile(plistPath); pbxProject.WriteToFile(projectPath); }
static void OnPostprocessBuild(BuildTarget buildTarget, string path) { if (buildTarget != BuildTarget.iOS) { return; } #if UNITY_IOS string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject proj = new PBXProject(); proj.ReadFromFile(projPath); string target = proj.TargetGuidByName("Unity-iPhone"); proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); proj.AddCapability(target, PBXCapabilityType.InAppPurchase); proj.WriteToFile(projPath); #endif }
public static void ModifyXcodeProject(BuildTarget buildTarget, string pathToBuiltProject) { if (buildTarget == BuildTarget.iOS) { var xcodeProjectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; var project = new PBXProject(); project.ReadFromFile(xcodeProjectPath); string target = project.TargetGuidByName("Unity-iPhone"); project.AddCapability(target, PBXCapabilityType.BackgroundModes); project.WriteToFile(xcodeProjectPath); var infoPlistPath = pathToBuiltProject + "/Info.plist"; var infoPlist = new PlistDocument(); infoPlist.ReadFromString(File.ReadAllText(infoPlistPath)); PlistElementDict rootDictionary = infoPlist.root; rootDictionary.SetString("NSLocationWhenInUseUsageDescription", "For stuff leñe!"); var backgroundModes = rootDictionary.CreateArray("UIBackgroundModes"); backgroundModes.AddString("location"); File.WriteAllText(infoPlistPath, infoPlist.WriteToString()); } }
public static void OnPostprocessingBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS) { #if UNITY_IOS string projPath = PBXProject.GetPBXProjectPath(path); PBXProject proj = new PBXProject(); proj.ReadFromFile(projPath); string target = proj.GetUnityMainTargetGuid(); proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); proj.AddFrameworkToProject(target, "StoreKit.framework", true); proj.AddFrameworkToProject(target, "AdSupport.framework", true); proj.AddCapability(target, PBXCapabilityType.InAppPurchase, null, true); //proj.AddCapability(target, PBXCapabilityType.ApplePay, entitlementsFilePath, true); proj.WriteToFile(projPath); // 修改Info.plist文件 string plistPath = Path.Combine(path, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); PlistElementDict dict = plist.root.CreateDict("NSAppTransportSecurity"); dict.SetBoolean("NSAllowsArbitraryLoads", true); plist.root.SetString("GADApplicationIdentifier", "ca-app-pub-3041081834653045~6836057851"); plist.root.SetBoolean("GADIsAdManagerApp", true); plist.root.SetBoolean("ITSAppUsesNonExemptEncryption", false); plist.root.SetString("FirebaseMessagingAutoInitEnabled", "NO"); //IronSource需求 PlistElementArray a = plist.root.CreateArray("SKAdNetworkItems"); PlistElementDict b = a.AddDict(); b.SetString("SKAdNetworkIdentifier", "SU67R6K2V3.skadnetwork"); plist.WriteToFile(plistPath); Debug.Log("post build ios success"); #endif } }
public static void OnPostprocessBuildHandler(BuildTarget buildTarget, string path) { var projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; var proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); var target = proj.GetUnityMainTargetGuid(); proj.AddFrameworkToProject(target, "UserNotifications.framework", true); proj.AddCapability(target, PBXCapabilityType.PushNotifications); if (Directory.Exists(ICONS_PROJECT_PATH)) { foreach (var file in Directory.GetFiles(ICONS_PROJECT_PATH, "*.png", SearchOption.AllDirectories)) { var dstLocalPath = Path.GetFileName(file); var resourcesBuildPhase = proj.GetResourcesBuildPhaseByTarget(target); var fileRef = proj.AddFile(dstLocalPath, dstLocalPath); File.Copy(file, Path.Combine(path, dstLocalPath), true); proj.AddFileToBuild(target, fileRef); } } File.WriteAllText(projPath, proj.WriteToString()); var capabilities = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(path), "app.entitlements", "Unity-iPhone"); capabilities.AddPushNotifications(true); capabilities.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications); capabilities.WriteToFile(); }
// Add the iCloud capability with the desired options. public void AddiCloud(bool keyValueStorage, bool iCloudDocument, string[] customContainers) { var ent = GetOrCreateEntitlementDoc(); var val = (ent.root[ICloudEntitlements.ContainerIdValue] = new PlistElementArray()) as PlistElementArray; if (iCloudDocument) { val.values.Add(new PlistElementString(ICloudEntitlements.ContainerIdValue)); var ser = (ent.root[ICloudEntitlements.ServicesKey] = new PlistElementArray()) as PlistElementArray; ser.values.Add(new PlistElementString(ICloudEntitlements.ServicesKitValue)); ser.values.Add(new PlistElementString(ICloudEntitlements.ServicesDocValue)); var ubiquity = (ent.root[ICloudEntitlements.UbiquityContainerIdKey] = new PlistElementArray()) as PlistElementArray; ubiquity.values.Add(new PlistElementString(ICloudEntitlements.UbiquityContainerIdValue)); for (var i = 0; i < customContainers.Length; i++) { ser.values.Add(new PlistElementString(customContainers[i])); } } if (keyValueStorage) { ent.root[ICloudEntitlements.KeyValueStoreKey] = new PlistElementString(ICloudEntitlements.KeyValueStoreValue); } project.AddCapability(m_TargetGuid, PBXCapabilityType.iCloud, m_EntitlementFilePath, iCloudDocument); }
void SetNativeSDK() { string path = GetXcodeProjectPath(option.PlayerOption.locationPathName); #region 添加XCode引用的Framework string projPath = PBXProject.GetPBXProjectPath(path); PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string target = proj.TargetGuidByName("Unity-iPhone"); // Bugly依赖 proj.AddFrameworkToProject(target, "libz.tbd", false); proj.AddFrameworkToProject(target, "libc++.tbd", false); //星辉SDK依赖 proj.AddFrameworkToProject(target, "libsqlite3.tbd", false); proj.AddFrameworkToProject(target, "libsqlite3.0.tbd", false); proj.AddFrameworkToProject(target, "libicucore.tbd", false); proj.AddFrameworkToProject(target, "SafariServices.framework", false); proj.AddFrameworkToProject(target, "WebKit.framework", false); proj.AddFrameworkToProject(target, "MobileCoreServices.framework", false); proj.AddFrameworkToProject(target, "ImageIO.framework", false); proj.AddFrameworkToProject(target, "Photos.framework", false); // TPNS依赖 proj.AddFrameworkToProject(target, "CoreTelephony.framework", false); proj.AddFrameworkToProject(target, "SystemConfiguration.framework", false); proj.AddFrameworkToProject(target, "UserNotifications.framework", false); proj.AddFrameworkToProject(target, "CoreData.framework", false); proj.AddFrameworkToProject(target, "CFNetwork.framework", false); #endregion 添加XCode引用的Framework // BuildSetting修改 proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC"); proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-lc++"); proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-fprofile-instr-generate"); proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-all_load"); #region 修改Xcode工程Info.plist string plistPath = Path.Combine(path, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); PlistElementDict rootDict = plist.root; // 调整默认配置 rootDict.SetString("CFBundleDevelopmentRegion", "zh_CN"); // 权限配置 rootDict.SetString("NSCameraUsageDescription", "是否允许访问相机?"); rootDict.SetString("NSMicrophoneUsageDescription", "是否允许使用麦克风?"); rootDict.SetString("NSPhotoLibraryAddUsageDescription", "是否允许添加照片?"); rootDict.SetString("NSMicrophoneUsageDescription", "是否允许访问相册?"); rootDict.SetString("NSUserTrackingUsageDescription", "请放心选择允许,该权限仅用于获取您的设备标识,以便未来找回账号"); //星辉SDK默认为暗黑模式 但是开启之后隐私协议会看不到 所以要关闭暗黑模式 //rootDict.SetString("UIUserInterfaceStyle", "Light"); // SDK相关参数设置 rootDict.SetString("RaStarUMKey", "5bc6b08af1f55681f30000da"); rootDict.SetString("RaStarWeChatKey", "wxf4ea05dfad6b67f3"); rootDict.SetString("RaStarWeChatSecret", "ec8b3c05e2d81442c14bbc33450c24e1"); rootDict.SetString("RaStarWeChatUniversalLink", "https://3rd-sy.rastargame.com/sndwz/"); rootDict.SetString("RaStarQQID", "101908009"); rootDict.SetString("RaStarQQSecret", "5cbe0e16d98468e954e14087fb963ffe"); rootDict.SetString("RaStarWeiboAppKey", "2546046978"); rootDict.SetString("RaStarWeiboSecret", "ab014360f368b311739e5060256d4284"); PlistElementArray RaStarShareTypeArray = rootDict.CreateArray("RaStarShareTypeArray"); RaStarShareTypeArray.AddString("微信"); RaStarShareTypeArray.AddString("朋友圈"); RaStarShareTypeArray.AddString("微博"); RaStarShareTypeArray.AddString("QQ"); RaStarShareTypeArray.AddString("QQ空间"); //文件共享 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 = plist.root.CreateArray("CFBundleURLTypes"); //weixin PlistElementDict wxUrl = URLTypes.AddDict(); wxUrl.SetString("CFBundleTypeRole", "Editor"); wxUrl.SetString("CFBundleURLName", "weixin"); PlistElementArray wxUrlScheme = wxUrl.CreateArray("CFBundleURLSchemes"); wxUrlScheme.AddString("wxf4ea05dfad6b67f3"); //weibo PlistElementDict weibiUrl = URLTypes.AddDict(); weibiUrl.SetString("CFBundleTypeRole", "Editor"); weibiUrl.SetString("CFBundleURLName", "weibo"); PlistElementArray weibiUrlScheme = weibiUrl.CreateArray("CFBundleURLSchemes"); weibiUrlScheme.AddString("wb2546046978"); //tencent PlistElementDict tcUrl = URLTypes.AddDict(); tcUrl.SetString("CFBundleTypeRole", "Editor"); tcUrl.SetString("CFBundleURLName", "tencent"); PlistElementArray tcUrlScheme = tcUrl.CreateArray("CFBundleURLSchemes"); tcUrlScheme.AddString("tencent101908009"); //QQ PlistElementDict qqUrl = URLTypes.AddDict(); qqUrl.SetString("CFBundleTypeRole", "Editor"); qqUrl.SetString("CFBundleURLName", "QQ"); PlistElementArray qqUrlScheme = qqUrl.CreateArray("CFBundleURLSchemes"); qqUrlScheme.AddString("QQ0612fe29"); #endregion 修改Xcode工程Info.plist #region LSApplicationQueriesSchemes配置 PlistElementArray LSApplicationQueriesSchemes = plist.root.CreateArray("LSApplicationQueriesSchemes"); LSApplicationQueriesSchemes.AddString("wechat"); LSApplicationQueriesSchemes.AddString("weixin"); LSApplicationQueriesSchemes.AddString("weixinULAPI"); LSApplicationQueriesSchemes.AddString("sinaweibohd"); LSApplicationQueriesSchemes.AddString("sinaweibo"); LSApplicationQueriesSchemes.AddString("sinaweibosso"); LSApplicationQueriesSchemes.AddString("weibosdk"); LSApplicationQueriesSchemes.AddString("weibosdk2.5"); LSApplicationQueriesSchemes.AddString("mqqopensdklaunchminiapp"); LSApplicationQueriesSchemes.AddString("mqqopensdkminiapp"); LSApplicationQueriesSchemes.AddString("mqqapi"); LSApplicationQueriesSchemes.AddString("mqq"); LSApplicationQueriesSchemes.AddString("mqqOpensdkSSoLogin"); LSApplicationQueriesSchemes.AddString("mqqconnect"); LSApplicationQueriesSchemes.AddString("mqqopensdkdataline"); LSApplicationQueriesSchemes.AddString("mqqopensdkgrouptribeshare"); LSApplicationQueriesSchemes.AddString("mqqopensdkfriend"); LSApplicationQueriesSchemes.AddString("mqqopensdkapi"); LSApplicationQueriesSchemes.AddString("mqqopensdkapiV2"); LSApplicationQueriesSchemes.AddString("mqqopensdkapiV3"); LSApplicationQueriesSchemes.AddString("mqqopensdkapiV4"); LSApplicationQueriesSchemes.AddString("mqqzoneopensdk"); LSApplicationQueriesSchemes.AddString("wtloginmqq"); LSApplicationQueriesSchemes.AddString("wtloginmqq2"); LSApplicationQueriesSchemes.AddString("mqqwpa"); LSApplicationQueriesSchemes.AddString("mqzone"); LSApplicationQueriesSchemes.AddString("mqzoneV2"); LSApplicationQueriesSchemes.AddString("mqzoneshare"); LSApplicationQueriesSchemes.AddString("wtloginqzone"); LSApplicationQueriesSchemes.AddString("mqzonewx"); LSApplicationQueriesSchemes.AddString("mqzoneopensdkapiV2"); LSApplicationQueriesSchemes.AddString("mqzoneopensdkapi19"); LSApplicationQueriesSchemes.AddString("mqzoneopensdkapi"); LSApplicationQueriesSchemes.AddString("mqqbrowser"); LSApplicationQueriesSchemes.AddString("mttbrowser"); LSApplicationQueriesSchemes.AddString("tim"); LSApplicationQueriesSchemes.AddString("timapi"); LSApplicationQueriesSchemes.AddString("timopensdkfriend"); LSApplicationQueriesSchemes.AddString("timwpa"); LSApplicationQueriesSchemes.AddString("timegamebindinggroup"); LSApplicationQueriesSchemes.AddString("timapiwallet"); LSApplicationQueriesSchemes.AddString("timOpensdkSSoLogin"); LSApplicationQueriesSchemes.AddString("wtlogintim"); LSApplicationQueriesSchemes.AddString("timopensdkgrouptribeshare"); LSApplicationQueriesSchemes.AddString("timopensdkapiV4"); LSApplicationQueriesSchemes.AddString("timgamebindinggroup"); LSApplicationQueriesSchemes.AddString("timeopensdkdataline"); LSApplicationQueriesSchemes.AddString("wtlogintimV1"); LSApplicationQueriesSchemes.AddString("timpapiV1"); plist.WriteToFile(plistPath); #endregion LSApplicationQueriesSchemes配置 //文件追加 var entitlementsFileName = "sndwz.entitlements"; var entitlementsFilePath = Path.Combine("Assets/Plugins/iOS/SDK/", entitlementsFileName); File.Copy(entitlementsFilePath, Path.Combine(path, entitlementsFileName), true); proj.AddFileToBuild(target, proj.AddFile(entitlementsFileName, entitlementsFileName, PBXSourceTree.Source)); proj.AddCapability(target, PBXCapabilityType.InAppPurchase); proj.AddCapability(target, PBXCapabilityType.AccessWiFiInformation, entitlementsFileName); proj.AddCapability(target, PBXCapabilityType.AssociatedDomains, entitlementsFileName); proj.AddCapability(target, PBXCapabilityType.PushNotifications, entitlementsFileName); proj.WriteToFile(projPath); File.WriteAllText(projPath, proj.WriteToString()); }
void SetOverseaSDK(JObject sdkParams) { string appID = ""; string cchID = ""; if (sdkParams != null) { appID = sdkParams.Value <string>("AppId"); cchID = sdkParams.Value <string>("CchId"); } string path = GetXcodeProjectPath(option.PlayerOption.locationPathName); #region 添加XCode引用的Framework string projPath = PBXProject.GetPBXProjectPath(path); PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string target = proj.TargetGuidByName("Unity-iPhone"); // 系统框架 // Bugly依赖 proj.AddFrameworkToProject(target, "libz.tbd", false); proj.AddFrameworkToProject(target, "libc++.tbd", false); // SDK依赖 proj.AddFrameworkToProject(target, "iAd.framework", false); proj.AddFrameworkToProject(target, "StoreKit.framework", false); proj.AddFrameworkToProject(target, "AdSupport.framework", false); proj.AddFrameworkToProject(target, "UserNotifications.framework", false); proj.AddFrameworkToProject(target, "NotificationCenter.framework", false); proj.AddFrameworkToProject(target, "MobileCoreServices.framework", false); proj.AddFrameworkToProject(target, "SafariServices.framework", true); proj.AddFrameworkToProject(target, "ImageIO.framework", false); proj.AddFrameworkToProject(target, "Social.framework", false); proj.AddFrameworkToProject(target, "MessageUI.framework", false); proj.AddFrameworkToProject(target, "WebKit.framework", false); proj.AddFrameworkToProject(target, "AssetsLibrary.framework", false); proj.AddFrameworkToProject(target, "QuartzCore.framework", false); proj.AddFrameworkToProject(target, "ReplayKit.framework", false); proj.AddFrameworkToProject(target, "MediaPlayer.framework", false); // 文件追加 var fileName = "RSOverseaSDK.plist"; var filePath = Path.Combine("Assets/Plugins/iOS/SDK/", fileName); File.Copy(filePath, Path.Combine(path, fileName)); proj.AddFileToBuild(target, proj.AddFile(fileName, fileName, PBXSourceTree.Source)); #endregion 添加XCode引用的Framework // BuildSetting修改 proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC"); proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-all_load"); #region 修改Xcode工程Info.plist string plistPath = Path.Combine(path, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); PlistElementDict rootDict = plist.root; // 调整默认配置 rootDict.SetString("CFBundleDevelopmentRegion", "zh_CN"); rootDict.SetString("CFBundleVersion", "1"); rootDict.SetString("FacebookAppID", "1496435593826813"); rootDict.SetString("FacebookAppDisplayName", "少女的王座"); rootDict.SetBoolean("UIViewControllerBasedStatusBarAppearance", false); rootDict.CreateArray("UIBackgroundModes").AddString("remote-notification"); // 权限配置 rootDict.SetString("NSCameraUsageDescription", "是否允许访问相机?"); rootDict.SetString("NSPhotoLibraryAddUsageDescription", "是否允许添加照片?"); rootDict.SetString("NSMicrophoneUsageDescription", "是否允许访问相册?"); // URL types配置 PlistElementArray URLTypes = plist.root.CreateArray("CFBundleURLTypes"); string[] urlSchemes = { "fb1496435593826813", $"rastar{cchID}{appID}", "com.guanghuan.sndwzft", "liveops", "com.guanghuan.sndwzft://" }; foreach (string str in urlSchemes) { PlistElementDict typeRole = URLTypes.AddDict(); typeRole.SetString("CFBundleTypeRole", "Editor"); PlistElementArray urlScheme = typeRole.CreateArray("CFBundleURLSchemes"); urlScheme.AddString(str); } // LSApplicationQueriesSchemes配置 PlistElementArray LSApplicationQueriesSchemes = plist.root.CreateArray("LSApplicationQueriesSchemes"); // facebook接入配置 LSApplicationQueriesSchemes.AddString("fbapi"); LSApplicationQueriesSchemes.AddString("fb-messenger-share-api"); LSApplicationQueriesSchemes.AddString("fbauth2"); LSApplicationQueriesSchemes.AddString("fbshareextension"); // Navercafe接入配置 LSApplicationQueriesSchemes.AddString("navercafe"); LSApplicationQueriesSchemes.AddString("naversearchapp"); LSApplicationQueriesSchemes.AddString("naversearchthirdlogin"); // Line接入配置 LSApplicationQueriesSchemes.AddString("lineauth"); LSApplicationQueriesSchemes.AddString("line3rdp.$(APP_IDENTIFIER)"); LSApplicationQueriesSchemes.AddString("line"); plist.WriteToFile(plistPath); #endregion 修改Xcode工程Info.plist // Capabilitise添加 var entitlementsFileName = "celia.entitlements"; var entitlementsFilePath = Path.Combine("Assets/Plugins/iOS/SDK/", entitlementsFileName); File.Copy(entitlementsFilePath, Path.Combine(path, entitlementsFileName)); proj.AddFileToBuild(target, proj.AddFile(entitlementsFileName, entitlementsFileName, PBXSourceTree.Source)); proj.AddCapability(target, PBXCapabilityType.GameCenter); var array = rootDict.CreateArray("UIRequiredDeviceCapabilities"); array.AddString("armv7"); array.AddString("gamekit"); plist.WriteToFile(plistPath); proj.AddCapability(target, PBXCapabilityType.AssociatedDomains, entitlementsFileName); proj.AddCapability(target, PBXCapabilityType.BackgroundModes); proj.AddCapability(target, PBXCapabilityType.PushNotifications, entitlementsFileName); proj.WriteToFile(projPath); // 修改语言支持 // AddLanguage(path, new string[] { "zh", "zh-Hant", "vi-VN", "th", "ri", "ko", "es-ES", "id-ID" }); File.WriteAllText(projPath, proj.WriteToString()); }
public static void OnPostProcessBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS) { #if UNITY_IOS //localization NativeLocale.AddLocalizedStringsIOS(path, Path.Combine(Application.dataPath, "NativeLocale/iOS")); ConDebug.Log($"Application.dataPath = {Application.dataPath}"); var projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; var pbxProject = new PBXProject(); pbxProject.ReadFromFile(projectPath); // Facebook SDK가 Bitcode 미지원하므로 이 플래그를 꺼야 빌드가 된다. //string target = pbxProject.TargetGuidByName("Unity-iPhone"); var target = pbxProject.GetUnityMainTargetGuid(); pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); // DSYM 생성 안하도록 (빌드 시간 단축?) foreach (var configName in pbxProject.BuildConfigNames()) { var configGuid = pbxProject.BuildConfigByName(target, configName); pbxProject.SetBuildPropertyForConfig(configGuid, "DEBUG_INFORMATION_FORMAT", "dwarf"); } // 로컬 알림 관련해서 아래 프레임워크가 추가 되어야 한다. pbxProject.AddFrameworkToProject(target, "UserNotifications.framework", false); pbxProject.AddCapability(target, PBXCapabilityType.iCloud); pbxProject.AddCapability(target, PBXCapabilityType.GameCenter); pbxProject.AddCapability(target, PBXCapabilityType.InAppPurchase); // Facebook Audience Network에서 필요로 한다. pbxProject.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC"); pbxProject.AddFile(Path.Combine(Application.dataPath, "GoogleService-Info.plist"), "GoogleService-Info.plist"); var googleServiceInfoPlistGuid = pbxProject.FindFileGuidByProjectPath("GoogleService-Info.plist"); pbxProject.AddFileToBuild(target, googleServiceInfoPlistGuid); pbxProject.WriteToFile(projectPath); // en.lproj의 InfoPlist.strings 파일과 겹쳐서 빌드 오류난다. // 꼼수를... File.WriteAllText($"{path}/Unity-iPhone Tests/en.lproj/InfoPlist.strings", "\"CFBundleDisplayName\" = \"Color Museum\";"); var plistPath = Path.Combine(path, "Info.plist"); var plist = new PlistDocument(); plist.ReadFromFile(plistPath); // 수출 관련 규정 플래그 추가 (AppStore 제출 시 필요하다고 안내하고 있음) plist.root.SetBoolean("ITSAppUsesNonExemptEncryption", false); // 스크린샷을 앨범에 저장하고자 할 때 필요한 권한을 요청하는 팝업 설정 (지정하지 않으면 크래시) plist.root.SetString("NSPhotoLibraryUsageDescription", "Screenshot Save"); plist.root.SetString("NSPhotoLibraryAddUsageDescription", "Screenshot Save"); // https://developers.google.com/ad-manager/mobile-ads-sdk/ios/quick-start#update_your_infoplist plist.root.SetBoolean("GADIsAdManagerApp", true); // ERROR ITMS-90503: "Invalid Bundle. You've included the "arm64" value for the UIRequiredDeviceCapabilities key in your Xcode project, indicating that your app may only support 64-bit. Your binary, '<package name>', must only contain the 64-bit architecture slice. Learn more (https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW3)." var devCapArray = plist.root["UIRequiredDeviceCapabilities"].AsArray(); devCapArray.values = devCapArray.values.Where(e => e.AsString() != "arm64").ToList(); plist.root["UIRequiredDeviceCapabilities"] = devCapArray; plist.root.SetString("NSUserTrackingUsageDescription", TrackingDescription); plist.WriteToFile(plistPath); // Copy entitlements file File.Copy("black.entitlements", path + "/black.entitlements", true); #endif // https://stackoverflow.com/questions/55419956/how-to-fix-pod-does-not-support-provisioning-profiles-in-azure-devops-build const string podfileAppend = @" post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['CODE_SIGN_STYLE'] = ""Automatic""; end end end "; File.AppendAllText($"{path}/Podfile", podfileAppend); } }
/// <summary> /// Adds iCloud capability to project /// </summary> /// <param name="enableKeyValueStorage">Enables key-value storage option if set to true</param> /// <param name="enableiCloudDocument">Enables iCloud document option if set to true</param> /// <param name="enablecloudKit">Enables cloudKit option if set to true</param> /// <param name="addDefaultContainers">Default containers are added if this option is set to true</param> /// <param name="customContainers">A list of custom containers to add</param> public void AddiCloud(bool enableKeyValueStorage, bool enableiCloudDocument, bool enablecloudKit, bool addDefaultContainers, string[] customContainers) { var ent = GetOrCreateEntitlementDoc(); var val = (ent.root[ICloudEntitlements.ContainerIdKey] = new PlistElementArray()) as PlistElementArray; // Cloud document storage and CloudKit require specifying services. PlistElementArray ser = null; if (enableiCloudDocument || enablecloudKit) { ser = (ent.root[ICloudEntitlements.ServicesKey] = new PlistElementArray()) as PlistElementArray; } if (enableiCloudDocument) { val.values.Add(new PlistElementString(ICloudEntitlements.ContainerIdValue)); ser.values.Add(new PlistElementString(ICloudEntitlements.ServicesDocValue)); var ubiquity = (ent.root[ICloudEntitlements.UbiquityContainerIdKey] = new PlistElementArray()) as PlistElementArray; if (addDefaultContainers) { ubiquity.values.Add(new PlistElementString(ICloudEntitlements.UbiquityContainerIdValue)); } if (customContainers != null && customContainers.Length > 0) { // For cloud document, custom containers go in the ubiquity values. for (var i = 0; i < customContainers.Length; i++) { ubiquity.values.Add(new PlistElementString(customContainers[i])); } } } if (enablecloudKit) { if (addDefaultContainers && !enableiCloudDocument) { val.values.Add(new PlistElementString(ICloudEntitlements.ContainerIdValue)); } if (customContainers != null && customContainers.Length > 0) { // For CloudKit, custom containers also go in the container id values. for (var i = 0; i < customContainers.Length; i++) { val.values.Add(new PlistElementString(customContainers[i])); } } ser.values.Add(new PlistElementString(ICloudEntitlements.ServicesKitValue)); } if (enableKeyValueStorage) { ent.root[ICloudEntitlements.KeyValueStoreKey] = new PlistElementString(ICloudEntitlements.KeyValueStoreValue); } project.AddCapability(m_TargetGuid, PBXCapabilityType.iCloud, m_EntitlementFilePath, enablecloudKit); }
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()); }
static void ProcessPBXProject(string pathToBuiltProject) { var unityProjPath = Application.dataPath.Replace("Assets", ""); string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string target = proj.TargetGuidByName("Unity-iPhone"); var settings = GetiOSBuildOptions(); //1.1 framework && lib if (settings.SystemFiles != null) { foreach (var fileName in settings.SystemFiles) { if (fileName.EndsWith(".framework")) { proj.AddFrameworkToProject(target, fileName, false); } else { var fileGuid = proj.AddFile("usr/lib/" + fileName, "Frameworks/" + fileName, PBXSourceTree.Sdk); proj.AddFileToBuild(target, fileGuid); } } } //2 Capabilities if (settings.Capability != null) { foreach (var name in settings.Capability) { switch (name) { case "GameCenter": proj.AddCapability(target, PBXCapabilityType.GameCenter); break; case "InAppPurchase": proj.AddCapability(target, PBXCapabilityType.InAppPurchase); break; case "PushNotifications": proj.AddCapability(target, PBXCapabilityType.PushNotifications); var bundleIdLastIndex = settings.BundleIdentifier.LastIndexOf('.') + 1; var entitlementName = string.Format("{0}.entitlements", settings.BundleIdentifier.Substring(bundleIdLastIndex)); var capManager = new ProjectCapabilityManager(projPath, entitlementName, PBXProject.GetUnityTargetName()); capManager.AddPushNotifications(true); capManager.WriteToFile(); File.Copy(Path.Combine(pathToBuiltProject, entitlementName), Path.Combine(pathToBuiltProject, "Unity-iPhone", entitlementName), true); break; default: break; } } } //3 Info(Info.plist) string plistPath = pathToBuiltProject + "/Info.plist"; var plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); var plistRoot = plist.root; //麦克风权限 plistRoot.SetString("NSMicrophoneUsageDescription", "用于游戏内语音功能时访问麦克风收录语音"); plist.WriteToFile(plistPath); //4 Build Settings // 关闭bitcode(tolua不支持) proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); //5 class string unityAppControllerPath = pathToBuiltProject + "/Classes/UnityAppController.mm"; // 6 appiconset if (!string.IsNullOrEmpty(settings.AppIconSetPath)) { string dstPath = pathToBuiltProject + "/Unity-iPhone/Images.xcassets/AppIcon.appiconset/"; string srcPath = Path.Combine(unityProjPath, settings.AppIconSetPath); foreach (var file in Directory.GetFiles(srcPath)) { var to = Path.Combine(dstPath, Path.GetFileName(file)); File.Copy(file, to, true); } } // Save PBXProject proj.WriteToFile(projPath); }
public 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 pbxProject.AddCapability(targetGuid, PBXCapabilityType.InAppPurchase); pbxProject.AddCapability(targetGuid, PBXCapabilityType.iCloud); pbxProject.AddCapability(targetGuid, PBXCapabilityType.GameCenter); pbxProject.AddCapability(targetGuid, PBXCapabilityType.PushNotifications); // pbxProject.SetBuildProperty(targetGuid, "DEVELOPMENT_TEAM", "<set developement key here>"); var guid = pbxProject.FindFileGuidByProjectPath("Classes/UI/Keyboard.mm"); var flags = pbxProject.GetCompileFlagsForFile(targetGuid, guid); flags.Add("-fno-objc-arc"); pbxProject.SetCompileFlagsForFile(targetGuid, guid, flags); pbxProject.AddFrameworkToProject(targetGuid, "CloudKit.framework", false); 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.SetBoolean("ITSAppUsesNonExemptEncryption", false); // Add URL Scheme\ // Apply editing settings to Info.plist var cap = plist.root.CreateArray("UIRequiredDeviceCapabilities"); cap.AddString("gamekit"); plist.WriteToFile(plistPath); //----- var file_name = "unity.entitlements"; var proj_path = projectPath; var proj = new PBXProject(); proj.ReadFromFile(proj_path); // target_name = "Unity-iPhone" var target_name = PBXProject.GetUnityTargetName(); var target_guid = proj.TargetGuidByName(target_name); var dst = pathToBuiltProject + "/" + target_name + "/" + file_name; try { File.WriteAllText(dst, entitlements); proj.AddFile(target_name + "/" + file_name, file_name); proj.AddBuildProperty(target_guid, "CODE_SIGN_ENTITLEMENTS", target_name + "/" + file_name); proj.WriteToFile(proj_path); } catch (IOException e) { Debug.Log("Could not copy entitlements. Probably already exists. " + e); } UnityEditor.iOS.Xcode.ProjectCapabilityManager pcm = new UnityEditor.iOS.Xcode.ProjectCapabilityManager(proj_path, dst, target_name); pcm.AddPushNotifications(false); }
// ============================================================================================== /// <summary> /// IOS용 XCode Initialize /// </summary> // ReSharper disable once UnusedParameter.Local private static void Init_XCodeProject(string strXCodeProjectPath) { #if UNITY_IOS BuildConfig.IOSSetting pIOSSetting = g_pLastConfig.pIOSSetting; var projectPath = strXCodeProjectPath + "/Unity-iPhone.xcodeproj/project.pbxproj"; Debug.Log($"{const_strPrefix_ForDebugLog} {nameof(Init_XCodeProject)} Start - {nameof(strXCodeProjectPath)} : {strXCodeProjectPath}\n" + $"projectPath : {projectPath}"); PBXProject pPBXProject = new PBXProject(); pPBXProject.ReadFromFile(projectPath); string strTargetGuid = pPBXProject.TargetGuidByName("Unity-iPhone"); // Set Apple Team ID pPBXProject.SetTeamId(strTargetGuid, pIOSSetting.strAppleTeamID); // Copy File Asset To XCode Project foreach (var strFilePath in pIOSSetting.arrCopy_AssetFilePath_To_XCodeProjectPath) { CopyFile_Asset_To_XCode(strXCodeProjectPath, strFilePath); } // Add XCode Framework foreach (string strFramework in pIOSSetting.arrXCode_Framework_Add) { pPBXProject.AddFrameworkToProject(strTargetGuid, strFramework, false); Debug.Log($"{const_strPrefix_ForDebugLog} Add Framework \"{strFramework}\" to XCode Project"); } // Remove XCode Framework foreach (string strFramework in pIOSSetting.arrXCode_Framework_Remove) { pPBXProject.RemoveFrameworkFromProject(strTargetGuid, strFramework); Debug.Log($"{const_strPrefix_ForDebugLog} Remove Framework \"{strFramework}\" to XCode Project"); } // Set XCode OTHER_LDFLAGS pPBXProject.UpdateBuildProperty(strTargetGuid, "OTHER_LDFLAGS", pIOSSetting.arrXCode_OTHER_LDFLAGS_Add, pIOSSetting.arrXCode_OTHER_LDFLAGS_Remove); #region Sample // // Sample of setting build property // project.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); // 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); #endregion Sample string strTargetEntitlementsFilePath = strXCodeProjectPath + "/" + pIOSSetting.strEntitlementsFileName_Without_ExtensionName + ".entitlements"; pPBXProject.AddCapability(strTargetGuid, PBXCapabilityType.PushNotifications, strTargetEntitlementsFilePath, true); pPBXProject.AddCapability(strTargetGuid, PBXCapabilityType.InAppPurchase, null, true); pPBXProject.AddCapability(strTargetGuid, PBXCapabilityType.GameCenter, null, true); pPBXProject.AddBuildProperty(strTargetGuid, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)"); SetIOS_AuthToken(pPBXProject, strTargetGuid); // Apply settings File.WriteAllText(projectPath, pPBXProject.WriteToString()); #else Debug.Log($"{const_strPrefix_ForDebugLog} {nameof(Init_XCodeProject)} - Define Symbol is Not IOS"); #endif }
private static void AddCapability(MOBXCodeEditorModel xcodeModel, PBXProject xcodeProj, string xcodeTargetGuid, string xcodeTargetPath) { string projectPath = PBXProject.GetPBXProjectPath(xcodeTargetPath); if (xcodeModel.isOpenRestoreScene || xcodeModel.isHaveApple || xcodeModel.associatedDomains.Count > 0) { string entitlementsPath = xcodeModel.entitlementsPath; if (entitlementsPath == null || entitlementsPath == "" || !xcodeModel.entitlementsPath.Contains(".entitlements")) { string[] s = UnityEditor.PlayerSettings.applicationIdentifier.Split('.'); string productname = s[s.Length - 1]; entitlementsPath = "Unity-iPhone/" + productname + ".entitlements"; } #if UNITY_2018_1_OR_NEWER #if UNITY_2019_3_OR_NEWER ProjectCapabilityManager capManager = new ProjectCapabilityManager(projectPath, entitlementsPath, null, xcodeTargetGuid); #else ProjectCapabilityManager capManager = new ProjectCapabilityManager(projectPath, entitlementsPath, "Unity-iPhone"); #endif if (xcodeModel.associatedDomains.Count > 0 || xcodeModel.isHaveApple) { string[] domains = new string[xcodeModel.associatedDomains.Count]; int index = 0; foreach (string domainStr in xcodeModel.associatedDomains) { Debug.Log("AddCapabilityAssociatedDomains:" + domainStr); domains[index] = domainStr; index++; } //Debug.Log("xcodeTargetGuid:" + xcodeTargetGuid); //Debug.Log("xcodeTargetPath:" + xcodeTargetPath); //Debug.Log("projectPath:" + projectPath); //Debug.Log("GetUnityTargetName:" + PBXProject.GetUnityTargetName()); //Debug.Log("domainStr:" + MiniJSON.jsonEncode(domains)); if (capManager.GetType().GetMethod("AddAssociatedDomains") != null) { capManager.GetType().GetMethod("AddAssociatedDomains").Invoke(capManager, new object[] { domains }); } //Debug.Log("bundleIdentifier:" + UnityEditor.PlayerSettings.applicationIdentifier); //Debug.Log("productName:" + UnityEditor.PlayerSettings.productName); if (xcodeModel.isHaveApple && capManager.GetType().GetMethod("AddSignInWithApple") != null) { capManager.GetType().GetMethod("AddSignInWithApple").Invoke(capManager, null); } //推送 //capManager.AddPushNotifications(true); //内购 //capManager.AddInAppPurchase(); capManager.WriteToFile(); xcodeProj.AddCapability(xcodeTargetGuid, PBXCapabilityType.AssociatedDomains, xcodeTargetPath + "/" + entitlementsPath, true); } #else var entitlementFile = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version = \"1.0\"><dict>"; if (xcodeModel.associatedDomains.Count > 0 || xcodeModel.isHaveApple) { string[] domains = new string[xcodeModel.associatedDomains.Count]; int index = 0; foreach (string domainStr in xcodeModel.associatedDomains) { Debug.Log("AddCapabilityAssociatedDomains:" + domainStr); domains[index] = "<string>" + domainStr + "</string>"; index++; } var associatedDomainsString = ""; if (domains.Length > 0) { associatedDomainsString = "<key>com.apple.developer.associated-domains</key><array>" + string.Join("", domains) + "</array>"; } var appleString = ""; if (xcodeModel.isHaveApple) { appleString = "<key>com.apple.developer.applesignin</key><array><string> Default </string></array>"; } entitlementFile = entitlementFile + associatedDomainsString + appleString + "</dict></plist>"; } Debug.LogWarning(entitlementFile); Debug.LogWarning(xcodeTargetPath + "/" + entitlementsPath); Debug.LogWarning(xcodeTargetPath); StreamWriter sWriter = new StreamWriter(xcodeTargetPath + "/" + entitlementsPath); sWriter.WriteLine(entitlementFile); sWriter.Close(); sWriter.Dispose(); xcodeProj.AddBuildProperty(xcodeTargetGuid, "CODE_SIGN_ENTITLEMENTS", entitlementsPath); string fileGuid = (string)xcodeProj.AddFile(xcodeTargetPath + "/" + entitlementsPath, entitlementsPath, PBXSourceTree.Absolute); xcodeProj.AddFileToBuild(xcodeTargetGuid, fileGuid); #endif } }
public static void OnPostProcessBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS) { #if UNITY_IOS //localization NativeLocale.AddLocalizedStringsIOS(path, Path.Combine(Application.dataPath, "NativeLocale/iOS")); SushiDebug.Log("DEBUG_________Application datapath:" + Application.dataPath); string projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromFile(projectPath); // Facebook SDK가 Bitcode 미지원하므로 이 플래그를 꺼야 빌드가 된다. //string target = pbxProject.TargetGuidByName("Unity-iPhone"); string target = pbxProject.GetUnityMainTargetGuid(); pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); // 로컬 알림 관련해서 아래 프레임워크가 추가 되어야 한다. pbxProject.AddFrameworkToProject(target, "UserNotifications.framework", false); pbxProject.AddCapability(target, PBXCapabilityType.iCloud); pbxProject.AddCapability(target, PBXCapabilityType.GameCenter); pbxProject.AddCapability(target, PBXCapabilityType.InAppPurchase); pbxProject.WriteToFile(projectPath); var plistPath = Path.Combine(path, "Info.plist"); var plist = new PlistDocument(); plist.ReadFromFile(plistPath); // 수출 관련 규정 플래그 추가 (AppStore 제출 시 필요하다고 안내하고 있음) plist.root.SetBoolean("ITSAppUsesNonExemptEncryption", false); // 스크린샷을 앨범에 저장하고자 할 때 필요한 권한을 요청하는 팝업 설정 (지정하지 않으면 크래시) plist.root.SetString("NSPhotoLibraryUsageDescription", "Screenshot Save"); plist.root.SetString("NSPhotoLibraryAddUsageDescription", "Screenshot Save"); // 최신 AdMob SDK에서는 아래 항목이 필수다...헛헛헛... plist.root.SetString("GADApplicationIdentifier", "ca-app-pub-5072035175916776~2508482457"); // https://developers.google.com/ad-manager/mobile-ads-sdk/ios/quick-start#update_your_infoplist plist.root.SetBoolean("GADIsAdManagerApp", true); // ERROR ITMS-90503: "Invalid Bundle. You've included the "arm64" value for the UIRequiredDeviceCapabilities key in your Xcode project, indicating that your app may only support 64-bit. Your binary, 'com.pronetizen.sushi', must only contain the 64-bit architecture slice. Learn more (https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW3)." var devCapArray = plist.root["UIRequiredDeviceCapabilities"].AsArray(); devCapArray.values = devCapArray.values.Where(e => e.AsString() != "arm64").ToList(); plist.root["UIRequiredDeviceCapabilities"] = devCapArray; plist.root.SetString("NSUserTrackingUsageDescription", TrackingDescription); plist.WriteToFile(plistPath); // Copy entitlements file System.IO.File.Copy("balloon.entitlements", path + "/balloon.entitlements", true); // https://stackoverflow.com/questions/55419956/how-to-fix-pod-does-not-support-provisioning-profiles-in-azure-devops-build var podfileAppend = @" post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['CODE_SIGN_STYLE'] = ""Automatic""; end end end "; File.AppendAllText($"{path}/Podfile", podfileAppend); #endif } }
// PBXProject編集. static void EditPBXProject(string pbxPath) { Debug.Log(">>>>>>>> EditPBXProject"); var pbx = new PBXProject(); pbx.ReadFromFile(pbxPath); var targetGuid = pbx.TargetGuidByName("Unity-iPhone"); pbx.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); // EnableBitCodeをfalseに. // ビルド設定.マニュアルにする.DEVELOPMENT_TEAMを設定するとAutomaticaryにされるっぽいので注意. pbx.SetBuildProperty(targetGuid, "CODE_SIGN_STYLE", "Manual"); if(!BatchBuild.IsReleaseBuild){ pbx.SetBuildProperty(targetGuid, "CODE_SIGN_IDENTITY", "iPhone Distribution: SMILE-LAB CO., LTD. (N7GKJM7E62)"); }else{ pbx.SetBuildProperty(targetGuid, "CODE_SIGN_IDENTITY", "iPhone Distribution: FUJI GAMES, INC. (KQ4JCYSACP)"); } // プロビジョニング設定. #if ではこの回のビルド時の切り替えを判別できない.BatchBuild時に予め設定しておくようにする. if(!string.IsNullOrEmpty(BatchBuild.ProvisioningAtBuildTime)){ pbx.SetBuildProperty(targetGuid, "PROVISIONING_PROFILE_SPECIFIER", BatchBuild.ProvisioningAtBuildTime); } // SmartBeat用にlibzを追加 pbx.AddFileToBuild(targetGuid, pbx.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk)); // Adjust用にiAd追加、Linkerフラグ-ObjCを追加、Objective-C exceptionsを有効化 pbx.AddFrameworkToProject(targetGuid, "iAD.framework", true); // Enable Objective-C Exceptions = YES pbx.SetBuildProperty (targetGuid, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES"); // "Other Linker Flags" に "-ObjC" を追加 pbx.AddBuildProperty (targetGuid, "OTHER_LDFLAGS", "-ObjC"); // --- Capabilitiesの設定 --- // リモート通知 /* // TODO: フォーラムから応用 いい方法を知りたい var entitlementsMaster = ScriptableObject.CreateInstance<iOSEntitlementsSetting>(); DefaultAsset entitlementsFile = null; if (!BatchBuild.IsReleaseBuild) { entitlementsFile = entitlementsMaster.RomDev; } else { entitlementsFile = entitlementsMaster.RomRelease; } ScriptableObject.DestroyImmediate(entitlementsMaster); if (entitlementsFile != null) { //ビルドの出力先を取得 var builtProjectPath = pbxPath.Replace ("/Unity-iPhone.xcodeproj/project.pbxproj", ""); // Copy the entitlement file to the xcode project var entitlementPath = AssetDatabase.GetAssetPath (entitlementsFile); var entitlementFileName = Path.GetFileName (entitlementPath); var unityTarget = PBXProject.GetUnityTargetName(); var relativeDestination = unityTarget + "/" + entitlementFileName; FileUtil.CopyFileOrDirectory(entitlementPath, builtProjectPath + "/" + relativeDestination); // Add the pbx configs to include the entitlements files on the project pbx.AddFile(relativeDestination, entitlementFileName); // 通知の設定 pbx.AddBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", relativeDestination); // Add push notifications as a capability on the target pbx.AddBuildProperty(targetGuid, "SystemCapabilities", "{com.apple.Push = {enabled = 1;};}"); } else { pbx.AddCapability(targetGuid, PBXCapabilityType.PushNotifications); } */ pbx.AddCapability(targetGuid, PBXCapabilityType.PushNotifications); File.WriteAllText(pbxPath, pbx.WriteToString()); }
private static void CorrectXCodeProject(string pathToProject, bool writeOut) { string path = Path.Combine(Path.Combine(pathToProject, "Unity-iPhone.xcodeproj"), "project.pbxproj"); string xcodeproj = File.ReadAllText(path); // 1. Make sure it can run on devices and emus! xcodeproj = SetValueOfXCodeGroup("SDKROOT", xcodeproj, "\"iphoneos\""); // 2. Enable Objective C exceptions xcodeproj = xcodeproj.Replace("GCC_ENABLE_OBJC_EXCEPTIONS = NO;", "GCC_ENABLE_OBJC_EXCEPTIONS = YES;"); // 3. Remove Android content that gets injected in the XCode project xcodeproj = Regex.Replace(xcodeproj, @"^.*Libraries/Plugins/Android/SwrveSDKPushSupport.*$", "", RegexOptions.Multiline); // 4. Add required frameworks for Conversations PBXProject project = new PBXProject(); project.ReadFromString(xcodeproj); #if UNITY_2019_3_OR_NEWER string targetGuid = project.GetUnityFrameworkTargetGuid(); #else string targetGuid = project.TargetGuidByName("Unity-iPhone"); #endif project.AddFrameworkToProject(targetGuid, "Webkit.framework", true /*weak*/); // 6. Add conversations resources to bundle if (!AddFolderToProject(project, targetGuid, "Assets/Plugins/iOS/SwrveConversationSDK/Resources", pathToProject, "Libraries/Plugins/iOS/SwrveConversationSDK/Resources")) { UnityEngine.Debug.LogError("Swrve SDK - Could not find the Conversation resources folder in your project. If you want to use Conversations please contact [email protected]"); } // 7. Add the required frameworks for push notifications project.AddFrameworkToProject(targetGuid, "UserNotifications.framework", true /*weak*/); project.AddFrameworkToProject(targetGuid, "UserNotificationsUI.framework", true /*weak*/); // 8. Add framework required for SwrveCommmonSDK for SwrveUtils. It needs CoreTelephony.framework project.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false /*weak*/); string appGroupIndentifier = SwrveBuildComponent.GetPostProcessString(SwrveBuildComponent.APP_GROUP_ID_KEY); if (string.IsNullOrEmpty(appGroupIndentifier)) { SwrveLog.Log("Swrve iOS Rich Push requires an iOSAppGroupIdentifier set in the postprocess.json file. Without it there will be no influence tracking and potential errors."); } else { // 8. Add Extension Target for Push project = AddExtensionToProject(project, pathToProject); // 9. Add Entitlements to project project.AddCapability(targetGuid, PBXCapabilityType.AppGroups, null, false); project.AddCapability(targetGuid, PBXCapabilityType.PushNotifications, null, false); } // Write changes to the Xcode project xcodeproj = project.WriteToString(); if (writeOut) { File.WriteAllText(path, xcodeproj); } }
// Enables Advanced Push Capabilities private static PBXProject AddExtensionToProject(PBXProject project, string pathToProject) { PBXProject proj = project; #if UNITY_2019_3_OR_NEWER string mainTarget = proj.GetUnityMainTargetGuid(); #else string mainTarget = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); #endif // Add Push files to the extension CopyFolder("Assets/Plugins/iOS/SwrvePushExtension", pathToProject + "/SwrvePushExtension"); string extensionTarget = proj.AddAppExtension(mainTarget, "SwrvePushExtension", PlayerSettings.applicationIdentifier + ".ServiceExtension", "SwrvePushExtension/Info.plist"); // Ensure Service Files are part of the Build Phases proj.AddFile(pathToProject + "/SwrvePushExtension/NotificationService.h", "SwrvePushExtension/NotificationService.h"); proj.AddFileToBuild(extensionTarget, proj.AddFile(pathToProject + "/SwrvePushExtension/NotificationService.m", "SwrvePushExtension/NotificationService.m")); // Add TeamID from Player Settings to project proj.SetTeamId(extensionTarget, PlayerSettings.iOS.appleDeveloperTeamID); // Add Extension Common if (!AddFolderToProject(proj, extensionTarget, "Assets/Plugins/iOS/SwrveSDKCommon", pathToProject, "SwrvePushExtension/SwrveSDKCommon")) { UnityEngine.Debug.LogError("Swrve SDK - Could not find the Common folder in the extension. If you want to use Rich Push please contact [email protected]"); } // Add Frameworks needed for SwrveSDKCommon proj.AddFrameworkToProject(extensionTarget, "AudioToolbox.framework", false /*weak*/); proj.AddFrameworkToProject(extensionTarget, "AVFoundation.framework", true /*weak*/); proj.AddFrameworkToProject(extensionTarget, "CFNetwork.framework", false /*weak*/); proj.AddFrameworkToProject(extensionTarget, "CoreGraphics.framework", false /*weak*/); proj.AddFrameworkToProject(extensionTarget, "CoreMedia.framework", false /*weak*/); proj.AddFrameworkToProject(extensionTarget, "CoreMotion.framework", false /*weak*/); proj.AddFrameworkToProject(extensionTarget, "CoreVideo.framework", false /*weak*/); proj.AddFrameworkToProject(extensionTarget, "CoreTelephony.framework", false /*weak*/); proj.AddFrameworkToProject(extensionTarget, "Foundation.framework", false /*not weak*/); proj.AddFrameworkToProject(extensionTarget, "iAd.framework", false /*weak*/); proj.AddFrameworkToProject(extensionTarget, "MediaPlayer.framework", true /*weak*/); proj.AddFrameworkToProject(extensionTarget, "UIKit.framework", true /*weak*/); proj.AddFrameworkToProject(extensionTarget, "AdSupport.framework", false /*not weak*/); // Add Notification Frameworks proj.AddFrameworkToProject(extensionTarget, "UserNotifications.framework", false /*not weak*/); proj.AddFrameworkToProject(extensionTarget, "UserNotificationsUI.framework", false /*not weak*/); // Update Build Settings for Compatibility proj.AddBuildProperty(extensionTarget, "CLANG_ENABLE_OBJC_ARC", "YES"); proj.AddBuildProperty(extensionTarget, "IPHONEOS_DEPLOYMENT_TARGET", "10.0"); proj.AddBuildProperty(extensionTarget, "TARGETED_DEVICE_FAMILY", "1,2"); proj.AddBuildProperty(extensionTarget, "ARCHS", "$(ARCHS_STANDARD)"); // Add appgroupconfig.json to XCode project string appGroupIndentifier = SwrveBuildComponent.GetPostProcessString(SwrveBuildComponent.APP_GROUP_ID_KEY); string appGroupConfig = "appgroupconfig.json"; // Add the app group config so it can be read at run-time by the main app and the service extension SwrveBuildComponent.SetAppGroupConfigKey("ios", Path.Combine(pathToProject + "/SwrvePushExtension", appGroupConfig)); proj.AddFileToBuild(extensionTarget, proj.AddFile(pathToProject + "/SwrvePushExtension/" + appGroupConfig, "SwrvePushExtension/" + appGroupConfig)); proj.AddFileToBuild(mainTarget, proj.AddFile(pathToProject + "/SwrvePushExtension/" + appGroupConfig, "SwrvePushExtension/" + appGroupConfig)); // Edit template entitlements file string entitlementContents = File.ReadAllText(pathToProject + "/SwrvePushExtension/SwrvePushExtension.entitlements"); entitlementContents = entitlementContents.Replace("<string>APP_GROUP_TEMP</string>", "<string>" + appGroupIndentifier + "</string>"); File.WriteAllText(pathToProject + "/SwrvePushExtension/SwrvePushExtension.entitlements", entitlementContents); // Add entitlements file to service extension proj.AddFileToBuild(extensionTarget, proj.AddFile(pathToProject + "/SwrvePushExtension/SwrvePushExtension.entitlements", "SwrvePushExtension/SwrvePushExtension.entitlements")); proj.AddCapability(extensionTarget, PBXCapabilityType.AppGroups, "SwrvePushExtension/SwrvePushExtension.entitlements", false); // Return edited project return(proj); }
public static void AddMyCapability(this PBXProject pbxProject, PBXCapabilityType capabilityType) { pbxProject.AddCapability(pbxProject.UnityTargetGuid(), capabilityType, EntitlementsFileName, true); }
public static void IOSXcodeSettings() { string CurPath = path; //if (!string.IsNullOrEmpty(_path)) //{ // CurPath = _path; //} //添加XCode引用的Framework string projPath = PBXProject.GetPBXProjectPath(CurPath); 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非常需要的 #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(path, "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("fbapi20130214"); LSApplicationQueriesSchemes.AddString("fbapi20130410"); LSApplicationQueriesSchemes.AddString("fbapi20130702"); LSApplicationQueriesSchemes.AddString("fbapi20131010"); LSApplicationQueriesSchemes.AddString("fbapi20131219"); LSApplicationQueriesSchemes.AddString("fbapi20140410"); LSApplicationQueriesSchemes.AddString("fbapi20140116"); LSApplicationQueriesSchemes.AddString("fbapi20150313"); LSApplicationQueriesSchemes.AddString("fbapi20150629"); LSApplicationQueriesSchemes.AddString("fbapi20160328"); 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 // Capabilitise添加 //var entitlementsFileName = "tw.entitlements"; //var entitlementsFilePath = Path.Combine("Assets/Plugins/iOS/SDK/", entitlementsFileName); //File.Copy(entitlementsFilePath, Path.Combine(path, entitlementsFileName)); //proj.AddFileToBuild(target, proj.AddFile(entitlementsFileName, entitlementsFileName, PBXSourceTree.Source)); proj.AddCapability(target, PBXCapabilityType.GameCenter); proj.AddCapability(target, PBXCapabilityType.InAppPurchase); //添加推送和其他的有点不一样,需要添加一个文件。这个文件只能考进去。 //或者事先准备好了Base.entitlements 文件,文件类容 就是手动添加进去的内容,手动添加完成后生成的那个文件 //proj.AddCapability(target, PBXCapabilityType.PushNotifications, entitlementsFileName); //ProjectCapabilityManager projectCapabilityManager = new ProjectCapabilityManager(projPath, "tw.entitlements", PBXProject.GetUnityTargetName()); //projectCapabilityManager.AddGameCenter(); //projectCapabilityManager.AddInAppPurchase(); plist.WriteToFile(plistPath); proj.WriteToFile(projPath); Debug.Log("--**--4.IOSXcodeSettings--**--"); }