Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 38    Views: 267

Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
02/08/13 09:06 PM (12 years ago)

Tutorial: How to disable ads using the Easy IAP Plugin

WARNING - THIS TUTORIAL IS OUTDATED AND WONT COMPILE CORRECTLY I figured some of you guys might be interested in this - this is a method I just worked up of using the Easy IAP plugin to add a "Disable Ads" in-app-purchase to your app. 1. Download the Easy In App Purchase plugin (iOS only) - <a href="http://www.buzztouch.com/plugins/plugin.php?pid=16E7586E9E8D437768AEE84" target="_blank" rel="nofollow">http://www.buzztouch.com/plugins/plugin.php?pid=16E7586E9E8D437768AEE84</a> 2. Set up the IAP like you would any other - fill in the details in ITC, create the screen in your control panel, etc. There's already a ton of stuff on the forums explaining how to do these things. You will also need at least one test user to be set up on ITC...this tutorial explains how - <a href="http://www.buzztouch.com/files/howtos/inAppPurchase.pdf" target="_blank" rel="nofollow">http://www.buzztouch.com/files/howtos/inAppPurchase.pdf</a> 3. Go to the .h file of whatever plugin you have set up as your home screen - scroll down to where all of the "-(void)" lines are and add this line of code - -(void)disableAds; 4. Now you need to create the "disable ads" button. I do this by simply adding the button to the navigation bar of my main menu. First of all, go to the .m file of whatever plugin you have set up as your home screen - in my case this is BT_screen_menuButtons.m. Next, add this block of code inside of the "viewWillAppear" method - if(![[NSUserDefaults standardUserDefaults] boolForKey:@"noAds"]) { ((UINavigationController*)[appDelegate.rootApp.rootNavController.retain retain]).navigationBar.topItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:(@"Disable Ads") style:UIBarButtonItemStyleBordered target:(self) action:@selector(disableAds)]; } else { nil; } If you want it to be on the left side then just change "rightBarButtonItem" to "leftBarButtonItem" - the result will look something like this - <a href="http://www.pixobit.com/wp-content/uploads/2013/02/iOS-Simulator-Screen-shot-Feb-8-2013-6.32.02-PM.png" target="_blank" rel="nofollow">http://www.pixobit.com/wp-content/uploads/2013/02/iOS-Simulator-Screen-shot-Feb-8-2013-6.32.02-PM.png</a> 5. In the same .m file, right after the "viewWillAppear" method referred to above, add the following disableAds method - -(void) disableAds{ //flag this as the current screen onedirectiontriviagame_appDelegate *appDelegate = (onedirectiontriviagame_appDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.rootApp.currentScreenData = self.screenData; BT_item *screenObjectToLoad = [appDelegate.rootApp getScreenDataByNickname:@"Disable Ads"]; [BT_viewControllerManager handleTapToLoadScreen:self.screenData :nil :screenObjectToLoad]; } !!IMPORTANT!!! The above code is telling your button what screen to go to when it is tapped. Replace "Disable Ads" with whatever the Screen Nickname of your IAP is 6. Go to Easy_in_app_purchase.m -- find the "goToPurchasedScreen" method -- replace the ENTIRE method with this -- -(void)goToPurchasedScreen{ [BT_debugger showIt:self:@"goToPurchasedScreen"]; purchasePageFlag = YES; if([[BT_strings getStyleValueForScreen:self.screenData:@"navBarTitleText":@""] isEqualToString:@"Disable Fullscreen Ads"]) { //flag this as the current screen YOUR_DELEGATE_HERE *appDelegate = (YOUR_DELEGATE_HERE *)[[UIApplication sharedApplication] delegate]; appDelegate.rootApp.currentScreenData = self.screenData; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"noAds"]; [appDelegate downloadAppData]; } //load next screen if we have a next screen nickname set... else if([productScreenNickname length] > 1){ onedirectiontriviagame_appDelegate *appDelegate = (onedirectiontriviagame_appDelegate *)[[UIApplication sharedApplication] delegate]; BT_item *screenObjectToLoad = [appDelegate.rootApp getScreenDataByNickname:productScreenNickname]; [BT_viewControllerManager handleTapToLoadScreen:self.screenData :nil :screenObjectToLoad]; } } !!IMPORTANT!! The above code check the navigation bar text of your IAP - if it matches the nav bar text you have set for your "disable ads" IAP, then it will execute the code that disables the ads. Otherwise it will run the usual IAP code that takes users to locked screens. You will need to edit the above code and replace YOUR_DELEGATE_HERE with your app delegate name, and you will also need to make sure the "navBarTitleText" matches up with that of your IAP. The code saves a BOOL that it will check before running ads, and it also runs the [appDelegate downloadAppData]; method. The point of running this method is to restart the app, after which the "disable ads" button will no longer be visible. If you scroll up to the button code, you will see this is because the button is set to only show if the BOOL equals NO (the in app purchase set it to equal YES) I'm no expert on this BOOL stuff so if anybody feels the need to correct me feel free :P 7. Set up the ads. I'm assuming you already have your ads set up somewhere - to make this work, all you need to do is use the same if/else statement that was used to create the button. For instance - this is what it looks like in the appDelegate of my app - if(![[NSUserDefaults standardUserDefaults] boolForKey:@"noAds"]) { [ALInterstitialAd showOver: [application.windows lastObject]]; //show revmob fullscreen RevMobFullscreen *fullscreen = [[RevMobAds session] fullscreenWithPlacementId:@"xxxxxxxxxxxxxxxxxx"]; [fullscreen showAd]; // Configure Chartboost Chartboost *cb = [Chartboost sharedChartboost]; cb.appId = @"xxxxxxxxxxxxxxxxxx"; cb.appSignature = @"xxxxxxxxxxxxxxxxxx"; // Show Interstitial [cb cacheInterstitial]; [cb showInterstitial]; }else{ nil; } As always, if anybody is stuck on anything just let me know!
 
