Skip to content
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

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

Open
sido420 opened this issue Sep 7, 2020 · 7 comments
Open

Comments

@sido420
Copy link

sido420 commented Sep 7, 2020

I did not find sample usage details in demo app.

There is no existing issue related to this.

  • Android (not tested on iOS)

  • Android 8.1.0

  • ASUS Zenphone

  • CLI: 6.7.8

  • Cross-platform modules: "6.5.0"

  • Runtime(s): 6.5.0 (both)

  • Plugin(s): let me know if needed

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
Copy link
Author

sido420 commented Sep 7, 2020

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
Copy link
Member

@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
Copy link
Author

sido420 commented Sep 7, 2020

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
Copy link
Author

sido420 commented Sep 7, 2020

I use:

npx tns platform  clean android
npx tns build android
npx tns debug android

@farfromrefug
Copy link
Member

Can you share the full error stack?

@sido420
Copy link
Author

sido420 commented Sep 11, 2020

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
Copy link
Member

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

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

No branches or pull requests

2 participants