Menu

iOS import matters

Unity3D-iOS import instructions

1 iOS configuration instructions

After using Unity to compile the Xcode project, open the Xcode project, introduce the required SDK according to the instructions of each third-party platform, and link the system framework and lib it depends on. You can also see TopOn's platform access help.

All third-party Framework packages are included in Unity's sdk package. Unnecessary sdk packages can be deleted as needed. Details of which platforms require the introduction of which packages Please check the help document above

According to the information listed above, introduce the SDK required by each third-party network and introduce the system framework and lib according to the requirements of each SDK. After introducing the system framework and lib, you need to build Settings perform the following configuration:

1 In the Xcode project's Build Settings , search for bitcode and change its value to NO (In Xcode projects compiled by the current version of Unity (2018.02), this setting defaults to Yes), As shown in the picture:

2 Build Settings, search runpath search paths , and change its value to @executable_path/Frameworks as shown in the figure:

3 In the Xcode project's Build Settings, search for other linker flags and add -ObjC, -fobjc-arc As shown in the picture:


Note: If you integrate Pangolin v3.5.0.0 or above, you need to add additional -l"c++", -l"c++abi", -l"sqlite3", -l"z" as shown in the figure:

4 In the Build Settings of the Xcode project, search for C Language Dialect and change its value to GNU99[-std=gnu99] as shown in the figure:

All the above configuration can be done programmatically using C# Editor Script:


#if (UNITY_5 && UNITY_IOS) || UNITY_IPHONE
using UnityEditor.iOS.Xcode;
#endif

public static class MyBuildPostprocess
{
    [PostProcessBuild(999)]
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        #if (UNITY_5 && UNITY_IOS) || UNITY_IPHONE
            if (buildTarget == BuildTarget.iOS)
            {
                string projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

                PBXProject pbxProject = new PBXProject();
                pbxProject.ReadFromFile(projectPath);

                //Used by unity 2019.4.x or above
                string target = pbxProject.GetUnityFrameworkTargetGuid();
                //Used under Unity 2019.4.x
                // string target = pbxProject.GetUnityMainTargetGuid();
                //Unity 2018, 2017 version can be used
                // string target = pbxProject.TargetGuidByName("Unity-iPhone"); 

                pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
                pbxProject.SetBuildProperty(target, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");
                pbxProject.SetBuildProperty(target, "GCC_C_LANGUAGE_STANDARD", "gnu99");

                pbxProject.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
                pbxProject.AddBuildProperty(target, "OTHER_LDFLAGS", "-fobjc-arc");
                pbxProject.AddFileToBuild(target, pbxProject.AddFile("usr/lib/libxml2.tbd", "Libraries/libxml2.tbd", PBXSourceTree.Sdk));
                pbxProject.AddFileToBuild(target, pbxProject.AddFile("usr/lib/libresolv.9.tbd", "Libraries/libresolv.9.tbd", PBXSourceTree.Sdk));
                #if UNITY_2019_3_OR_NEWER
                pbxProject.AddFileToBuild(target, pbxProject.AddFile("Frameworks/AnyThinkAds/Plugins/iOS/Core/AnyThinkSDK.bundle", "Frameworks/AnyThinkAds/Plugins/iOS/Core/AnyThinkSDK.bundle", PBXSourceTree.Sdk));
                #else
                #endif
                pbxProject.WriteToFile (projectPath);

                var plistPath = Path.Combine(path, "Info.plist");
                PlistDocument plist = new PlistDocument();
                plist.ReadFromFile(plistPath);

                // 集成admob平台时需要设置,传入admob的Appid
                // plist.root.SetString("GADApplicationIdentifier", "ca-app-pub-9488501426181082~7319780494");
                // plist.root.SetBoolean("GADIsAdManagerApp", true);
                plist.WriteToFile(plistPath);
        }
        #endif
    }
}

Note: You need to write this code to a C# file and place it in the Editor directory of Unity3D IDE:

2 CocoaPods introduction instructions

CocoaPods is a tool used to help us manage third-party dependent libraries. It can resolve dependencies between libraries, download the source code of the library, and connect these third-party libraries to our projects by creating an Xcode workspace. Up, convenient for development. If you have not installed the Cocoapods environment, please refer to CocoaPods Official tutorial.

Starting from version v5.7.98, the advertising platform SDK will be introduced via Cocoapod. Please follow the steps below:

  1. Before introducing a new version of the SDK, you must first delete all the old versions of the SDK to prevent the residue of the old version of the SDK from affecting subsequent pod integration. The adjusted files in the new version only retain the Editor files corresponding to the platform, and the directory structure is as follows:
  2. After exporting the Xcode project from Unity IDE, go to the project directory to find the Podfile file, for example:
  3. Complete Unity related configuration according to the iOS configuration instructions. The Podfile file can be referred to as shown in the figure:
  4. After the configuration is completed, use the terminal to go to the project directory and execute pod install or pod update2.1 Notes (1) Since the SDKs of Kuaishou, Start.io, BigoAds and PubNative are dynamic libraries, introducing them through CocoaPods will cause incorrect judgment of checkAdStatus , so we recommend using the manual introduction of Kuaishou SDK. Taking the introduction of Kuaishou SDK as an example, the operation is as follows:
  5. Download and select the SDK package for the corresponding version of iOS through our Document Center. As shown in the picture:
  6. After decompression, find AnyThinkKuaiShouAdapter.framework and Kuaishou related SDK and import them into the Xcode project. As shown in the picture:
  7. The last step is to modify the Embed property of KSAdSDK.framework in the main project after importing. As shown in the picture: Note: Since the Kuaishou platform does not support bitcode, if there is an integrated Kuaishou platform, you need to search for bitcode in the Build Settings of the Xcode project and change its value to NO

(2) If you integrate Pangolin domestically and overseas at the same time, you need to manually modify the Podfile and replace the original pod

​'AnyThinkiOS/AnyThinkTTAdapter','5.9.51' and pod 'AnyThinkiOS/AnyThinkPangleAdapter','5.9.51' annotation, change to use: pod 'AnyThinkPangleGlobalAdapter','5.9.51'

If everything goes well, you should compile your project. If you use Cocoapod to manage third-party libraries, please use a file with the suffix xcworkspace such as Unity-iPhone.xcworkspace to open the project. If it is a manually integrated third-party SDK, please use Unity-iPhone.xcodeproj opens the project.

3 常见问题

  1. Unity exports the Xcode project successfully, but prompts: iOS framework addition failed due to a CocoaPods installation failure. This will likely result in an non-functional Xcode project.

Solution:

(1): Terminal execution $open ~/.bash_profile

(2): Add export LANG=en_US.UTF-8

(3): Save and close the bash_profile file

(4): Re-execute untiy to export xcode

  1. After importing the advertising SDK of Unity Ads, if an error occurs, as shown in the figure below:

Solution: You need to create a Swift file in the project for bridging, right-click New File in the Xcode directory, select Swift File, and select as shown in the picture. After clicking Create, a dialog box will appear, click Confirm.

  1. Invalid Bundle appears when Xcode is packaged. The bundle at 'ProductName.app/Frameworks/ UnityFramework.framework' contains disallowed file 'Frameworks'. As shown in the picture:

解决办法:
在Build Settings -> always embed swift standard Libraries 设置为NO。如图:



Last modified: 2025-05-30Powered by