Closed ryc16 closed 5 years ago
You can probably do the permissions on application loaded event, but I don't believe you can do it before that point because several things aren't setup until loaded.
However, it might be better to navigate to a splash screen that does the permission check and then when the permission check is successful navigate to the main page...
@NathanaelA , about loaded event, do you mean application.launchEvent? Unfortunately put it on application.launchEvent got the same problem. If this is not you mean, please post the partial code here.
Agree, another option is to have splash to do the job but still want to know loaded event.
Yep, the launch event. I would have thought is should have worked by that point. I'll try and run some tests later this week...
Btw, I tested this in the current version of NativeScript in the App.js file;
application.on(application.launchEvent, function() {
const permissions = require("nativescript-permissions");
const perm = permissions.requestPermission(android.Manifest.permission.READ_CONTACTS, "I need Read Contact!");
perm.then(() => {
console.log("WooHoo, Perms");
}).catch(() => {
console.log("So sad, no perms...");
});
});
And it worked fine.
@NathanaelA , nice simple plugin. I put it on the real situation. For example, create a app where the main page require to access the calllog. So i add some code your demo main-view-model.js as
Now, I want to settle to the permission before go to main page. So I think i should request on app.ts.
However, I got below exception
I got 2 questions.
1. In above situation, is it too early to invoke requestPermission? Where is the early places to invoke requestPermission before goes to main screen.
2. Let's say if I register application.uncaughtErrorEvent, once the permission throw exception, the uncaughtErrorEvent catch above permission deny but how we could invoke requestPermission again and navigate back to main page.