uniapp 获取通讯录

就获取通讯录与判断用户通讯录权限状态的处理

    getContacts() {
      // 获取通讯录对象
      plus.contacts.getAddressBook(
        plus.contacts.ADDRESSBOOK_PHONE,
        (addressbook) => {
          // 查找联系人
          addressbook.find(
            ['displayName', 'phoneNumbers'],
            (contacts) => {
              let lis = contacts
              ...业务逻辑
            },
            () => {
              this.openAuthorize()
            },
            { multiple: true }
          )
        },
        (e) => {
          this.openAuthorize()
        }
      )
    },
    openAuthorize() {
      // #ifdef APP-PLUS
      plus.android.requestPermissions(
        ['plus.contacts.ADDRESSBOOK_PHONE'],
        (e) => {
          let result = e.deniedAlways.some((_) => {
            return _ === 'plus.contacts.ADDRESSBOOK_PHONE'
          })
          if (result) {
            ...业务逻辑
          }
        }
      )
      // #endif
    }

你可能感兴趣的:(javascript,js,安卓,uni-app)