NativeScript / nativescript-facebook

NativeScript plugin, wrapper of native Facebook SDK for Android and iOS
Apache License 2.0
79 stars 50 forks source link

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

Open Mixelated opened 4 years ago

Mixelated commented 4 years ago

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

daweedm commented 4 years ago

Any news about this ?

daweedm commented 4 years ago

@Mixelated How did you manage to fix this ?

Mixelated commented 4 years ago

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

kriefsacha commented 4 years ago

Any news about this ? I need both plugins

daweedm commented 4 years ago

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 commented 4 years ago

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.