0
0

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 3 years have passed since last update.

【Swift】App Tracking Transparencyでアップル審査Rejectされた

Posted at

概要

iOSアプリがアップルの審査でリジェクトされた。
内容は、App Tracking Transparencyの許可を求めるポップアップが出てこないというもの。
原因は、iOS15で仕様変更により、アプリがアクティブなとき(UIApplicationStateActive)にのみApp Tracking Transparencyの許可リクエストを行う必要があるということでした。
その対処方法をまとめる。
Screen Shot 2022-03-18 at 16.54.21.png

ソースコード これまで

	override func viewDidLoad() {
		// これまでは、ここにATTの処理を書いていた
	}

ソースコード これから

ATTの処理は、viewDidLoad()ではなく、applicationDidBecomeActive()に記述する。

import AppTrackingTransparency // IDFA対応
import AdSupport // IDFA対応

func applicationDidBecomeActive(_ application: UIApplication) {

        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
        // IDFA対応
        if #available(iOS 14, *) {
            switch ATTrackingManager.trackingAuthorizationStatus {
            case .authorized:
                print("Allow Tracking")
                print("IDFA: \(ASIdentifierManager.shared().advertisingIdentifier)")
            case .denied:
                print("😭拒否")
            case .restricted:
                print("🥺制限")
            case .notDetermined:
                showRequestTrackingAuthorizationAlert()
            @unknown default:
                fatalError()
            }
        }
        else {
        // iOS14未満
            if ASIdentifierManager.shared().isAdvertisingTrackingEnabled {
                print("Allow Tracking")
                print("IDFA: \(ASIdentifierManager.shared().advertisingIdentifier)")
            } else {
                print("🥺制限")
            }
        }
    }

    private func showRequestTrackingAuthorizationAlert() {
        if #available(iOS 14, *) {
            ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
                switch status {
                case .authorized:
                    print("🎉")
                    //IDFA取得
                    print("IDFA: \(ASIdentifierManager.shared().advertisingIdentifier)")
                case .denied, .restricted, .notDetermined:
                    print("😭") 
// viewDidLoad()に記述した場合、ここを通るが、ポップアップは表示されていなかった
                @unknown default:
                    fatalError()
                }
            })
        }
    }

参考

iOS15でATT(App Tracking Transparency)の許可ダイアログが表示されない場合に確認すること
https://qiita.com/shindyu/items/10f5ee8d92eea9f80be4

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?