使用Expo SDK的React Native iOS应用程序的Info.plist文件

24

我想正确地格式化Info.plist文件,以便在react-native-in-app-utils中使用应用内购买功能,但我不确定如何格式化数据以及插入什么类型的数据。

这个帖子提到在Info.plist文件中包括应用程序包标识的必要性。

iOS应用内购买 - 没有收到产品

1个回答

74

如果你在使用expo,它不会向你公开整个info.plist

Expo解决方案

您可以在app.json中的ios对象的子级中添加一个对象,如下所示:

"infoPlist": {
  "NSCameraUsageDescription": "This app uses the camera to scan barcodes on event tickets."
},

虽然这可以编写到本地级别,但是存在一定的限制。以下是使用expo时可以访问的所有键的列表。

<key>NSCameraUsageDescription</key>
<string>Allow Expo experiences to use your camera</string>
<key>NSContactsUsageDescription</key>
<string>Allow Expo experiences to access your contacts</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Allow Expo experiences to use your location</string>
<key>NSMicrophoneUsageDescription</key>
<string>Allow Expo experiences to access your microphone</string>
<key>NSMotionUsageDescription</key>
<string>Allow Expo experiences to access your device's accelerometer</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Give Expo experiences permission to save photos</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Give Expo experiences permission to access your photos</string>

查看 Expo 官方文档这里

React-native Init

如果您需要更低级别的访问权限,请考虑使用react-native init MyProject而不是create-react-native-app MyProject

这将为您提供对所有 iOS 和 Android 包的完全访问权限。

React-native eject

或者,如果您已经通过create-react-native-app MyProject构建了您的应用程序,则可以运行react-native eject来获取react-native-init MyProject的构建版本。

请注意,运行此命令后无法返回。


3
我不确定你发布这个答案后是否有更改,但是expo的文档指定您现在可以在“infoPlist”条目中放置任意键/值而无需进行其他验证。请参见此处的文档:https://docs.expo.io/versions/latest/config/app/#infoplist - stuckj
4
您可以运行 expo prebuild 来为您的项目生成本机代码,并查看在托管的 EAS 构建中生成的 Info.plist。 在传统的 expo build:ios 项目中,生成的 Info.plist 可能会略有不同。 - Evan Bacon
你知道如何编写语法来允许 NSAllowsArbitraryLoads 为 true 吗?我需要在开发中启用 HTTP 调用,但是我无法使设置被检测到。 - Eric Hasegawa
这可能在最初创建时已经发生了变化,但根据Expo当前的信息,“infoPlist”是一个“任意配置字典,用于添加到独立应用程序的本地Info.plist中。在所有其他Expo特定配置之前应用。不进行其他验证,因此使用时需自行承担被App Store拒绝的风险。”所以应该支持任何任意的Info.plist值。 - Falgantil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接