nativescript-community / perms

An unified permissions API for NativeScript on iOS and Android.
https://nativescript-community.github.io/perms/
Apache License 2.0
12 stars 9 forks source link

TypeError: Cannot read property 'checkSelfPermission' of undefined #4

Open sido420 opened 4 years ago

sido420 commented 4 years ago

I did not find sample usage details in demo app.

There is no existing issue related to this.

Here is code example:

import { getTypes, request, RequestOptions, Rationale, check, Permissions } from '@nativescript-community/perms';
declare var global: any;

export const getPermissionTypes = () => {
    console.log(`Getting  permission types for the platform`)
    console.log(getTypes());
}

export const requestContactsPermission = (): Promise<any> => {
    let perm: Permissions = `contacts`;
    let rationale: Rationale = {
        title: global.AppName + ' contacts permission',
        message: global.AppName + ' needs access to your contacts.',
        buttonPositive: "OK", // optional
        //buttonNegative?: string;
        //buttonNeutral?: string;
    },
        opts: RequestOptions = {
            type: 'always',
            rationale
        };
    return request(perm, opts).then(response => {
        //this.setState({ locationPermission: response[0] })
        console.log(response)
    });
}

getPermissionTypes works fine but requestContactsPermission throws the error in title in the calling function.

sido420 commented 4 years ago

I have the following permissions added to AndroidManifest.xml

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
farfromrefug commented 4 years ago

@sido420 you are using n7 version with N 6.x (share your package.json next time, easier to see all). Either use nativescript-perms with N 6.x or @nativesciprt-community/perms with N 7.x

sido420 commented 4 years ago

Same error even with nativescript-perms

import { getTypes, request, RequestOptions, Rationale, check, Permissions } from 'nativescript-perms';

Here is package.json:

    "nativescript": {
        "id": "com.example",
        "tns-ios": {
            "version": "6.5.0"
        },
        "tns-android": {
            "version": "6.5.0"
        }
    },
    "dependencies": {
        "@nativescript/core": "6.5.0",
        "@nativescript/theme": "^2.3.3",
        "@nstudio/nativescript-loading-indicator": "^4.0.0",
        "localforage": "^1.9.0",
        "localforage-memoryStorageDriver": "^0.9.2",
        "nativescript-accelerometer": "3.0.0",
        "nativescript-background-http": "4.2.1",
        "nativescript-camera": "4.5.0",
        "nativescript-contacts": "^1.6.2",
        "nativescript-feedback": "^1.5.0",
        "nativescript-geolocation": "5.1.0",
        "nativescript-https": "^2.1.0",
        "nativescript-image": "3.0.1",
        "nativescript-imagepicker": "7.1.0",
        "nativescript-intl": "3.0.0",
        "nativescript-iqkeyboardmanager": "1.5.1",
        "nativescript-oauth2": "^2.4.2",
        "nativescript-perms": "^2.0.11",
        "nativescript-secure-storage": "^2.6.1",
        "nativescript-social-share": "1.6.0",
        "nativescript-theme-core": "1.0.6",
        "nativescript-toast": "^2.0.0",
        "nativescript-ui-autocomplete": "6.0.1",
        "nativescript-ui-calendar": "6.1.0",
        "nativescript-ui-chart": "7.1.1",
        "nativescript-ui-dataform": "6.0.0",
        "nativescript-ui-gauge": "6.0.0",
        "nativescript-ui-listview": "8.0.1",
        "nativescript-ui-sidedrawer": "8.0.0",
        "nativescript-urlhandler": "^1.3.0",
        "nativescript-vibrate": "^3.1.0",
        "nativescript-vue": "2.5.0",
        "svelte-native": "0.8.1",
        "tns-core-modules": "6.5.0"
    },
    "devDependencies": {
        "nativescript-dev-webpack": "1.5.1",
        "node-sass": "~4.12.0",
        "svelte": "3.20.1",
        "svelte-loader": "github:rixo/svelte-loader#2204a8f7e66e441f5e0ce6e70a5fa0f9e6bb2103",
        "svelte-native-preprocessor": "^0.1.4",
        "tns-platform-declarations": "^6.5.15",
        "typescript": "3.5.3"
    }
sido420 commented 4 years ago

I use:

npx tns platform  clean android
npx tns build android
npx tns debug android
farfromrefug commented 4 years ago

Can you share the full error stack?

sido420 commented 4 years ago

Sorry for the late response.

I tried many things, but couldn't get NS to print a meaningful stack trace.

All of the following just give me the error in title:

If you know of anything else that I can try, I'd be happy to do so. Other than that, plz let me know if theres any other way I could help you debug.

farfromrefug commented 4 years ago

It gave you the error but with more Please copy your full console log from when you get that error