Swift 5 Trying to Accept and Parse a Firebase Dynamic Link and Deeplink - Getting Errors, and never execute my code - Software caused connection abort

Viewed 665

First of all, I am more of an Android developer than IOS. I am using FirebaseDynamicLinks (7.11.0), Xcode 12.5. Running on IOS 14.5.1. I updated everything to try to fix the errors.

I created a Dynamic link on the Firebase Console. The long link is: https://fishcounter.page.link/?link=https://fcm.dkcc.com?req%3Dfollow%26nickname%3DDave's%2BAndroid&apn=com.dkcc.fishcounter&isi=1566139081&ibi=com.dkcc.fishcounter&st=Fishcounter+App&sd=Check+out+the+Fishcounter+app&si=https://fcm.dkcc.com/sites/fishcounter/files/icon.png The short link is https://fishcounter.page.link/iGuj

In Android, I can receive the short link, and parse the results. The logs show: MainActivity: showDeepLinkOffer req=follow, nickname=Dave's Android

I am trying to do the same in Swift 5. I am able to receive Firebase Messages and process them, so Firebase Messaging is working. I just can't get the app to process a dynamic link and parse it.

Following the example on Firebase web site, I added these three funcs to AppDelegate: Forgive the logMessage, it is more Android-like, but they can be replaced with Print()

   @available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {

    logMessage.logDebug(tag: TAG, msg: "open url iOS 9.0 url=\(url)")
    logMessage.logDebug(tag: TAG, msg: "open url iOS 9.0 req=\(getQueryStringParameter(url: "\(url)", param: "req"))")
    return application(app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: "")
}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    logMessage.logDebug(tag: TAG, msg: "open url url=\(url)")
    if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
        // Handle the deep link. For example, show the deep-linked content or
        // apply a promotional offer to the user's account.
        // ...
        logMessage.logDebug(tag: TAG, msg: "open url dynamicLink=\(dynamicLink)")
        logMessage.logDebug(tag: TAG, msg: "open url dynamicLink=\(dynamicLink)")

        return true
    }
    return false
}

func application(_ application: UIApplication, continue userActivity: NSUserActivity,
                 restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    logMessage.logDebug(tag: TAG, msg: "continue userActivity")
    let handled = DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
        self.logMessage.logDebug(tag: self.TAG, msg: "continue userActivity dynamiclink=\(dynamiclink), error=\(error)")
    }
    logMessage.logDebug(tag: TAG, msg: "continue userActivity handled=\(handled)")
    return handled
}

When I click the link, the app opens, (or gets focus), I get no log messages from the 3 functions, but I get the following errors - One time only. I need to delete the app from the phone, and re-install it via Xcode tethering to get the error again. It does nothing after the first try, (no errors or log messages when I click the link).

2021-05-11 14:53:38.873386-0600 FishCounter[524:37319] [Snapshotting] Snapshotting a view (0x13e80fa00, UIKeyboardImpl) that is not in a visible window requires afterScreenUpdates:YES.
2021-05-11 14:53:39.926476-0600 FishCounter[524:37516] [connection] nw_read_request_report [C3] Receive failed with error "Software caused connection abort"
2021-05-11 14:53:39.963022-0600 FishCounter[524:37516] [connection] nw_read_request_report [C1] Receive failed with error "Software caused connection abort"
2021-05-11 14:53:39.963292-0600 FishCounter[524:37516] [connection] nw_read_request_report [C5] Receive failed with error "Software caused connection abort"
2021-05-11 14:53:39.963492-0600 FishCounter[524:37516] [connection] nw_read_request_report [C2] Receive failed with error "Software caused connection abort"
2021-05-11 14:53:39.975452-0600 FishCounter[524:37516] Connection 10: received failure notification
2021-05-11 14:53:39.975635-0600 FishCounter[524:37516] [connection] nw_flow_add_write_request [C10.1.1 192.168.50.220:443 failed channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, dns)] cannot accept write requests
2021-05-11 14:53:39.975921-0600 FishCounter[524:37516] [connection] nw_write_request_report [C10] Send failed with error "Socket is not connected"
2021-05-11 14:53:39.978430-0600 FishCounter[524:37516] Connection 7: received failure notification
2021-05-11 14:53:39.978548-0600 FishCounter[524:37516] [connection] nw_flow_add_write_request [C7.1.1 192.168.50.220:443 failed channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, dns)] cannot accept write requests
2021-05-11 14:53:39.978623-0600 FishCounter[524:37516] [connection] nw_write_request_report [C7] Send failed with error "Socket is not connected"
2021-05-11 14:53:46.848505-0600 FishCounter[524:37319] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

These errors appear to be System generated, as they do not match my format for logs. I have tried searching all the errors, and cannot figure out how to fix this. I can't even figure out where in the app it is throwing these errors.

I have double checked my IOS app id is correct. I tried adding FirebaseDynamicLinksCustomDomains in info.plist adding my url (and the internal IP address in case).

Another option (from google searches) was to add this to SceneDelegate in willConnectTo session:

//        if let firstUrlContext = connectionOptions.userActivities.first,let url = firstUrlContext.webpageURL  {
//            DynamicLinks.dynamicLinks().handleUniversalLink(url) { (dynamiclink, error) in
//                if let dynamiclink = dynamiclink {
//                    self.handleDynamicLink(dynamicLink: dynamiclink)
//                }
//            }
//        }

I tried adding public var reconnectAttemptsMax: Int? = nil to AppDelegate.

1 Answers

Try adding func scene(_ scene: UIScene, continue userActivity: NSUserActivity) to your SceneDelegate.swift file instead of using that function in AppDelegate.swift. This fixes it for me

Related