Skip to content

Ability to check the status of the requested permissions. #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
racekarl opened this issue Jun 1, 2017 · 5 comments
Closed

Ability to check the status of the requested permissions. #42

racekarl opened this issue Jun 1, 2017 · 5 comments

Comments

@racekarl
Copy link

racekarl commented Jun 1, 2017

Why does the requestPermissions method return void and not the result of the request? How are we supposed to handle the case where the user denies permission to use the camera? I can see in the code for iOS you catch the permission denied case and log it, while in Android the result is never even checked. In both cases nothing is returned to the calling code, which does not make sense to me. Am I missing something?

@tsonevn
Copy link
Contributor

tsonevn commented Jun 5, 2017

Hi @racekarl,
The requestPermissions is created by design to request the needed rights, however, it will not check, whether the user has accepted them or not. This is something that should be handled in the project manually. In case you ned to verify, whether you have the needed permission you could use native code and check this information. You could review the below-given code sample, where the both scenarios for iOS and Android are shown.
XML

<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">

    <Page.actionBar>
        <ActionBar title="My App" icon="" class="action-bar">
        </ActionBar>
    </Page.actionBar>

    <StackLayout class="p-20">
        <Label text="Tap the button" class="h1 text-center"/>
        <Button text="TAP" tap="onTap" class="btn btn-primary btn-active"/>
        <Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
    </StackLayout>
</Page>

TypeScript

import { EventData } from 'data/observable';
import { Page } from 'ui/page';
import { HelloWorldModel } from './main-view-model';
import {isIOS} from "platform"
declare var PHPhotoLibrary:any;
declare var PHAuthorizationStatus:any;
// Event handler for Page "navigatingTo" event attached in main-page.xml
export function navigatingTo(args: EventData) {
   
    let page = <Page>args.object;
    
   
    page.bindingContext = new HelloWorldModel();
}

export function onTap(){
    if(isIOS){
    let authStatus = PHPhotoLibrary.authorizationStatus();
        console.log("authStatus");
        console.log(authStatus);
        switch (authStatus) {
            case PHAuthorizationStatus.notDetermined:
                console.log("iOS - notDetermined")
                break;
            case PHAuthorizationStatus.restricted:
                console.log("iOS - restricted ")
                break;
            case PHAuthorizationStatus.denied:
                console.log("iOS - denied")
                break;
            case PHAuthorizationStatus.authorized:
                console.log("iOS - authorized")
                break;
        
            default:
                break;
        }
    }
    else{
         if ((<any>android.support.v4.content.ContextCompat).checkSelfPermission(applicationModule.android.currentContext, (<any>android).Manifest.permission.WRITE_EXTERNAL_STORAGE) == android.content.pm.PackageManager.PERMISSION_GRANTED ||
        (<any>android.support.v4.content.ContextCompat).checkSelfPermission(applicationModule.android.currentContext, (<any>android).Manifest.permission.CAMERA) == android.content.pm.PackageManager.PERMISSION_GRANTED) {
        console.log("Android Have Permissions")
    }
    }
}

@tsonevn tsonevn changed the title What happens if permission is denied by the user? Ability to check the status of the requested permissions. Jun 16, 2017
@nmongiya
Copy link

nmongiya commented Oct 3, 2017

I am using the
https://github.com/NathanaelA/nativescript-permissions
This is a workaround, It has a function to check permission and return true and false.
permissions.hasPermission(permissionName);

permissionName - The permission you are requesting.
returns Boolean - true or false

@halaharr
Copy link

halaharr commented Oct 3, 2017 via email

@AnthonySmith01
Copy link

AnthonySmith01 commented Oct 26, 2017

It would be ideal if nativescript-camera provided a means to check the permission.

Projects can implement their own logic to track permissions but this doesn't take into account that users can revoke permissions outside of the app. What if the user removes the app permission in settings and then re-opens the app? It becomes a confusing mess.

Nativescript-permissions is also a great plugin but it doesn't support ios.

@DimitarTachev
Copy link

Hi guys,

The fix was implemented by @surdu in pull request #73 and released in version 3.2.0 of the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants