Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

New Tutorial (29) - Codea v1.5.2: Objective C Add On, iAds

edited April 2013 in Code Sharing Posts: 563

If you are interested in adding iAds to your exported projected then have a look at our latest tutorial at: http://codeatuts.blogspot.com.au/2013/04/tutorial-29-codea-v152-objective-c-add.html

Feel free to use in your own projects. Comments welcome.

Tagged:

Comments

  • Posts: 2,042

    @Reefwing, do you have a tutorial for iAPs?

  • Posts: 563

    Not yet...

    I'll have a crack next weekend.

  • Posts: 2,042

    Awesome

  • Posts: 2,042

    @Reefwing I added iAds using the above tutorial and everything worked great until just recently I started getting an error where if I click on an ad in game, when I return to the game it causes an error and stops working. Do you know what's going on?

  • Posts: 119

    Sounds good. Still waiting for your in-app purchase tutorial :) haha

  • Posts: 563

    @zapaper - yep. Just finished my Collision Detection tute. iAP is next. Everything takes longer than you think...

    @JakAttak - are you pausing Codea when the ad is opened and then restarting it when the ad closes? You need to implement the ADBannerViewDelegate Protocol. This has two call back methods which tell you when an ad is opening or closing.

    //  This method is triggered when the user touches the iAds banner in your application. If the willLeave argument 
    //  passed through to the method is YES then your application will be placed into the background while the user is 
    //  taken elsewhere to interact with or view the ad. If the argument is NO then the ad will be superimposed over your 
    //  running application.
    
    - (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
    {
        self.codeaViewController.paused = YES;
        NSLog(@"Ad being displayed - Codea paused.");
    
        return YES;
    }
    
    //  This method is called when the ad view removes the ad content currently obscuring the application interface. 
    //  If the application was paused during the ad view session this method can be used to resume activity.
    
    - (void)bannerViewActionDidFinish:(ADBannerView *)banner
    {
        self.codeaViewController.paused = NO;
        NSLog(@"Ad dismissed - Codea running.");
    }
    
  • Posts: 2,042

    @Reefwing, is it supposed to pause and then restart? Because that's not what I want to happen. It should resume from where it was.

  • Posts: 563

    @JakAttak - sorry I meant pause and resume. Poor choice of words on my part.

    I've gone back and checked the two apps that I have exported from Codea with iAds and they work ok when the ad is tapped and closed. However, I'm only showing ads on the menu screen so nothing particularly complex is going on. What error are you getting?

  • Posts: 2,042

    I use a finite state machine that saves the current "scene" as a variable screen and then do screen:draw(), screen:touched(touch), etc. after exiting an ad it says something like "trying to index nil value screen"

  • Posts: 563

    Sounds like your screen variable is being deleted or released somehow. I'm not sure what happens under the covers when the codeaViewController is paused - @Simeon may have some thoughts.

    As a work around can you save the screen variables locally when an ad appears and then check if screen is nil and recreate it when the ad is dismissed?

  • Posts: 2,042

    How do you tell that an ad has been clicked?

  • Posts: 563

    That's when the method - (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave - gets called.

  • Posts: 2,042

    But that's not a lua function is it? Do I need to add it?

  • Posts: 563

    hmm - thinking about this a bit more, I don't know a way to call a lua function running in the Codea sandbox from Objective C. I'm sure there is a way, I just don't know how to do it. The add-on functionality allows you to go the other way (call an Objective C method from Lua).

    What you need is a register Lua call back method added to the CodeaViewController.

    Alternately, if 2 new functions were added to Codea like viewControllerWillPause and viewControllerResumeFromPause, that would do the trick. However I suspect that isn't likely.

  • Posts: 2,042

    @Reefwing, after doing some more testing I realized that this doesn't happen in the simulator. So I'm wondering if maybe it's just my device... But I'm not sure

  • Posts: 563

    That's interesting, I only tested on the Simulator. Let me see if the same thing happens for me.

  • Posts: 563

    @JakAttak - I just checked the tute code on my iPad. It works ok.

  • Posts: 2,042

    Alright. Well, I'll test my app on another device. What really matters is that it works for everyone else

  • Posts: 392

    I am trying to add @Reefwing 's ads to my codea project in Xcode, but am experiencing some linking problems. I am very new to this, so probably an error on my part. I am trying to do it without the audio addOn.

    I modified the AppDelegate.h and AppDelegate.mm as described in the tutorial.
    I created a new file IAdsAddOn.h. From the tutorial it was not completely clear how or where to do this. The IAdsAddOn.h file is located just below the CodeaAddon.h (does it matter the order of the files in the Addons folder?)

    The build reports the following errors...

    Undefined symbols for architecture i386:
    "OBJC_CLASS$_IAdsAddOn", referenced from:
    objc-class-ref in AppDelegate.o
    ld: symbol(s) not found for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    I have checked numerous times the files are the same as in the tutorial (especially the use of capital I or small i).

    Anyone have an idea how to fix this? I am stuck!

  • Did you include the IAd framework into your app? I bet that is the problem. Visit this link:

    http://stackoverflow.com/questions/8845625/undefined-symbols-for-architecture-i386-building-for-ios

  • Posts: 1,976

    @austinmccoy Look at the last post date...I'm sure he's figured it out by now, or at least he's been posting some other things.

  • edited August 2014 Posts: 145

    @austinmccoy Obviously he has figured it out, considering it is over a year old. It is still helpful to others though.

  • Posts: 392

    Actually at the. time i didn't solve my problems with iads, so in the end i submitted my app 'circulation'
    https://itunes.apple.com/gb/app/circulation-1/id695148887?mt=8
    as a paid app. Consequently it had very few downloads!

    Soon i hope I will get around to submitting my new app (LinkemUp)
    http://codea.io/talk/discussion/comment/42019#Comment_42019
    I will try to make this one free with iads. So thanks @austinmccoy for your suggestion, perhaps that was my problem.

  • Cool!

Sign In or Register to comment.