NathanaelA / nativescript-permissions

Wraps up the entire Android 6 permissions system in a easy to use plugin.
MIT License
46 stars 22 forks source link

Property 'Manifest' does not exist on type 'typeof android' #28

Closed sserdyuk closed 7 years ago

sserdyuk commented 7 years ago

This must be something obvious, but I don't know what to do. I have added platform references per NS documentation and android.Manifest isn't defined there. What do you use?

I am trying to use this plugin along with the nativescript-contacts one to hack together a quick proof of concept. Currently the contants plugin fails with a permission error on Android 7.1 but works on 4.4, hence my interest in the permissions plugin.

import { Observable } from 'data/observable';
var app = require("application");
var contacts = require("nativescript-contacts");
var permissions = require("nativescript-permissions");

export class HelloWorldModel extends Observable {

   // tap first
    onTap2() {
        permissions.requestPermission(android.Manifest.permission.READ_CONTACTS, "I need these permissions because I'm cool")
            .then(function () {
                console.log("Woo Hoo, I have the power!");
            })
            .catch(function () {
                console.log("Uh oh, no permissions - plan B time!");
            });
    }

   // tap second
    public onTap() {
        contacts.getContact().then(function (args) {
            /// Returns args: 
            /// args.data: Generic cross platform JSON object 
            /// args.reponse: "selected" or "cancelled" depending on wheter the user selected a contact.  
            console.log('args.response ' + args.response);

            if (args.response === "selected") {
                var contact = args.data; //See data structure below 

                // lets say you wanted to grab first name and last name 
                console.log(contact.name.given + " " + contact.name.family);

                //lets say you want to get the phone numbers 
                contact.phoneNumbers.forEach(function (phone) {
                    console.log(phone.value);
                });

                //lets say you want to get the addresses 
                contact.postalAddresses.forEach(function (address) {
                    console.log(address.location.street);
                });
            }
        });
    }
}
$ tns info
All NativeScript components versions information
┌──────────────────┬─────────────────┬────────────────┬─────────────┐
│ Component        │ Current version │ Latest version │ Information │
│ nativescript     │ 3.0.3           │ 3.0.3          │ Up to date  │
│ tns-core-modules │ 3.0.1           │ 3.0.1          │ Up to date  │
│ tns-android      │ 3.0.1           │ 3.0.1          │ Up to date  │
│ tns-ios          │ 3.0.1           │ 3.0.1          │ Up to date  │
└──────────────────┴─────────────────┴────────────────┴─────────────┘
$ cat package.json 
{
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "org.nativescript.ContactBrowingTest",
    "tns-ios": {
      "version": "3.0.1"
    },
    "tns-android": {
      "version": "3.0.1"
    }
  },
  "dependencies": {
    "nativescript-contacts": "git+https://github.com/sserdyuk/nativescript-contacts.git",
    "nativescript-permissions": "^1.2.3",
    "nativescript-theme-core": "~1.0.2",
    "tns-core-modules": "~3.0.0"
  },
  "devDependencies": {
    "babel-traverse": "6.24.1",
    "babel-types": "6.24.1",
    "babylon": "6.17.2",
    "lazy": "1.0.11",
    "nativescript-dev-android-snapshot": "^0.*.*",
    "nativescript-dev-typescript": "~0.4.0",
    "tns-platform-declarations": "^3.0.1",
    "typescript": "~2.2.1"
  }
}
NathanaelA commented 7 years ago

I would recommend you read my blog. http://fluentreports.com/blog But in a nutshell, you need to either globally define android as an or prefix it in a single use (<any>android). as and .

sserdyuk commented 7 years ago

Thank you!