Hi,
Add a Uninstall event on tns-core-modules/application that allow us to do some stuff when the application is being uninstall like delete Keychain or remote notifications....
import * as application from "tns-core-modules/application";
import { SecureStorage } from "nativescript-secure-storage";
application.on("uninstall", (args) => {
// Do stuff here
let secureStorage = new SecureStorage();
secureStorage.removeAllSync();
});
Thanks
As far as I know, there is no such event (_uninstall_) in iOS or in Android. There are some custom solutions which are a bit hacky so not so much suitable for permanent event handling.
@kefahB I think everything related to the application will be removed if you uninstall the app.
Hi everybody,
@NickIliev I try to do some thing on NS that can work as a quick solution, can you please tell me what you think about this demo
We have a dispatcher page that will be loaded on app lunch (run) and in terms of some logic will navigate the user to some pages home or register or login due to isLoggedin function...
To do some stuff when app is uninstalled and reinstalled like remove all keychain we need the function isFristRun it will check if this is the first run off the app and if true will remove the keychain and set the applicationSettings.setBoolean("isFirstRun", false); to false, then the next time applicationSettings.setBoolean("isFirstRun", false); will return false and the app continu normally.
I use applications-settings because those will be removed on uninstall the app, then if is the first run the value will be isFristRun will be undefined...
To see the action please try to comment/uncomment applicationSettings.setBoolean("isFirstRun", false); on line 6
export function isFirstRun(): Promise<boolean> {
return new Promise((resolve, reject) => {
console.log("===========");
const isFirstRun: boolean = applicationSettings.getBoolean("isFirstRun", true);
console.log(isFirstRun);
// if is first run delete all keychain
if (isFirstRun === true) {
console.log("First run :: remove all Keychain");
/*let secureStorage = new SecureStorage();
secureStorage.removeAll().then(res => {
console.log(res)
});*/
// do this just after
applicationSettings.setBoolean("isFirstRun", false);
resolve(true)
}
else {
resolve(false)
}
});
}
Hi @NickIliev,
I facing n very strange behavior once I try to set a boolean with applications-settings module !
I try to debug the problem and I think the aps do not persist the change if there is a navigation set ?
When I remove the navigation the value is persisted and every think work as expected ..
Can you help please.
@kefahB there should be no difference, and the application-settings should persist the setting no matter when it is set. Please create a sample Playground so I could investigate the case.
Hi @NickIliev .. Excuse me .. It work as expected .. but I do not pay attention to a little function that change the behavior !