Skip to content

warning: Conflict with existing popular plugins such as nativescript-firebase #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Mixelated opened this issue Nov 4, 2019 · 6 comments

Comments

@Mixelated
Copy link

nativescript-facebook is in conflict with other apps that show push notifications such as nativescript-firebase since it overrides other delegates as seen here. It took me quite a while to debug this.

// TODO: Extend existing delegate if exists

@daweedm
Copy link

daweedm commented Jan 18, 2020

Any news about this ?

@daweedm
Copy link

daweedm commented Jan 18, 2020

@Mixelated How did you manage to fix this ?

@Mixelated
Copy link
Author

Hey @daweedm rather than working with nativescript-facebook I just did everything with nativescript firebase

@kriefsacha
Copy link

Any news about this ? I need both plugins

@daweedm
Copy link

daweedm commented Mar 30, 2020

My hacky solution was the following :

Put to bottom of node_modules/nativescript-plugin-firebase/firebase.ios.js :

(function () {
                    function extractAppURL(urlParam) {
                        if (!!urlParam) {
                            var url_1 = urlParam.toString(),
                            params = new Map(), urlWithPath = url_1.indexOf('//') < url_1.length - 2,
                            urlWithParams = url_1.indexOf('?') !== -1, path = urlWithPath ? url_1.substring(url_1.indexOf('//') + 2,
                            urlWithParams ? url_1.indexOf('?') : url_1.length) : null,
                            parameters = url_1.substring(url_1.indexOf('?') + 1).split('&');
                            if (urlWithParams) {
                                for (var i = 0, len = parameters.length; i < len; i++) {
                                    var paramData = parameters[i].split('=');
                                    params.set(paramData[0], paramData[1] ? paramData[1] : null);
                                }
                            }
                            return {
                                params: params,
                                path: path,
                                toString: function () {
                                    return url_1;
                                }
                            };
                        } else {
                            return null;
                        }
                    }

                    getAppDelegate().prototype.applicationOpenURLOptions = function (application, url, options) {
                        if (getAppDelegate().prototype.___DS_IOS_HANDLER) {

                            FBSDKApplicationDelegate.sharedInstance.applicationOpenURLSourceApplicationAnnotation(application, url, options.valueForKey(UIApplicationOpenURLOptionsSourceApplicationKey), options.valueForKey(UIApplicationOpenURLOptionsAnnotationKey));

                            var lastArgument = arguments[arguments.length - 1];
                            var previousResult = lastArgument !== options ? lastArgument : undefined;
                            if (!previousResult) {
                                var appURL_1 = extractAppURL(url.absoluteString);
                                if (appURL_1 != null) {
                                    setTimeout(function () { return getAppDelegate().prototype.___DS_IOS_HANDLER(appURL_1); });
                                }
                                return true;
                            }
                            return previousResult;

                        }
                    };

                    getAppDelegate().prototype
                    .applicationContinueUserActivityRestorationHandler = function (application, userActivity, restorationHandler) {
                        if (getAppDelegate().prototype.___DS_IOS_HANDLER) {
                            if (userActivity.activityType === NSUserActivityTypeBrowsingWeb) {
                                var appURL_2 = extractAppURL(userActivity.webpageURL);
                                if (appURL_2 !== null) {
                                    setTimeout(function () { return getAppDelegate().prototype.___DS_IOS_HANDLER(appURL_2); });
                                }
                            }
                            return true;
                        }
                    };

                })();

Then, in your app.component.ts, register an additional callback for iOS only :

require('tns-core-modules/application/application').ios.delegate.prototype.___DS_IOS_HANDLER = (url) => {
            console.log('GOT url from ___DS_IOS_HANDLER', url);
            setTimeout(() => this.ngZone.run(() => this.handleOpenURL(url)));
        };

@alexgritton
Copy link
Contributor

alexgritton commented Jul 3, 2020

I worked around this a different way. Since I know the only other plugin I'm using that registers the ios.delegate is firebase, In the index.ios file I added this check.

if (!applicationModule.ios.delegate) {
  applicationModule.ios.delegate = BaseDelegate;
}

This works because firebase looks for the FBSDKApplicationDelegate and if it exists then it uses it. Since firebase will use the FBSDKApplicationDelegate, then there is no need for this to register it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants