配置文件Info.plist

  1. Info.plist 是什么?
  2. Info.plist 的作用
    1. 应用基础信息
    2. 权限用途说明(最关键)
    3. UI/功能配置
    4. 系统集成信息

Info.plist 是什么?

全称:Information Property List

类型:XML 格式的配置文件

位置:Flutter iOS 项目里在 ios/Runner/Info.plist

作用:告诉 iOS 系统关于 App 的 元信息(Metadata),让系统知道 App 能做什么、权限用途是什么、如何启动等

Info.plist 就是 iOS 系统读取的 App “说明书”,告诉系统:这个 App 能干什么,需要哪些权限,以及如何表现。

Info.plist 的作用

应用基础信息

App 名称、Bundle ID、版本号

<key>CFBundleName</key>
<string>MyApp</string>
<key>CFBundleIdentifier</key>
<string>com.example.myapp</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>

权限用途说明(最关键)

iOS 规定:访问 敏感权限(相机、麦克风、相册、定位、通知等)必须写用途说明,否则系统会直接拒绝权限请求。

<key>NSCameraUsageDescription</key>
<string>需要使用相机来拍照</string>

<key>NSPhotoLibraryUsageDescription</key>
<string>需要访问相册来选择图片</string>

<key>NSMicrophoneUsageDescription</key>
<string>需要使用麦克风来录音</string>

没写 → permission_handler 请求权限会直接返回 permanentlyDenied

UI/功能配置

启动画面、状态栏风格、横竖屏方向、深色模式支持等

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UISupportedInterfaceOrientations</key>
<array>
  <string>UIInterfaceOrientationPortrait</string>
</array>

系统集成信息

URL Scheme、推送通知配置、后台模式配置等

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>myapp</string>
    </array>
  </dict>
</array>

×

喜欢就点赞,疼爱就打赏