我正在使用库 react-native-permissions。最初我想获得发送通知的权限,但遇到了许多构建错误并决定至少获得联系人权限。
我按照文档上的步骤进行操作。
播客文件:
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
platform :ios, '11.0'
target 'MyApp' do
permissions_path = '../node_modules/react-native-permissions/ios'
config = use_native_modules!
pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts"
use_react_native!(
:path => config[:reactNativePath],
# to enable hermes on iOS, change `false` to `true` and then install pods
:hermes_enabled => false
)
target 'MyAppTests' do
inherit! :complete
# Pods for testing
end
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable the next line.
use_flipper!()
post_install do |installer|
react_native_post_install(installer)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
end
end
包含在我的 info.plist 中:
<key>NSContactsUsageDescription</key>
<string>Allow permission for contacts</string>
在我的 App.js
import { request, PERMISSIONS } from 'react-native-permissions';
useEffect(() => {
request(PERMISSIONS.IOS.CONTACTS)
.then((result) => {
console.log(result);
})
.catch((e) => console.log(e));
}, []);
请求执行的那一刻,应用程序立即崩溃。
任何帮助将不胜感激!