titaniumappceleratorappcelerator-titaniumappcelerator-hyperloophyperloop

Hyperloop and Google Mobile Ads SDK


I'm trying to use Google-Mobile-Ads-SDK in my appcelerator project since ti.admob (https://github.com/appcelerator-modules/ti.admob) doesn't seem to support rewarded ads. So I created a Podfile in the top project directory:

install! 'cocoapods',
         :integrate_targets => false

platform :ios, '7.0'

target 'my app' do
  use_frameworks!
  pod 'Google-Mobile-Ads-SDK', '7.15'
end

(I couldn't use the latest version of the pod, Xcode bailed on some type declaration issue - this one compiled fine.)

Then I used the library, like this:

var GADRequest = require('GoogleMobileAds/GADRequest');
var GADRewardBasedVideoAd = require('GoogleMobileAds/GADRewardBasedVideoAd');
var instance = GADRewardBasedVideoAd.sharedInstance();
if (!instance.isReady()) {
  var request = new GADRequest();
  instance.loadRequest(request, Alloy.CFG.rewardedadid);
}

And the code failed with error:

TypeError: undefined is not a function
(evaluating 'instance.loadRequest(request, Alloy.CFG.rewardedadid)')

Looking at the corresponding generated .js file at ./build/hyperloop/ios/js/googlemobileads/gadrewardbasedvideoad.js, I noticed that function signatures for instance methods and properties are generated for all that is in GADRewardBasedVideoAd.h except for loadRequest(). The header entry for loadRequest() is:

- (void)loadRequest:(GADRequest *)request withAdUnitID:(NSString *)adUnitID;

The only noticeable difference with this is that it's using a named parameter. Is there anything special with this kind of method? Am I doing something wrong or does Hyperloop not yet support such functions?


Solution

  • The issue here is that you are not including the full signature (missing the withAdUnitID: selector). For fixing it, simply concatenate parameters in Hyperloop like this:

    // Compiles to native "loadRequest:withAdUnitID:"
    instance.loadRequestWithAdUnitID(request, Alloy.CFG.rewardedadid);
    

    This is documented in the Named Methods section of the Hyperloop Programming Guide.

    Tip: There is an open source example of using the Google Mobile Ads Android Library on Hyperloop as well, try it out!