Swift 由于苹果新政,IDFA要授权,获取IDFA

2021-04-23  本文已影响0人  AlwaysLuckyMa
import AdSupport 
import AppTrackingTransparency   

if #available(iOS 14, *) {
                    
               ATTrackingManager.requestTrackingAuthorization { (status) in
                   switch status {
                    case .denied:
                       debugPrint("用户拒绝")
                       break
                   case .authorized:
                        debugPrint("用户允许")
                       debugPrint("IDFA:\(ASIdentifierManager.shared().advertisingIdentifier.uuidString)")
                       break
                   case .notDetermined:
                       debugPrint("用户没有选择")
                   default:
                       break
                   }
               }
           } else {
               // iOS13及之前版本,继续用以前的方式
               if ASIdentifierManager.shared().isAdvertisingTrackingEnabled {
                   debugPrint("可以获取:\(ASIdentifierManager.shared().advertisingIdentifier.uuidString)")
               } else {
                   debugPrint("用户未打开IDFA开关")
               }
           }
上一篇下一篇

猜你喜欢

热点阅读