How to retrieve iPhone IDFA from API?

前端 未结 11 806
深忆病人
深忆病人 2020-12-12 14:37

I would like to get the device IDFA. How to get this info from iOS official API ?

11条回答
  •  既然无缘
    2020-12-12 14:43

    A nicer approach to get the IDFA or nil if tracking is disabled via iOS Setting is using a (private) extension:

    import AdSupport
    
    class YourClass {
    
        func printIDFA() {
            print(ASIdentifierManager.shared().advertisingIdentifierIfPresent)
        }
    }
    
    private extension ASIdentifierManager {
    
        /// IDFA or nil if ad tracking is disabled via iOS system settings
        var advertisingIdentifierIfPresent: String? {
            if isAdvertisingTrackingEnabled {
                return advertisingIdentifier.uuidString
            }
    
            return nil 
        }        
    }
    

提交回复
热议问题