After asking ATTrackingManager.requestTrackingAuthorization with an authorized status and then ask for AppLinkUtility.fetchDeferredAppLink always it return nil with this strange error:
ATTrackingManager.AuthorizationStatus must be authorized for deferred deep linking to work. Read more at: https://developer.apple.com/documentation/apptrackingtransparency
It doesn't make sense because the status is authorized
Steps to Reproduce
What are the steps necessary to reproduce this issue? Very simple to describe:
- Login to your facebook
- Then Click https://developers.facebook.com/tools/app-ads-helper
- Select an app you want to test from drop down
- Hit submit
- At the bottom you will find 'Deep Link Tester' under Developer Tools.
- Hit 'Test Deep Link' and in the dialog you can enter your deep link.
- Select both 'Send Notification' and 'Send Deferred' check marks.
- Then you will get a notification to your facebook app.
- Tap in the notification and it is opened the App Store
- Install the App through Xcode
Code Samples & Details
Then in my code I tried all this variants:
I tried this:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set the trackings to true in test mode
Settings.setAdvertiserTrackingEnabled(true)
Settings.isAdvertiserIDCollectionEnabled = true
Settings.isAutoLogAppEventsEnabled = true
// Initialize the Facebook SDK
ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
Settings.shared.isAdvertiserIDCollectionEnabled = false
Settings.shared.isAdvertiserTrackingEnabled = false
Settings.shared.isAutoLogAppEventsEnabled = false
}
Then on the primary ViewController:
class SomePrimaryViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}
@available(iOS 14.5.1, *)
private func presentTransparencyMode() {
ATTrackingManager.requestTrackingAuthorization { status in
switch status
{
case .authorized:
// Tracking authorization dialog was shown
// and we are authorized
print("Authorized")
// Now that we are authorized we can get the IDFA
print(ASIdentifierManager.shared().advertisingIdentifier)
// Get the Deferred link
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
self.setupDefferedLink()
}
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:
print("Unknown")
}
}
}
private func setupDefferedLink() {
// Set the trackings to true in test mode
Settings.shared.isAdvertiserIDCollectionEnabled = true
Settings.shared.isAdvertiserIDCollectionEnabled = true
Settings.shared.isAutoLogAppEventsEnabled = true
let id = ASIdentifierManager.shared().advertisingIdentifier.uuidString
let request = GraphRequest(graphPath: "/971082983006874/activities", parameters: ["event": "DEFERRED_APP_LINK",
"advertiser_id": id,
"application_tracking_enabled": "1",
"advertiser_tracking_enabled": "1"], httpMethod: .post)
request.start { [unowned self] connection, result, error in
if let result = result as? NSDictionary {
print(result as Any)
// It prints a dictionary with a key `success` with value `true`
// and nothing about the url
}
}
AppLinkUtility.initialize()
AppLinkUtility.fetchDeferredAppLink { (url, error) in
if let url = url {
print(url)
}
print(error as Any)
// It prints:
// ATTrackingManager.AuthorizationStatus must be `authorized` for deferred deep linking to work. Read more at: https://developer.apple.com/documentation/apptrackingtransparency
// That is an Error of the SDK, because the permission has been granted
}
}
}
No matter which variant you try, the result is always the same, url = nil