This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo 联系人(旧版)
一个提供访问手机系统联系人的库。
重要
expo-contacts库中包含Contacts API的legacy版本。它可以与从根目录导出的基于类的expo-contactsAPI 一起使用。要使用旧版 API,请从expo-contacts/legacy导入。
expo-contacts 提供对设备系统联系人的访问,允许你获取联系人信息,以及添加、编辑或删除联系人。
在 iOS 上,联系人具有多层级分组系统,你也可以通过此 API 访问。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
应用配置中的配置
如果你在项目中使用配置插件(持续原生生成(CNG)),可以使用 expo-contacts 内置的 配置插件 来进行配置。该插件允许你配置一些无法在运行时设置的属性,这些属性需要重新构建新的应用二进制文件后才会生效。如果你的应用不使用 CNG,那么你需要手动配置该库。
Example app.json with config plugin
Configurable properties
Are you using this library in an existing React Native app?
如果你没有使用持续原生生成(CNG)(即你在手动使用原生 android 和 ios 项目),那么你需要在原生项目中配置以下权限:
-
对于 Android,请将
android.permission.READ_CONTACTS和android.permission.WRITE_CONTACTS权限添加到项目的 android/app/src/main/AndroidManifest.xml 中:<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> -
对于 iOS,请将
NSContactsUsageDescription键添加到项目的 ios/[app]/Info.plist 中:<key>NSContactsUsageDescription</key> <string>允许 $(PRODUCT_NAME) 访问你的联系人</string>
用法
API
import * as Contacts from 'expo-contacts/legacy';
Component
Type: React.PureComponent<ContactAccessButtonProps>
Creates a contact access button to quickly add contacts under limited-access authorization.
For more details, you can read the Apple docs about the underlying ContactAccessButton SwiftUI view.
ColorValueA color of the button's background. Provided color should not be transparent, otherwise it may not satisfy platform requirements for button legibility.
stringWhen the query produces a single result, the contact access button shows the caption under the matching contact name. It can be nothing (default), email address or phone number.
Acceptable values are: 'default' | 'email' | 'phone'
string[]An array of email addresses. The search omits contacts matching query that also match any email address in this array.
string[]An array of phone numbers. The search omits contacts matching query that also match any phone number in this set.
stringA string to match against contacts not yet exposed to the app. You typically get this value from a search UI that your app presents, like a text field.
ColorValueA color of the button's title. Slightly dimmed version of this color is used for the caption text. Make sure there is a good contrast between the text and the background, otherwise platform requirements for button legibility may not be satisfied.
ColorValueA tint color of the button and the modal that is presented when there is more than one match.
Static methods
Returns a boolean whether the ContactAccessButton is available on the platform.
This is true only on iOS 18.0 and newer.
booleanConstants
Methods
Promise<string>Promise<ContactsPermissionResponse>Promise<boolean>Promise<boolean>Promise<string[]>Promise<ExistingContact | null>Promise<ContactsPermissionResponse>Event subscriptions
Types
Literal type: union
Acceptable values are: CalendarFormats | {CalendarFormats}
String union of SortTypes values.
Literal type: union
Permission expiration time. Currently, all permissions are granted permanently.
Acceptable values are: 'never' | number
Enums
权限
Android
此库会自动为你的应用添加 READ_CONTACTS 和 WRITE_CONTACTS 权限:
iOS
此库使用以下用途描述键: