我正在Unity手机版中制作游戏。
我正在使用Ironsource作为广告中介。我已经将SDK添加到我的项目中,并且可以在Android上使用。

如果我将构建目标切换到iOS,则会收到编译器错误。

Assets \ IronSource \ Editor \ IronSourceBuildPostprocessor.cs(53,48):错误
CS0619:“PBXProject.GetUnityTargetName()”已过时:“此函数
不推荐使用。现在有两个目标
GetUnityMainTargetGuid()-适用于应用程序或GetUnityFrameworkTargetGuid()-
让源代码/插件获得Guid而不是调用
TargetGuidByName(GetUnityTargetName())。

我在Unity 2019.3.2f1
在2019.3之后的任何版本中,该功能均已弃用。

因此,无需等待修复或Ironsource的答复,我可以自己解决此问题,方法是用错误中建议的任何一个替换不推荐使用的功能...

但是哪一个呢?我不知道该功能做什么。
这是来自ironsource sdk的整个 class ,这里的线路是..
该文件称为IronSourceBuildPostprocessor.cs
香港专业教育学院划坏线。

#if UNITY_IOS

using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Reflection;

namespace IronSource.Editor
{
    public class IronSourceBuildPostprocessor
    {
        [PostProcessBuild]
        public static void OnPostprocessBuild (BuildTarget buildTarget, string buildPath)
        {
            if (buildTarget == BuildTarget.iOS) {
                string projectPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
                string dirpath = Application.dataPath + "/IronSource/Editor/";
                string currentNamespace = MethodBase.GetCurrentMethod().DeclaringType.Namespace;

                updateProject (buildTarget, projectPath);

                if (Directory.Exists (dirpath)) {
                    //Match the classes that has "Settings" in their name, and don't start with "I"
                    var files = Directory.GetFiles (dirpath, "*.cs", SearchOption.TopDirectoryOnly).Where (file => Regex.IsMatch (Path.GetFileName (file), "^(?!IAdapter).+Settings.*$"));

                    //Go over all the adapter settings classes, and call their updateProject method
                    foreach (string file in files) {
                        string classname = Path.GetFileNameWithoutExtension (file);

                        if (!String.IsNullOrEmpty (classname)) {
                            IAdapterSettings adapter = (IAdapterSettings)Activator.CreateInstance (Type.GetType (currentNamespace + "." + classname));
                            adapter.updateProject (buildTarget, projectPath);
                        }
                    }
                }
            }

            Debug.Log ("IronSource build postprocessor finished");
        }

        private static void updateProject (BuildTarget buildTarget, string projectPath)
        {
            Debug.Log ("IronSource - Update project for IronSource");

            PBXProject project = new PBXProject ();
            project.ReadFromString (File.ReadAllText (projectPath));

            string targetId = project.TargetGuidByName (PBXProject.GetUnityTargetName ()); // THIS IS BAD LINE!!!

            // Required System Frameworks
            project.AddFrameworkToProject (targetId, "AdSupport.framework", false);
            project.AddFrameworkToProject (targetId, "AudioToolbox.framework", false);
            project.AddFrameworkToProject (targetId, "AVFoundation.framework", false);
            project.AddFrameworkToProject (targetId, "CoreGraphics.framework", false);
            project.AddFrameworkToProject (targetId, "CoreMedia.framework", false);
            project.AddFrameworkToProject (targetId, "CoreTelephony.framework", false);
            project.AddFrameworkToProject (targetId, "CoreVideo.framework", false);
            project.AddFrameworkToProject (targetId, "CFNetwork.framework", false);
            project.AddFrameworkToProject (targetId, "Foundation.framework", false);
            project.AddFrameworkToProject (targetId, "MobileCoreServices.framework", false);
            project.AddFrameworkToProject (targetId, "QuartzCore.framework", false);
            project.AddFrameworkToProject (targetId, "Security.framework", false);
            project.AddFrameworkToProject (targetId, "StoreKit.framework", false);
            project.AddFrameworkToProject (targetId, "SystemConfiguration.framework", false);
            project.AddFrameworkToProject (targetId, "WebKit.framework", false);


            project.AddFileToBuild (targetId, project.AddFile ("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));

            // Custom Link Flag
            project.AddBuildProperty (targetId, "OTHER_LDFLAGS", "-ObjC");

            File.WriteAllText (projectPath, project.WriteToString ());
        }
    }
}
#endif

最佳答案

所以Ironsource说要这样做。

#if UNITY_2019_3_OR_NEWER
string targetId = project.GetUnityFrameworkTargetGuid();
#else
string targetId = project.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif

他们还说:“这是Unity和Apple的错误,但您可以尝试一下。”这显然是总BS。他们为什么不通过添加这些行来修复SDK?

关于ios - 如何在iOS上修复Ironsource Unity SDK中的错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60459020/

10-11 12:15