nativescript-facebook icon indicating copy to clipboard operation
nativescript-facebook copied to clipboard

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

Open Mixelated opened this issue 6 years ago • 6 comments

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.

https://github.com/NativeScript/nativescript-facebook/blob/edfcb7c382df51a5f9e4584c50c8c61a65b86969/src/index.ios.ts#L11

Mixelated avatar Nov 04 '19 04:11 Mixelated

Any news about this ?

daweedm avatar Jan 18 '20 20:01 daweedm

@Mixelated How did you manage to fix this ?

daweedm avatar Jan 18 '20 20:01 daweedm

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

Mixelated avatar Feb 26 '20 07:02 Mixelated

Any news about this ? I need both plugins

kriefsacha avatar Mar 30 '20 09:03 kriefsacha

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)));
        };

daweedm avatar Mar 30 '20 10:03 daweedm

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.

alexgritton avatar Jul 03 '20 21:07 alexgritton