theMonster
Code is Art
Profile
Posts: 435
Reg: Oct 18, 2011
US
8,050
like
02/08/13 09:25 PM (12 years ago)
So cool. Lots of people have wondered about adding/disabling Ads with my plugin. You should throw this into a .pdf for the how-to section. I wish BT would finish reviewing my plugin :/ I know they're busy and all but I can't wait for you guys to use iAPv2.0.
 
awesome123
Aspiring developer
Profile
Posts: 132
Reg: Dec 27, 2011
location unknow...
2,320
like
02/08/13 09:43 PM (12 years ago)
How do you get this great with no programming knowledge? Everything you share is PURE GOLD!
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
02/09/13 12:31 AM (12 years ago)
Great tutorial Absentia! Have you thought about about creating plugins? I'm 110% sure you'd be great at it.. You tweak so well and your tutorials are awesome! I hope to see you make plugins. I know you can do it!! Thanks for this :) @theMonster... looking forward to the update too!
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
02/09/13 02:11 AM (12 years ago)
I'm one of Abs biggest fans!
 
Black White
I hate code!
Profile
Posts: 292
Reg: Feb 22, 2012
hanoi
4,770
like
02/09/13 03:00 AM (12 years ago)
Great tutorial @Absentia i really need it Thank you so much i will try it anf feedback soon
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
02/09/13 04:24 AM (12 years ago)
Nice one buddy! Post of the weekend without a doubt.
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
02/09/13 02:11 PM (12 years ago)
Thanks a lot for the feedback guys! I'll try to get a PDF together today @awesomatt - I wouldn't be able to figure any of this stuff out without the wealth of useful info in these forums. And for whatever problem these forums can't solve, http://stackoverflow.com is amazing - you can literally find the solution to any problem imaginable on that site @mysps - haha, I appreciate the confidence, but I'm not so sure. I might dig into all of the webinars and give it a go one of these days, but lately I've been 100% absorbed with creating and updating apps
 
awesome123
Aspiring developer
Profile
Posts: 132
Reg: Dec 27, 2011
location unknow...
2,320
like
02/18/13 10:00 PM (12 years ago)
yeah i agree i search that site for most of my xcode problems :D anyway, i was not able to make the button work on the BTA design menu. it worked when i placed it inside the appdelegate.m file where the appoxee button is placed. however im having an error 'screenData' not found on object of type 'appname_appDelegate' what do you think? when i set it up with bta design menu it appears for half a second whenever i click on a back button that leads to the bta design menu (click a menu button - press back button - the disable ads button appears for half a second)
 
awesome123
Aspiring developer
Profile
Posts: 132
Reg: Dec 27, 2011
location unknow...
2,320
like
02/18/13 10:55 PM (12 years ago)
by the way absentia i have an unrelated question what's your eCPM with the more apps button that leads to chartboost? why don't you just put a revmob link instead of chartboost? have you tested which converts better?
 
Kahuna
Apple Fan
Profile
Posts: 137
Reg: Nov 18, 2011
Milan
4,670
like
03/12/13 04:57 AM (12 years ago)
Great tutorial! Thank you Absentia. I saw in your 1D app that there isn't the "disable ads" button anymore; is it on purpose or related to the BT recent update in the code? Thanks again for the precious code. Kahuna
 
