Search Unity

Question Add Admob to unity-project and build to ios xcode

Discussion in 'iOS and tvOS' started by markknoffer, Feb 21, 2021.

  1. markknoffer

    markknoffer

    Joined:
    Dec 20, 2020
    Posts:
    23
    hello,

    hope somebody could help me. i am trying to build an example game that includes admob and unity ads in xcode.

    i am not sure if i am doing it right, as i do not see any admob ads when building the project to my iphone device.

    could somebody help me and tell me if i am doing it right and if there is something missing.

    here are my steps:


    1)
    downloaded and installed google mobile ads unity plugin from here: https://github.com/googleads/googleads-mobile-unity/releases/tag/v5.4.0
    -> imported it to the unity project and set the right app-id in the settings
    -> added banner and interstitial to the game

    2)
    build the game to as ios build.
    -> before that installed cocoapods in assets menu

    3)
    in the builded xcode folder i opened podfile and checked if this was there:
    pod 'Google-Mobile-Ads-SDK'
    -> yes it was

    4)
    opened terminal and put „cd build-folder-location“ (get into the build folder where unity created the xcode build)

    5)
    typed in the cocoapods command so that it installs Google-Mobile-Ads-SDK into the folder of the xcode-project:
    pod install --repo-update

    -> here i am not sure if step 4&5 are needed?

    6) opened the newly created Unity-iPhone.xcworkspace file

    here i am not sure if i need to put anything in the code, as admob say that you should add this:

    Code (CSharp):
    1. @import GoogleMobileAds;
    2.  
    3. @implementation AppDelegate
    4.  
    5. - (BOOL)application:(UIApplication *)application
    6.     didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    7.  
    8.   [[GADMobileAds sharedInstance] startWithCompletionHandler:nil];
    9.   return YES;
    10. }
    11.  
    12. @end
    i dont have a file called
    AppDelegate.m

    but in some other file of my xcode-project (file called UnityAppController.mm) i have similar code as discribed here:
    https://developers.google.com/admob/ios/quick-start#objective-c

    so i tried to add the recommended code:

    Code (CSharp):
    1. @import GoogleMobileAds;
    but this gives error:
    Use of '@IMpoRt' when C++ modules are disabled, consider using -fmodules and -fcxx-modules

    however i did not put anything from this section to „initialize the mobile ads sdk“.

    -

    in my xcode project in the info settings my app-id is set correctly to GADApplicationIdentifier and also SKAdNetworkItems in included.

    ——


    When i build the app to the iphone everything works as it should but the ads dont get displayed.

    in the run editor i see this when searching for google:

    Code (CSharp):
    1. 2021-02-21 14:02:40.410371+0100 journey[11302:2154750] <Google> To get test ads on this device, set: GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = @[ @"myidisdisplayedhere" ];
    also this


    Code (CSharp):
    1. 2021-02-21 14:02:51.921547+0100 appname[11302:2155022]  - <Google>[I-ACS901017] Encounter network error. Code, error: -1005, Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=-4, NSUnderlyingError=0x281218f90 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDownloadTask <5B238684-60A5-448C-B481-C65CD75F974E>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    2.     "LocalDownloadTask <5B238684-60A5-448C-B481-C65CD75F974E>.<1>"
    3. ), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=https://app-measurement.com/config/app/ca-app-pub-xxmyidxx~xxmyidxx?platform=ios&app_instance_id=&gmp_version=70500, NSErrorFailingURLKey=https://app-measurement.com/config/app/ca-app-pub-xxmyidxx~xxmyidxx?platform=ios&app_instance_id=&gmp_version=70500, _kCFStreamErrorDomainKey=4}
    4. 2021-02-21 14:02:51.923249+0100 appname[11302:2155163]  - <Google>[I-ACS023128] Network request failed to fetch remote config. Code, Error: 0, Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=-4, NSUnderlyingError=0x281218f90 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDownloadTask <5B238684-60A5-448C-B481-C65CD75F974E>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    5.     "LocalDownloadTask <5B238684-60A5-448C-B481-C65CD75F974E>.<1>"
    6. ), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=https://app-measurement.com/config/app/ca-app-pub-xxmyidxx~xxmyidxx?platform=ios&app_instance_id=&gmp_version=70500, NSErrorFailingURLKey=https://app-measurement.com/config/app/ca-app-pub-xxmyidxx~xxmyidxx?platform=ios&app_instance_id=&gmp_version=70500, _kCFStreamErrorDomainKey=4}
    hope somebody can help me and tell me what i am doing wrong and the steps i did are the correct way to implement admob to a unity project to let let run on xcode/ios.

    thanks in advance,
    mark
     
  2. nordicelectronics

    nordicelectronics

    Joined:
    Oct 4, 2014
    Posts:
    10
    I have also a issue with google mobile ads unity plugin v.5.4.0 as you downloaded.
    I have been at this 2 days already, and what I found out is that its not working on either Android or iOS.
    I even did a clean project in Unity 2019.4.21, and only imported the unitypackage + made a script to show ads => Nothing working.
    So as far as I am concerned this unitypackage does not work out of the box at least.
    This version is needed because of the new Ad requirement in iOS

    Hope someone else can help out here.
     
  3. Riz1

    Riz1

    Joined:
    Nov 11, 2015
    Posts:
    4
    I also have same Issue I did everything but Google Ads not displaying no error found game work perfectly but ads not displaying. If I check in Unity Ads displaying perfectly.
     
  4. kimmo1

    kimmo1

    Joined:
    Feb 7, 2014
    Posts:
    49
    Did you find solution? my ads show on android and editor but ios wont... unity newest 2019v.
     
  5. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    Still got same problem... I listed my iphone as test device at admob website, but not work. Ads not showing in my iphone 13 device.

    Used proven c# code that worked well at android.

    What additionally should I where setting? Too complicated....