【问题标题】:How to get required Contact display name based on phone number in react-native如何根据 react-native 中的电话号码获取所需的联系人显示名称
【发布时间】:2019-01-29 14:41:55
【问题描述】:

我正在研究 react-native。我想根据他/她的电话联系人中的电话号码获取联系人显示名称。 我正在使用下面的代码。它给了我错误。任何人都可以建议正确的 API 或代码吗?

 Contacts.searchContacts( "ABC", (error, contacts) =>  {
        if (error) {
          console.error(error);
        }
        else {
          console.log(contacts);
        }
      });

【问题讨论】:

    标签: react-native


    【解决方案1】:

    如果您使用的是react-native-contacts,他们的 API 中似乎没有“searchContacts”函数。我建议使用“getContactsMatchingString”(字符串,回调) - 其中字符串是匹配名称(名字,中间,家庭)的任何字符串

    {
      recordID: '6b2237ee0df85980',
      company: "",
      emailAddresses: [{
        label: "work",
        email: "carl-jung@example.com",
      }],
      familyName: "Jung",
      givenName: "Carl",
      jobTitle: "",
      note: 'some text',
      urlAddresses: [{
        label: "home",
        url: "www.jung.com",
      }],
      middleName: "",
      phoneNumbers: [{
        label: "mobile",
        number: "(555) 555-5555",
      }],
      hasThumbnail: true,
      thumbnailPath: 'content://com.android.contacts/display_photo/3',
      postalAddresses: [
        {
          street: '123 Fake Street',
          city: 'Sample City',
          state: 'CA',
          region: 'CA',
          postCode: '90210',
          country: 'USA',
          label: 'home'
        }
      ],
      birthday: {"year": 1988, "month": 0, "day": 1 }
    }
    

    【讨论】:

    • 嗨 vincent vella,感谢您可以从号码中获取姓名
    • 是的,我已经编辑了我的原始帖子以显示收到的联系人的回调格式。 @user1915370
    猜你喜欢
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    • 2016-12-26
    • 1970-01-01
    相关资源
    最近更新 更多