0
2

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.

【SwiftUI】iOS15以降 & SwiftUIでATT許可ダイアログを出す

Last updated at Posted at 2022-08-16

以前は didFinishLaunching でATT許可ダイアログ出してもいけましたが、iOS15からはアプリがアクティブな状態でないとダイアログが出なくなりました。
そこでSwiftUIでATTダイアログを出す方法です。

struct MainView: View {
    var body: some View {
        VStack {
            Text("Hello!")
        }
        .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
            if ATTrackingManager.trackingAuthorizationStatus == .notDetermined {
                ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in })
            }
        }
    }
}

.onReceive で UIApplication.didBecomeActiveNotification を受け取って処理しています。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?