[Cordova] cordova-plugin-admob-free 廣告外掛在 iOS 平台當機?

[Cordova] cordova-plugin-admob-free 廣告外掛在 iOS 平台當機?

今天要用 Cordova 編譯 iOS app,編譯沒有問題,

但執行時卻莫名的當掉,

從 Xcode 的錯誤訊息來看,寫著:

Terminating app due to uncaught exception ‘GADInvalidInitializationException’, reason: ‘The Google Mobile Ads SDK was initialized incorrectly. Google AdMob publishers should follow instructions here: https://googlemobileadssdk.page.link/admob-ios-update-plist to include the AppMeasurement framework, set the -ObjC linker flag, and set GADApplicationIdentifier with a valid App ID. Google Ad Manager publishers should follow instructions here: https://googlemobileadssdk.page.link/ad-manager-ios-update-plist’

 

依照訊息中的連結,

到 https://googlemobileadssdk.page.link/ad-manager-ios-update-plist 看看,

提到的是要在 Info.plist 檔案裡面,加上 GADApplicationIdentifier 資訊。

 

我的 Cordova app 的廣告是用 cordova-plugin-admob-free 外掛

看了一下官網,裡面有提到將 GADApplicationIdentifier 加入的方法,

是在 config.xml 的 <platform name=”ios”> 區塊下,

加入如下的程式碼:

<config-file target="*-Info.plist" parent="GADApplicationIdentifier">
    <string>ca-app-pub-1971976XXXXXXXXX~44YYYYYYYY</string>
</config-file>

 

不過加好之後重新編譯執行,一樣當掉…

搜尋了一下,在 <Project name>-Info.plist 裡面,

有看到 GADApplicationIdentifier 的定義,為什麼還是不行呢?

 

又上網查了一下,有人說還要加上 GADIsAdManagerApp,

不過沒有範例,就仿照 GADApplicationIdentifier 加了一筆:

<config-file target="*-Info.plist" parent="GADIsAdManagerApp">
    <string>true</string>
</config-file>

 

噹噹~編譯執行後,這次 app 可以成功執行沒有當掉了~

話說回來,這個 AdMob SDK 是有多傲嬌啊,

上次是 Android 版本 app 因為沒指定 ADMOB_APP_ID 就當機

這次是在 iOS 版本上因為類似的原因也當掉,

沒指定就頂多沒廣告不就好了嗎,非得要死一下?!

 

參考資料:cordova ‘admob free’ in ios – exception when app running – Stack Overflow

(本頁面已被瀏覽過 530 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料