React Native Expo iOS端如何打开默认通讯录应用?
在React Native Expo中打开iOS默认通讯录应用
解决步骤:
- 先在项目的
app.json文件中添加iOS的URL Scheme白名单配置,确保App被允许唤起通讯录应用:{ "expo": { "ios": { "infoPlist": { "LSApplicationQueriesSchemes": ["contacts"] } } } } - 之后使用
Linking模块调用正确的URL Scheme打开通讯录:import { Linking } from 'react-native'; const openIOSContacts = async () => { try { const isSupported = await Linking.canOpenURL('contacts://'); if (isSupported) { await Linking.openURL('contacts://'); } else { console.log('无法打开通讯录应用'); } } catch (err) { console.error('打开通讯录失败:', err); } };
补充说明:
- iOS 9及以上版本强制要求在
infoPlist中声明LSApplicationQueriesSchemes,否则Linking.canOpenURL()会返回false,也无法唤起对应应用。你之前直接调用Linking.openURL('contacts://')无效,大概率是缺少这个配置。
内容的提问来源于stack exchange,提问作者segev_gr
相关产品推荐
相关产品推荐

