iOS 上未显示应用跟踪透明度对话框
App Tracking Transparency Dialog does not appear on iOS
Apple 审阅者刚刚拒绝了我的应用程序,因为 ATT 请求没有出现:“我们在 iOS 15.0.1 上审阅时无法找到应用程序跟踪透明度权限请求。”
我的代码如下图:
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { (status) in
//print("IDFA STATUS: \(status.rawValue)")
FBAdSettings.setAdvertiserTrackingEnabled(true)
}
}
我在 AppDelegate didFinishLaunchingWithOptions
和 viewDidLoad
中都实现了这段代码。 ATT 权限请求出现在 iOS 14,但未出现在 iOS 15.
一个Apple person建议您通过AppDelegate
中的applicationDidBecomeActive(_:)
请求它。这就是我解决 iOS.
问题的方法
import UIKit
import AppTrackingTransparency
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
func applicationDidBecomeActive(_ application: UIApplication) {
if #available(iOS 15.0, *) {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
})
}
}
}
该死,我修好了:( 这都是关于 iOS 警报系统的。我在请求通知请求后请求 App Tracking Transparency。通知请求警报关闭后,ATT 警报需要已经出现了。它在 iOS 14 上工作正常,但在 iOS 15 上显示一个警报接一个警报,它们之间需要有一个延迟时间。
编辑:
这是我的代码,分别显示两个警报:
func setNotification(){
//Ask for notification permission
let n = NotificationHandler()
n.askNotificationPermission {
//n.scheduleAllNotifications()
//IMPORTANT: wait for 1 second to display another alert
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { (status) in
//print("IDFA STATUS: \(status.rawValue)")
//FBAdSettings.setAdvertiserTrackingEnabled(true)
}
}
}
}
}
为了方便起见,这是我的 NotificaitionHandler class:
import UserNotifications
class NotificationHandler{
//Permission function
func askNotificationPermission(completion: @escaping ()->Void){
//Permission to send notifications
let center = UNUserNotificationCenter.current()
// Request permission to display alerts and play sounds.
center.requestAuthorization(options: [.alert, .badge, .sound])
{ (granted, error) in
// Enable or disable features based on authorization.
completion()
}
}
我已经更改为从 AppDelegate 的 applicationDidBecomeActive 方法调用请求并且成功了!
弹出窗口在 iOS15 的第一次应用启动时显示。
我已经更改为从
调用请求
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
}
至
@available(iOS 13.0, *)
func sceneDidBecomeActive(_ scene: UIScene) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.requestPermission()
}
}
func requestPermission() {
if #available(iOS 15.0, *) {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
switch status {
case .authorized:
// Tracking authorization dialog was shown
// and we are authorized
print("Authorized")
case .denied:
// Tracking authorization dialog was
// shown and permission is denied
print("Denied")
case .notDetermined:
// Tracking authorization dialog has not been shown
print("Not Determined")
case .restricted:
print("Restricted ")
@unknown default:
}
})
}
}
}
Apple 审阅者刚刚拒绝了我的应用程序,因为 ATT 请求没有出现:“我们在 iOS 15.0.1 上审阅时无法找到应用程序跟踪透明度权限请求。”
我的代码如下图:
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { (status) in
//print("IDFA STATUS: \(status.rawValue)")
FBAdSettings.setAdvertiserTrackingEnabled(true)
}
}
我在 AppDelegate didFinishLaunchingWithOptions
和 viewDidLoad
中都实现了这段代码。 ATT 权限请求出现在 iOS 14,但未出现在 iOS 15.
一个Apple person建议您通过AppDelegate
中的applicationDidBecomeActive(_:)
请求它。这就是我解决 iOS.
import UIKit
import AppTrackingTransparency
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
func applicationDidBecomeActive(_ application: UIApplication) {
if #available(iOS 15.0, *) {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
})
}
}
}
该死,我修好了:( 这都是关于 iOS 警报系统的。我在请求通知请求后请求 App Tracking Transparency。通知请求警报关闭后,ATT 警报需要已经出现了。它在 iOS 14 上工作正常,但在 iOS 15 上显示一个警报接一个警报,它们之间需要有一个延迟时间。
编辑: 这是我的代码,分别显示两个警报:
func setNotification(){
//Ask for notification permission
let n = NotificationHandler()
n.askNotificationPermission {
//n.scheduleAllNotifications()
//IMPORTANT: wait for 1 second to display another alert
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { (status) in
//print("IDFA STATUS: \(status.rawValue)")
//FBAdSettings.setAdvertiserTrackingEnabled(true)
}
}
}
}
}
为了方便起见,这是我的 NotificaitionHandler class:
import UserNotifications
class NotificationHandler{
//Permission function
func askNotificationPermission(completion: @escaping ()->Void){
//Permission to send notifications
let center = UNUserNotificationCenter.current()
// Request permission to display alerts and play sounds.
center.requestAuthorization(options: [.alert, .badge, .sound])
{ (granted, error) in
// Enable or disable features based on authorization.
completion()
}
}
我已经更改为从 AppDelegate 的 applicationDidBecomeActive 方法调用请求并且成功了!
弹出窗口在 iOS15 的第一次应用启动时显示。
我已经更改为从
调用请求func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
}
至
@available(iOS 13.0, *)
func sceneDidBecomeActive(_ scene: UIScene) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.requestPermission()
}
}
func requestPermission() {
if #available(iOS 15.0, *) {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
switch status {
case .authorized:
// Tracking authorization dialog was shown
// and we are authorized
print("Authorized")
case .denied:
// Tracking authorization dialog was
// shown and permission is denied
print("Denied")
case .notDetermined:
// Tracking authorization dialog has not been shown
print("Not Determined")
case .restricted:
print("Restricted ")
@unknown default:
}
})
}
}
}