EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 444 forks source link

Unable to do deep-linking when firebase is installed #375

Open faisal3389 opened 7 years ago

faisal3389 commented 7 years ago

We are trying to do deep linking in our nativescript ios app. By writing a custom delegate and leveraging native events used for deep-linking which are

  1. public applicationOpenURLSourceApplicationAnnotation(app: UIApplication, url: NSURL, sourceApp: string, annotation: any): boolean {}

    // Handle Universal Link deep-linking

  2. public applicationContinueUserActivityRestorationHandler(app: UIApplication, userActivity: NSUserActivity, restorationHandler: (p1: NSArray) => void) {}

but these events are not getting triggered if we have firebase plugin for nativescript added to the project.

The problems seems to be that firebase has already overrode the above method using FBSDK for push-notifications.

Here is version I use :

platform: iOS iPhone 6 - any version (tested on version 10.3 (14C92) nativescript plugin firebase : 3.11.3 tns info : angular : 1.4.0 nativescript │ 2.5.3
tns-core-modules │ 2.5.0 tns-android │ 2.5.0
tns-ios │ 3.0.1

here is a working example i'm following https://github.com/ddfreiling/tns-ng-deeplink

jerbob92 commented 5 years ago

@faisal3389 We also had this issue, we fixed it like this:

import * as Application from 'tns-core-modules/application';

if (Application.ios) {
    let oldapplicationOpenURLSourceApplicationAnnotation;

    if (Application.ios.delegate === undefined) {
        // Create new delegate when none is set.
        @ObjCClass(UIApplicationDelegate)
        class CustomUIApplicationDelegateImpl extends UIResponder implements UIApplicationDelegate {
        }

        Application.ios.delegate = CustomUIApplicationDelegateImpl;
    } else {

        // Copy old delegate when already set, so we can call it in our own method.
        if (Application.ios.delegate.prototype.applicationOpenURLSourceApplicationAnnotation) {
            oldapplicationOpenURLSourceApplicationAnnotation = Application.ios.delegate.prototype.applicationOpenURLSourceApplicationAnnotation;
        }
    }

    Application.ios.delegate.prototype.applicationOpenURLSourceApplicationAnnotation = (application, url, sourceApplication, annotation) => {
        const ourResult = true;

        // @todo: do our logic here.

        let oldDelegate = true;
        if (oldapplicationOpenURLSourceApplicationAnnotation) {
            oldDelegate = oldapplicationOpenURLSourceApplicationAnnotation(url, sourceApplication, annotation);
        }
        return ourResult || oldDelegate;
    };
}

You should do this after require('nativescript-plugin-firebase');