How to use the react-native-contacts.checkPermission function in react-native-contacts

To help you get started, we’ve selected a few react-native-contacts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MiEcosystem / miot-plugin-sdk / projects / com.xiaomi.demo / Main / AddressBookDemo.js View on Github external
componentDidMount() {
      var Contacts = require('react-native-contacts');
    // var newPerson = {
    //     lastName: "Nietzsche",
    //     firstName: "Friedrich",
    //     emailAddresses: [{
    //       label: "work",
    //       email: "mrniet@example.com",
    //     }],
    //   }

    // AddressBook.addContact(newPerson, (err) => { /*...*/ })
    
    Contacts.checkPermission((err, permission) => {
      // AddressBook.PERMISSION_AUTHORIZED || AddressBook.PERMISSION_UNDEFINED || AddressBook.PERMISSION_DENIED
      if (permission === 'undefined') {
        Contacts.requestPermission((err, permission) => {
          // ...
        });
      }
      if (permission === 'authorized') {
        // yay!
        Contacts.getAll((err, contacts) => {
          console.log(err, contacts);
          //update the first record
          // let someRecord = contacts[0]
          // someRecord.emailAddresses.push({
          //   label: "junk",
          //   email: "mrniet+junkmail@test.com",
          // })
github MiEcosystem / miot-plugin-sdk / projects / com.xiaomi.demo / Main / ThirdPartDemo / AddressBookDemo.js View on Github external
componentDidMount() {
    var Contacts = require('react-native-contacts');

    Contacts.checkPermission((err, permission) => {
      // AddressBook.PERMISSION_AUTHORIZED || AddressBook.PERMISSION_UNDEFINED || AddressBook.PERMISSION_DENIED
      if (permission === 'undefined') {
        Contacts.requestPermission((err, permission) => {
          // ...
        });
      }
      if (permission === 'authorized') {
        // yay!
        Contacts.getAll((err, contacts) => {
          console.log(err, contacts);
          this.setState({ dataSource: this.state.dataSource.cloneWithRows(contacts) });
        });
      }
      if (permission === 'denied') {
        alert("通讯录未授权")
      }
github Skjutsgruppen / skjutsgruppen-reactnative / app / services / apollo / contact.js View on Github external
InteractionManager.runAfterInteractions(() => {
          Contacts.checkPermission(async (err, permission) => {
            if (err || permission !== 'authorized') {
              Contacts.requestPermission(async (contactErr, res) => {
                if (contactErr) {
                  if (Platform === 'ios' || Platform.OS === 'ios') {
                    // Crashlytics.recordError(contactErr);
                  }
                }

                if (res === 'authorized') {
                  contactList = await getMappedContacts();
                }

                mutate({ variables: { contactList } });
              });

              return;
github Skjutsgruppen / skjutsgruppen-reactnative / app / screens / tab / feed.js View on Github external
const { syncContacts } = this.props;
    try {
      if (Platform === 'android' || Platform.OS === 'android') {
        const permissions =
          await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_CONTACTS);

        if (!permissions) {
          const response =
            await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_CONTACTS);
          if (response && response === 'granted') {
            syncContacts();
          }
          this.setState({ contactPermission: !(response === 'denied' || response === 'never_ask_again'), contactPermissionResponse: response });
        }
      } else {
        Contacts.checkPermission(async (err, permission) => {
          const iosPermission = await AuthService.getContactPermission();

          if (permission === 'authorized' && (iosPermission === null)) {
            await syncContacts();
            await AuthService.setContactPermission('synced');
          }

          if (err || permission !== 'authorized') {
            Contacts.requestPermission((contactErr, res) => {
              if (contactErr) {
                if (Platform === 'ios' || Platform.OS === 'ios') {
                  // Crashlytics.recordError(contactErr);
                }
              }
              if (res === 'authorized') {
                syncContacts();
github Skjutsgruppen / skjutsgruppen-reactnative / app / screens / auth / onboarding / Onboarding.js View on Github external
const { syncContacts } = this.props;
    try {
      if (Platform === 'android' || Platform.OS === 'android') {
        const permissions =
          await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_CONTACTS);

        if (!permissions) {
          const response =
            await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_CONTACTS);
          if (response && response === 'granted') {
            syncContacts();
          }
          this.setState({ contactPermission: !(response === 'denied' || response === 'never_ask_again'), contactPermissionResponse: response });
        }
      } else {
        Contacts.checkPermission(async (err, permission) => {
          const iosPermission = await AuthService.getContactPermission();

          if (permission === 'authorized' && (iosPermission === null)) {
            await syncContacts();
            await AuthService.setContactPermission('synced');
          }

          if (err || permission !== 'authorized') {
            Contacts.requestPermission((contactErr, res) => {
              if (contactErr) {
                if (Platform === 'ios' || Platform.OS === 'ios') {
                  // Crashlytics.recordError(contactErr);
                }
              }
              if (res === 'authorized') {
                syncContacts();
github celo-org / celo-monorepo / packages / mobile / src / utils / permissions.ios.ts View on Github external
return new Promise((resolve, reject) => {
    Contacts.checkPermission((err, permission) => {
      if (err) {
        reject(err)
      } else {
        resolve(permission === 'authorized')
      }
    })
  })
}
github textileio / photos / App / features / contacts / sagas.ts View on Github external
(resolve, reject) => {
      Contacts.checkPermission((err, permission) => {
        if (err) {
          reject(err)
          return
        }
        if (permission === 'undefined') {
          Contacts.requestPermission((err, permission) => {
            if (err) {
              reject(err)
              return
            } else {
              resolve(permission)
            }
          })
        } else {
          resolve(permission)
        }