How to safely use iOS advertisingIdentifier?

According to [Apple's documentation](https://developer.apple.com/documentation/adsupport/asidentifiermanager/1614148-isadvertisingtrackingenabled):



> Check the value of this property before performing any advertising tracking. If the value is `false`, use the advertising identifier only for the following purposes: frequency capping, attribution, conversion events, estimating the number of unique users, advertising fraud detection, and debugging.



So based on that, the code below should work safely and be following Apple's documentation:



```

var advertisingID: String? {

if ASIdentifierManager.shared().isAdvertisingTrackingEnabled == true {

return nil

} else {

return ASIdentifierManager.shared().advertisingIdentifier.uuidString

}

}

```



Basically checking to see if it's false, then, if so using it. Of course that code could be simplified, but I'm trying to be as verbose as possible for this question.



That code seems correct to me according to Apple's documentation.



That being said, it doesn't fit the name of the property really, nor does it fit open source projects on GitHub.



Below are a few open source projects with links that do it a different way.



[DeviceInfo](https://github.com/marumemomo/DeviceInfo/blob/bddcfb42849189a8fc7d452ea9798a9b5be1bd60/DeviceInfo/DeviceInfo.swift#L59):



```

return ASIdentifierManager.shared().isAdvertisingTrackingEnabled ? ASIdentifierManager.shared().advertisingIdentifier.uuidString : ""

```



[drifter](https://github.com/wenerme/drifter/blob/aea35f9131071971c923e8b418c96c9d668db8f6/ios/Classes/SwiftDrifterPlugin.swift#L35-L40):



```

// Check whether advertising tracking is enabled

guard ASIdentifierManager.shared().isAdvertisingTrackingEnabled else {

return nil

}

// Get and return IDFA

return ASIdentifierManager.shared().advertisingIdentifier.uuidString

```



As you can see, instead of returning that value if it's `false` these solutions return the `advertisingIdentifier` if `isAdvertisingTrackingEnabled` is `true`. Which is not what Apple's documentation states. But it does make sense given the property name.



---



So my question is, which is correct? Is Apple's documentation wrong? Or are these open source projects doing it incorrectly? Or am I just missing something obvious and both those open source projects and Apple's documentation are both correct?