Black White
I hate code!
Profile
Posts: 292
Reg: Feb 22, 2012
hanoi
4,770
like
03/23/13 07:57 PM (12 years ago)
hi @Absentia, i have propblem in step 4 pls help me :( this is screen http://img20.imageshack.us/img20/2396/screenshot20130324at955.png
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
03/24/13 10:05 AM (12 years ago)
Hey @ Black White - Check out this PDF - https://www.dropbox.com/s/6vq33p1fguefzhz/disableAds.pdf - It's a much better version of this tutorial with screenshots to follow along with let me know how that one works out for you
 
Black White
I hate code!
Profile
Posts: 292
Reg: Feb 22, 2012
hanoi
4,770
like
03/24/13 10:08 AM (12 years ago)
Thank you @Absentia i will try it right now and let me know soon :)
 
Black White
I hate code!
Profile
Posts: 292
Reg: Feb 22, 2012
hanoi
4,770
like
03/24/13 10:28 AM (12 years ago)
hi @Absentia, in step 6, i have problem with 2 error pls help :( this is screen http://img32.imageshack.us/img32/449/screenshot20130325at122.png
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
03/24/13 10:32 AM (12 years ago)
Unfortunately, I'm about to board a flight..I'll be at my computer tomorrow and I'll be able to help you out. I know what the issue is..the formatting in my tutorial is out of date on account of the recent buzztouch updates
 
Black White
I hate code!
Profile
Posts: 292
Reg: Feb 22, 2012
hanoi
4,770
like
03/24/13 10:35 AM (12 years ago)
Ok, i understand so i waiting for you tomorrow take care :) -- Hoang www.facebook.com/BlackWhiteApps
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
03/26/13 11:07 AM (12 years ago)
what's your email?
 
Black White
I hate code!
Profile
Posts: 292
Reg: Feb 22, 2012
hanoi
4,770
like
03/26/13 01:19 PM (12 years ago)
you can email to me at [email protected] thank you ! --Hoang
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
03/26/13 08:02 PM (12 years ago)
k will do, sorry I've been pretty busy today but I'll try to help you get it all worked out tomorrow
 
Black White
I hate code!
Profile
Posts: 292
Reg: Feb 22, 2012
hanoi
4,770
like
03/26/13 08:13 PM (12 years ago)
dont worry, im still waiting for you :)
 
