-
-
Notifications
You must be signed in to change notification settings - Fork 32
This plugin overrides any existing AppDelegate #24
Comments
any idea what would be a good alternative? |
|
Thanks for the info. Will try to investigate on that and make a new release |
so you mean just using the activity result? |
Well, this issue was mainly for iOS, I don't know much about android, though it looks like they are preserving the existing callback for the |
@speigg very good point |
@speigg Could you submit a PR. I'm currently running out of time due to other projects |
I have tried to fix this. You can check out my fork: https://github.com/hettiger/nativescript-urlhandler/blob/24-plugin-overrides-existing-ios-appdelegate/src/urlhandler.ios.ts Unfortunately this doesn't seem to work for some reason. Any ideas? The reason for my attempt was this line: The plugin nativescript-plugin-firebase is used in a lot of projects and I bet other plugins do it in a similar way. I came to the conclusion that getters/setters would be a good fix but for some reason it doesn't work. Here is a plain JS proof of concept: function Delegate() {}
/**
* Original / already existing handler
*/
Delegate.prototype.handler = function (first, second) {
console.log(arguments);
console.log('Delegate handler – Original');
return false;
};
function enableMultipleOverridesFor(classRef, methodName) {
const prefix = '_';
Object.defineProperty(classRef.prototype, prefix + methodName, {
value: classRef.prototype[methodName] || (() => {}),
writable: true
});
Object.defineProperty(classRef.prototype, methodName, {
get: function () {
return classRef.prototype[prefix + methodName];
},
set: function (nextImplementation) {
const currentImplementation = classRef.prototype[prefix + methodName];
classRef.prototype[prefix + methodName] = function () {
const result = currentImplementation(...Array.from(arguments));
return nextImplementation(...Array.from(arguments), result);
};
}
});
}
/**
* It is important that this code is being executed before the first override
* in order to guarantee all overrides will be executed.
*/
enableMultipleOverridesFor(Delegate, 'handler');
/**
* Example for a plugin that overrides the handler
*/
(function() {
Delegate.prototype.handler = function (data) {
const lastArgument = arguments[arguments.length - 1];
const previousResult = lastArgument !== data ? lastArgument : undefined;
console.log(arguments);
if (!previousResult) {
console.log('Delegate handler – 1st overwrite');
return false;
}
return previousResult;
};
})();
/**
* Example for a plugin that overrides the handler
*/
(function() {
Delegate.prototype.handler = function (data) {
const lastArgument = arguments[arguments.length - 1];
const previousResult = lastArgument !== data ? lastArgument : undefined;
console.log(arguments);
if (!previousResult) {
console.log('Delegate handler – 2nd overwrite');
return true;
}
return previousResult;
};
})();
/**
* Example for a plugin that overrides the handler
*
* It is to be expected, that this handler will __not__ log "Delegate handler – 3rd overwrite"
* to the console because the previously executed handler returned true.
*/
(function() {
Delegate.prototype.handler = function (data) {
const lastArgument = arguments[arguments.length - 1];
const previousResult = lastArgument !== data ? lastArgument : undefined;
console.log(arguments);
if (!previousResult) {
console.log('Delegate handler – 3rd overwrite');
return false;
}
return previousResult;
};
})();
const delegate = new Delegate();
const finalResult = delegate.handler('1st argument', '2nd argument');
console.log(finalResult); You can execute this in a modern browser. It will output:
|
Hey @hypery2k , will you please let us know when the next release will be available in npm? |
I just tested with a local build this fix. |
not sure if i find time for a new version |
I'm also using nativescript-plugin-firebase and I think because of this, this plugin is not working on iOS. Does anyone have a workaround or an alternative? |
@muratcorlu I've been testing around this plugin for a while now and I think I know where your issue may reside. Firebase directly overrides the methods it requires of the app delegate, whereas this plugin (from the develop branch) chains the methods. In order for both plugins to work you would have to make sure that In addition my testing has lead me to believe that this chaining method does not work because properties defined with The actual code, which worked for me was: function enableMultipleOverridesFor(classRef, methodName, nextImplementation) {
const currentImplementation = classRef.prototype[methodName];
classRef.prototype[methodName] = function () {
const result = currentImplementation && currentImplementation(...Array.from(arguments));
return nextImplementation(...Array.from(arguments), result);
};
} Which is called like so: enableMultipleOverridesFor(appDelegate, 'applicationDidFinishLaunchingWithOptions', () => { console.log("This will be executed FIRST") } );
enableMultipleOverridesFor(appDelegate, 'applicationDidFinishLaunchingWithOptions', () => { console.log("This will be executed SECOND") } ); I hope this helps |
Excuse me mates, why this issue was closed? |
because the plugin itself not longer overwrites the delegate: nativescript-urlhandler/src/urlhandler.ios.ts Lines 9 to 12 in 1111fb8
|
Ohh Interesting, do you know if is possible to do that using ES6? also, if we can create a PR from the {N} Core repo to avoid overwriting the app delegate 🤔 |
This plugin overrides any existing app delegate:
This seems like a bad idea..
The text was updated successfully, but these errors were encountered: