facebook / facebook-ios-sdk

Used to integrate the Facebook Platform with your iOS & tvOS apps.
https://developers.facebook.com/docs/ios
Other
7.73k stars 3.5k forks source link

[iOS] `AppLinkUtility.fetchDeferredAppLink` returns nil url in completion #2368

Open pongloongyeat opened 1 month ago

pongloongyeat commented 1 month ago

Checklist before submitting a bug report

Xcode version

15.2

Facebook iOS SDK version

main branch

Dependency Manager

Building from Source

SDK Framework

Core

Goals

I'm trying to retrieve deferred deep link

Expected results

When calling AppLinkUtility.fetchDeferredDeepLink after a deferred deeplink has been sent using the App Ads Helper tool, I expect the url in the completion block to not be nil and should match the deeplink I sent.

Actual results

The url in the completion was nil. This was the network call the SDK made ("1043792656902611/activities" via the Graph API) when fetching the deferred deeplink:

POST https://ep1.facebook.com/v17.0/1043792656902611/activities
iOS 17.1.2

# Request
{
  "advertiser_id": "9ABB1466-XXXX-XXXX-XXXX-XXXXXXXXXX",
  "advertiser_id_collection_enabled": 1,
  "advertiser_tracking_enabled": 1,
  "anon_id": "XZ7E0AB6C1-XXXX-XXXX-XXXX-XXXXXXXXXX",
  "application_tracking_enabled": 1,
  "event": "DEFERRED_APP_LINK",
  "extinfo": ...
}

# Response
{
  "success": 1
}

Steps to reproduce

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
        return true
    }

    override func applicationDidBecomeActive(_ application: UIApplication) {
        if #available(iOS 14, *) {
            ATTrackingManager.requestTrackingAuthorization { [weak self] status in
                switch status {
                case .authorized:
                    Settings.shared.isAdvertiserTrackingEnabled = true
                    Settings.shared.isAdvertiserIDCollectionEnabled = true

                    self?.fetchDeferredAppLink()
                default:
                    Settings.shared.isAdvertiserTrackingEnabled = false
                    Settings.shared.isAdvertiserIDCollectionEnabled = false
                }
            }
        } else {
            Settings.shared.isAdvertiserTrackingEnabled = true
            Settings.shared.isAdvertiserIDCollectionEnabled = true
            self.fetchDeferredAppLink()
        }

        return super.applicationDidBecomeActive(application)
    }

    func fetchDeferredAppLink() {
        let idfa = ASIdentifierManager.shared().advertisingIdentifier
        print("IDFA: \(idfa)")

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: {
            AppLinkUtility.fetchDeferredAppLink { [weak self] uri, err in
                if let err = err {
                    print("FBSDK_Custom (error): \(err)") // <-- nil
                }

                if let uri = uri {
                    print("FBSDK_Custom (uri): \(uri)") // <-- nil
                }
            }
        })
    }
}
  1. Uninstall app
  2. Send deferred deeplink via App Ads Helper.
  3. Install app
  4. Launch app

Code samples & details

No response