添加flutter的image_picker依赖时出错(iOS)

qxsslcnc  于 2023-04-07  发布在  Flutter
关注(0)|答案(3)|浏览(333)

我需要为我的应用程序使用image_picker。我将image_picker依赖项添加到我的pubspec.yaml文件中,并且对于iOS,我将NSCameraUsageDescription NSPhotoLibraryUsageDescription NSMicrophoneUsageDescription添加到info.plist文件中,但是当我尝试在iOS模拟器上运行应用程序时,我会遇到此错误。
这是我在尝试运行应用程序时得到的错误.在调试模式下启动lib/main.dart on iPhone 11 Pro Max.../Users/sirapol/Desktop/FirstCareFrontEnd/care_now_frontend_v1/ios/Runner/Info.plist:属性列表错误:在第27行找到非键/ JSON错误:JSON文本未以数组或对象开头,并且未设置允许片段的选项。正在运行Xcode build... Xcode build done. 2.4s Failed to build iOS app Xcode build的错误输出:**构建失败** Xcode的输出:/Users/sirapol/Desktop/FirstCareFrontEnd/care_now_frontend_v1/build/ios/Debug-iphonesimulator/flutter_plugin_android_lifecycl e/flutter_plugin_android_lifecycle.framework:不允许资源分叉、Finder信息或类似的碎屑命令CodeSign失败,退出代码为非零注解:使用新构建系统注意事项:规划构建注解:正在构造生成说明警告:正在将体系结构armv7Map到i386。确保已为iOS模拟器平台正确配置此目标的体系结构和有效体系结构生成设置。(在项目“Pods”的目标“image_picker”中)警告:正在将体系结构arm 64Map到x86_64。确保已为iOS模拟器平台正确配置此目标的体系结构和有效体系结构生成设置。(在项目“Pods”的目标“image_picker”中)警告:签名的权能&权能可能无法正常工作,因为其权利使用占位符团队ID。若要解决此问题,请在Runner编辑器中选择开发团队。(在项目“Runner”的目标“Runner”中)
这是我的pubspec.yaml文件的一部分

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  provider: ^3.0.0
  http: ^0.12.0+4
  image_picker: ^0.6.3+1
  path_provider: ^1.1.0

dev_dependencies:
  flutter_test:
    sdk: flutter

这是我的info.plist文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>care_now_frontend_v1</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
  <key>NSLocationWhenInUseUsageDescription</key>
    <key>NSCameraUsageDescription</key>
    <key>NSPhotoLibraryUsageDescription</key>
    <key>NSMicrophoneUsageDescription</key>
  <false/>
</dict>
</plist>

我不知道为什么会出现错误。因为我已经做过一次了,没有错误。谢谢你的帮助

q5iwbnjs

q5iwbnjs1#

你需要确保在plist文件中的键值之后添加了一个值。在这些键下添加字符串值,它应该可以解决这个问题。
示例:

<key>NSLocationWhenInUseUsageDescription</key>
<string>Allow access to your phone's location</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Allow access your photo library</string>
<key>NSCameraUsageDescription</key>
<string>Allow access your phone's camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>Allow the app to record using your phone's microphone</string>

至于架构Map错误,请尝试在xcode项目中将iOS部署目标设置为9.0或更高版本。
另外,我注意到你的代码示例中有一个尾随值,看起来应该移到下面

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
izkcnapc

izkcnapc2#

如果其他人有这个问题,如果你在文件的末尾添加密钥,它将失败并发送Xcode无法读取Info.plist文件错误,请在Xcode版本12上测试它。
例如,此文件将正常工作:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> 
<dict>  
<key>CFBundleDevelopmentRegion</key>    
<string>$(DEVELOPMENT_LANGUAGE)</string>    
<key>CFBundleExecutable</key>   
<string>$(EXECUTABLE_NAME)</string>     
<key>CFBundleIdentifier</key>   
....
    <key>NSPhotoLibraryUsageDescription</key>   
    <string>Share pictures</string>     
    <key>NSCameraUsageDescription</key>     
    <string>Share pictures</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/> 
</dict> 
</plist>

但是,如果像这样将关键点移动到末尾,则会失败:

....
    <key>UIViewControllerBasedStatusBarAppearance</key>
        <key>NSPhotoLibraryUsageDescription</key>   
        <string>Share pictures</string>     
        <key>NSCameraUsageDescription</key>     
        <string>Share pictures</string>
    <false/> 
    </dict> 
    </plist>
z6psavjg

z6psavjg3#

如果你在编译时遇到的错误是在xcode上,那么你可以打开你的Podfile并添加这个

ENV['COCOAPODS_DISABLE_STATS'] = 'true'
platform :ios, '9.0'
project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

希望这将解决image_picker问题,它对我有效,我能够发布

相关问题