Flutter应用Android正常运行,iOS启动崩溃问题求助
问题定位
崩溃的核心原因是Google Mobile Ads SDK初始化时未读取到有效的应用ID,查看你提供的info.plist可以发现,GADApplicationIdentifier配置被错误嵌套在UISupportedInterfaceOrientations~ipad的数组内部,导致iOS系统无法识别这个配置项。
修复方案
- 打开iOS项目的
info.plist文件(可通过Xcode编辑Runner目录下的文件,或直接修改源码) - 将
GADApplicationIdentifier及其对应值从UISupportedInterfaceOrientations~ipad数组中移出,放到<dict>的根层级下 - 清理
UISupportedInterfaceOrientations~ipad数组中多余的<true/>节点(数组仅允许存放方向字符串)
修正后的关键代码片段:
<!-- 修正后的iPad屏幕方向配置 --> <key>UISupportedInterfaceOrientations~ipad</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> <!-- 移至根层级的AdMob应用ID配置 --> <key>GADApplicationIdentifier</key> <string>ca-app-pub-3940256099942544~1458002511</string>
额外验证点
- 你使用的
ca-app-pub-3940256099942544~1458002511是Google官方测试ID,用于开发阶段测试是合法有效的 - 确保Flutter代码中正确初始化广告SDK,比如在
main函数中调用MobileAds.instance.initialize()
内容的提问来源于stack exchange,提问作者Pramod Yadav
相关产品推荐
相关产品推荐

