3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Unity】Unity純正でiOS ATT許可ダイアログを出す

Last updated at Posted at 2021-07-17

元ネタはここです。

App Tracking Transparency in Unity (IDFA Popup)

#パッケージをインストール
Package ManagerのUnity RegistryからiOS 14 Advertising Supportをインストールします。
スクリーンショット 2021-07-17 8.51.34.png
このパッケージは以前はプレビュー版でしたが現在(Unity 2021.1.15f1)はPackage Managerに出てきます。
将来はUnity本体に内蔵されると思われます。

#コード

#if UNITY_IOS

using Unity.Advertisement.IosSupport;

#endif

#if UNITY_IOS

    if(ATTrackingStatusBinding.GetAuthorizationTrackingStatus() == 
    ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED)
    {
        ATTrackingStatusBinding.RequestAuthorizationTracking();
    }

#endif

#NSUserTrackingUsageDescriptionをInfo.plistに追加する
これも将来はUnityに内蔵されると思いますが、現在はないのでEditorフォルダにビルドの後処理を書きます。

using UnityEditor;
using UnityEditor.Callbacks;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif
using System.IO;

public class PostBuildProcessing : IPostprocessBuildWithReport
{
    //  実行順
    int IOrderedCallback.callbackOrder => 100;

    // ビルド後処理
    public void OnPostprocessBuild(BuildReport report)
    {
#if UNITY_IOS

        PlistDocument plistObj = new PlistDocument();
        string projectPlistPath = report.summary.outputPath + "/Info.plist";
        plistObj.ReadFromString(File.ReadAllText(projectPlistPath));
        PlistElementDict plistRoot = plistObj.root;

        plistRoot.SetString("NSUserTrackingUsageDescription", "This identifier will be used to deliver personalized ads to you.");
        File.WriteAllText(projectPlistPath, plistObj.WriteToString());

#endif
}

追記

NSUserTrackingUsageDescription は Localization を使えばいいそうです。

アプリ名(Display Name)やiOSの広告トラッキング許諾文言(NSUserTrackingUsageDescription)をLocalizationで簡単ローカライズ(多言語対応) 【Unity】【Localization】【iOS】【Android】

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?