How to call AppController.mm method from CCApplication.mm? (Ads integration)

Hi everyone!
I added RevMob ads to my Android game today and now I am adding it to iOS version (this tutorial: http://sdk.revmobmobileadnetwork.com/ios.html).
It works well but I want to manually tell when to show/hide ads.
What I did was added method showAds() to CCApplication.cpp and CCApplication.mm classes.
I managed it on Android, but I don’t know how to do it on iOS.
My RevMob banner is in AppController.mm class:

+ (void)show {
    [RevMobAds startSessionWithAppID:@"ads id"];
    [RevMobAds session].testingMode = RevMobAdsTestingModeWithAds;
    [[RevMobAds session] showBanner];
}

and I have following method in CCApplication.mm:

void CCApplication::showAds(bool pszUrl)
{
    //here i wanna to execute show() method
}

I don’t know ObjectiveC but I suppose it is very easy to do :slight_smile:
In Java I did it with abstract method added to Cocos2dxActivity.java and implemented in MyGame.java

How can I execute show() method from CCApplication.mm?
Or is there any other solution to show/hide RevMob banner on iOS platform game?
Thanks in advance!
Best regards!

you should be able to call
CCApplication::getInstance().showAds()
Directly from your c++ code

Thank you very much for your reply.
I don’t need to call showAds() from AppController.mm but I need to call AppController’s (void)show method from CCApplication.mm.
Thanks!

Anyone?
Did you guys manage to show/hide AdMob on iOS?

Did you find the solution yet? I’m having the same trouble.

Regards,
-KhangAzun

Hi, I used NSNotification center:


Regards,

Hi sortris,

Thanks for the quick reply. I will follow the links.

Best regards,
-KhangAzun

Easiest way is:

[AppController show];

That works because your show method is static (the + indicate a static method in Objective-C).
For non-static methods, you need to acquire an instance of the object. The easiest way to do that is to use a singleton, for example:

[[AppController sharedController] show];

Please note: to do that, your file needs to be a .mm (.m or .cpp won’t work), and it’s iOS specific, so it’s best if you put the file in an iOS specific location.
The prefered way to do wrappers (because that’s what it is) is to have the .h shared between all platforms, and a .cpp (Android) or .mm (iOS) specific to the platform, which implements the .h methods.