Search code examples
iosswiftfacebookfacebook-graph-apideep-linking

iOS - Test getting Facebook deferred deep link


I want to get deferred deep link after sending it to my app via "Test App Link" FB testing tool.

I've provided AppID in the Xcode project settings and implemented fetchDeferredAppLick method in the AppDelegate file. As well as I set all necessary app settings in the FB dev account and in xcode project info.plist file.
But it still doesn't show me green checkmarks in the FB app settings.

When I send deep link to the app by clicking "Test Deep Link", I get "Deep link notification could not be sent for the chosen platform" message in the prompt.

So how can I get green checkmarks in the app fb settings regarding the fact that I've already implemented fetchDeferredAppLink method and provided AppID ?

App Settings:

My AppDelegate code:

class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        AppEvents.activateApp()
        
        ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions) 

        AppLinkUtility.fetchDeferredAppLink { (url, error) in
            
            if let error = error {
                print("Received error while fetching deferred app link: \(error)")
            } else if let url = url {
                
                print("Deeplink is \(url)")
                
                // should open cautch deeplink here
                if #available(iOS 10, *) {
                    UIApplication.shared.open(url, options: [:], completionHandler: nil)
                } else {
                    UIApplication.shared.openURL(url)
                }
            } else { // url is nil 
                print("\nNo app link available\n")
            }
        }
        
        // MARK: - OneSignal
        let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false]

        // add OneSignal app id
        OneSignal.initWithLaunchOptions(launchOptions, appId: "", handleNotificationAction: nil, settings: onesignalInitSettings)

        OneSignal.inFocusDisplayType = OSNotificationDisplayType.notification;

        // to show the iOS push notification prompt
        OneSignal.promptForPushNotifications(userResponse: { accepted in
          print("User accepted notifications: \(accepted)")
        })
        
        return true
    }
    
    // MARK: - Track App Installs and App Opens
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        ApplicationDelegate.shared.application(app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation])
        return true
    }

    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        ApplicationDelegate.shared.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
        return true
    } 
}

My info.plist:

PS. I'm able to login in the FB dev account on the simulator. And fetchDeferredAppLink method returns nil.


Solution

  • You should specify add account id in the FB App Advanced setting.

    If you have free developer account - remove push notifications from your Xcode project.

    Then on your physical device you should install Facebook app and login into account from which you've registered your app.

    Plug in your device.

    Send deferred deeplink via FB testing tool (Mark both checkboxes).

    Run your app from Xcode on your physical device. For app to launch you show trust it from your phone Settings -> General -> Device Management -> Developer App -> Trust.

    Now your app should run, you should get deferred deeplink and green checkmark near the third option on the first photo should appear.