iOS项目运行报错:Info.plist第34行存在非键元素求助
iOS项目运行报错:Info.plist结构错误修复方案
错误原因分析
报错提示Info.plist: Property List error: Found non-key inside <dict> at line 34,核心问题是Info.plist的XML结构不符合plist字典规范——<dict>标签下必须严格遵循「<key> + 对应值类型(如<string>/<array>)」的成对结构,不能出现孤立的<key>或错位的键值对。
查看你的plist代码,问题出在这一段:
<key>UISupportedInterfaceOrientations</key> <key>NSMicrophoneUsageDescription</key> <string>This app requires Mic permission.</string> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array>
<key>UISupportedInterfaceOrientations</key>定义后,没有立即跟上它对应的<array>值,反而插入了NSMicrophoneUsageDescription的键值对,导致结构混乱:UISupportedInterfaceOrientations的key没有对应值,而NSMicrophoneUsageDescription的key被错误地放在了前一个key的value位置,触发了plist解析错误。
修正后的完整Info.plist代码
将NSMicrophoneUsageDescription的键值对移到正确位置(确保每个key都紧跟对应的value),修正后的代码如下:
<?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>CFBundleDisplayName</key> <string>Quezzy</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>quezzy</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>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>NSMicrophoneUsageDescription</key> <string>This app requires Mic permission.</string> <key>UISupportedInterfaceOrientations~ipad</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> <key>UIViewControllerBasedStatusBarAppearance</key> <false/> <key>CADisableMinimumFrameDurationOnPhone</key> <true/> <key>UIApplicationSupportsIndirectInputEvents</key> <true/> </dict> </plist>
验证方法
替换后重新编译项目,若仍有报错,可通过Xcode的「File > Open」直接打开Info.plist,切换到「Property List」可视化视图,Xcode会自动高亮显示结构错误的位置,方便进一步排查。
内容的提问来源于stack exchange,提问作者Rio
相关产品推荐
相关产品推荐