Black White
I hate code!
Profile
Posts: 292
Reg: Feb 22, 2012
hanoi
4,770
like
03/29/13 12:55 AM (12 years ago)
Thank you @Absentia so much everything great good now :) im very grateful to you
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
04/27/13 11:34 AM (12 years ago)
the PDF is gone? :o(
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
04/27/13 12:40 PM (12 years ago)
That one was outdated...here's the updated one - https://www.dropbox.com/s/5ftv1x99vmmkena/Untitled.pdf
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
04/27/13 02:53 PM (12 years ago)
ok, thankyou. I'm using a menuwithimage as my home page of a tabbed screen Here's what i have at step 4: if(![[NSUserDefaults standardUserDefaults] boolForKey:@"noAds"]) { ((UINavigationController*)[appDelegate.rootApp.rootTabBarController objectAtIndex: 0]).navigationBar.topItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:(@"Disable Ads") style:UIBarButtonItemStyleBordered target:(self) action:@selector(disableAds)]; } it compiles ok and immediately bombs out with this: [BT_tabBarController objectAtIndex:]: unrecognized selector sent to instance 0xb53f8c0 2013-04-27 22:42:16.989 UK RaceTrack Finder[34152:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BT_tabBarController objectAtIndex:]: unrecognized selector sent to instance 0xb53f8c0'
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
04/27/13 03:20 PM (12 years ago)
Are you using the correct tab number? The five tabs at the bottom of the screen are numbered 0-4. You want to replace "objectAtIndex: 0" with whatever the number is of the tab in which you want the button to show (i.e. "objectAtIndex: 4" for the fifth tab)
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
04/27/13 03:32 PM (12 years ago)
yep, its on tab 0 (first tab) :o/ in code view, i have a yellow warning: 'BT_tabBarController' may not respond to 'objectAtIndex:'
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
04/27/13 11:39 PM (12 years ago)
Could it be because I have a lot of menuwithimage screens d'ya think? Maybe I'll set up a buttons page and try it on there, will mean a minor redesign but I think I can fit it in
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
04/29/13 01:24 PM (12 years ago)
Ok, i changed layout to non-tabbed and with a menubuttons home page, all good up to step 6. screenie: https://www.dropbox.com/s/hhxk1t0vw8dytbz/Screen%20Shot%202013-04-29%20at%2021.19.28.png EDIT: ok, ignore...there was a red error a few lines further down, which was a duplicate of [BT_debugger showIt:self theMessage:@"goToPurchasedScreen"]; purchasePageFlag = YES;
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
04/29/13 04:36 PM (12 years ago)
sorry I'm just now getting back to you on this.. For the tab bar issue..I figured out what the problem is. You need to add "viewControllers" directly after "rootTabBarController" - so, the whole block of code should look like this - if(![[NSUserDefaults standardUserDefaults] boolForKey:@"noAds"]) { ((UINavigationController*)[appDelegate.rootApp.rootTabBarController.viewControllers objectAtIndex: 0]).navigationBar.topItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:(@"Disable Ads") style:UIBarButtonItemStyleBordered target:(self) action:@selector(disableAds)]; } And as for the issue in your most recent post - that is apparently something I totally missed in updating the PDF. The way the code is formatted is outdated - replace the line of code from the screenshot that is highlighted in yellow with the following code - if([[BT_strings getStyleValueForScreen:self.screenData nameOfProperty:@"navBarTitleText" defaultValue :@""] isEqualToString:@"Disable Adverts"]){ I see you say that the issue is fixed in your edit, but I'm not sure how doing what you said would make that error go away
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
04/30/13 10:54 AM (12 years ago)
i think i had incorrectly copy/pasted hence i had a duplicate of [BT_debugger......] i'm so almost there! the button is in place, it links and launches iap, iap crashes out... log file: [Easy_in_app_purchase isAlreadyPurchasedShouldGoToScreen:]: unrecognized selector sent to instance 0xca34d10 2013-04-30 18:46:35.815 UK RaceTrack Finder[14969:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Easy_in_app_purchase isAlreadyPurchasedShouldGoToScreen:]: unrecognized selector sent to instance 0xca34d10' *** First throw call stack: so the button is on 'home', and the disable ads iap has a title bar name of Disable Adverts. I've double checked and treble checked the product identifier matches itc with iap. The 'purchased item' setting in iap links back to 'home'. My head hurts
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
04/30/13 05:03 PM (12 years ago)
sorted. edit. not sorted :o/
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
05/01/13 03:11 AM (12 years ago)
crapola. i thought it was sorted. but it seems now pressing disable ads button will skip straight through the easyIAP screen and assume its been purchased :o/
 
trouty
I hate code!
Profile
Posts: 338
Reg: Mar 26, 2013
London Outskirt...
4,830
like
05/01/13 07:40 AM (12 years ago)
Ok, i think this is now RESOLVED. screenshots in the PDF make it seem like the code for step 6 should replace the code between PRAGMA and //Go to screen with content but, pasting it below this, putting it in place of the existing -(void)go to purchased screen, as per this screen: https://www.dropbox.com/s/six8829yw7yntbc/Screen%20Shot%202013-05-01%20at%2015.34.42.png seems to be all hunky dory :) :)
 
David73
Aspiring developer
Profile
Posts: 66
Reg: Jan 12, 2013
Texas
660
like
07/14/13 07:42 PM (11 years ago)
OK, I have been following this tutorial, but am having a problem. In step 5, I am getting an error at the very beginning. I can't remember the exact terminology, but it basically says I am calling a function that has not been defined. "-(void) disableAds{ .. . " I have put it in the .h file, but apparently that isn't good enough. Any ideas? Dave
 
Uelsimon
Lost but trying
Profile
Posts: 272
Reg: Mar 25, 2012
NYC
4,470
like
08/10/13 12:51 AM (11 years ago)
Is the pdf available anywhere?
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
08/10/13 02:44 PM (11 years ago)
@Uelsimon Maybe if you can figure out new problems you can post the tutorial update. Here is the old: https://copy.com/WZBqxf6WZUNwN7er
 
Uelsimon
Lost but trying
Profile
Posts: 272
Reg: Mar 25, 2012
NYC
4,470
like
08/22/13 12:38 AM (11 years ago)
thanks mysps... will see what happens when I try it. and report back
 
Mike the App Guy
Lost but trying
Profile
Posts: 435
Reg: Sep 19, 2011
Birmingham, Ala...
5,900
like
08/26/13 06:42 PM (11 years ago)
Any updates on this? I'm trying to get the easy in app purchase working
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.