Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 10    Views: 93

Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
07/23/12 05:22 PM (13 years ago)

coding help needed

I am going to whip up a very rough version of what I am trying to accomplish in Xcode - I'd really appreciate if any of you coding gurus could fill in the blanks with actual code I am going to use a random blank screen to call an ad that links to a random game in the app store - what I want to get is a message that says "launch app store?" with yes/no options. So it will go kind of like this - ViewDidLoad{ -show message that says "launch app store?" if (Yes) {[RevMobAds openAdLinkWithAppID:@"4f47e9ed5a804002a012f3c"];} if (No) -returnToMainMenu So basically if the user taps yes than the ad will run, and if they tap no the ad won't run and they will be returned to the home screen. Is this doable?
 
XboxMods
buzztouch Evangelist
Profile
Posts: 718
Reg: Oct 28, 2011
location unknow...
12,080
like
07/23/12 05:28 PM (13 years ago)
Are you talking about pop up ads- like when app starts up, a game banner will pop up, users clicks on it, ad takes its place and loads the app in App Store or users clicks X and ad disappears and app loads normally? Are you trying to accomplish something like this? Raoul FreeAppMonster.com
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
07/23/12 05:34 PM (13 years ago)
No it will actually be after the app has loaded - on the main menu screen, there will be an option that says "More Games". When the user taps on that menu option is when I want the ad to run
 
XboxMods
buzztouch Evangelist
Profile
Posts: 718
Reg: Oct 28, 2011
location unknow...
12,080
like
07/23/12 05:45 PM (13 years ago)
That is possible, but would require more code then the way I stated, what service are you planning to use? I encountered this a few months ago and went with the service TapJoy, the only downside of using this is they ONLY pay you after you reach a minimum payment of $250, so that will take some time unless your app is a major hit! Raoul FreeAppMonster.com
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
07/23/12 11:12 PM (13 years ago)
Or....just use a UIActionSheet to "slide up" some options. This is the default way of offering an iOS user a list of choices, like "delete draft" or "save draft" in the native email client. Lots of apps use this and it's sort-of the expected behavior (from a users perspective). English code: a) In viewWillAppear method, UIViewControllers shows the UIActionSheet b) User selects one of the options (it can have a few options) c) Code intercepts which button was clicked (button 0, 1, 2, 3, etc) then acts accordingly. Pseudo code: a) In the .h file of your class, add the UIActionSheetDelegate protocol to the class definition. Like in the BT_screen_map class, it looks like this (at the start of the class): @interface BT_screen_map : BT_viewController <BT_downloadFileDelegate, MKMapViewDelegate, MKReverseGeocoderDelegate, UIActionSheetDelegate> See the "UIActionSheetDelegate" in between the <> Add this to your classes .h file b) Still in the .h class, add the method declaration that tells the compiler that you will be using this method in the .m file (we'll get to the .m in a minute): -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex; Adding that to the .h file (with the other method declarations) tells the compiler to look for this method in the .m. And, because you said "hey iOS, this class adheres to the UIActionSheetDelegateMethod, you need to create this method. You told iOS you going to use it so you have to c) Close the .h and open the .m. Create the method you described in the .h -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { [BT_debugger showIt:self:[NSString stringWithFormat:@"actionSheet:clickedButtonAtIndex %@", @""]]; //button 0 if(buttonIndex == 0){ //do something when button zero is tapped } //button 1 if(buttonIndex == 1){ //do something when button one is tapped } //etc, etc, The number of buttons is up to you, our example will show two, one being the cancel button. If you want more, you'll need to pass an array of buttons to the UIActionSheet alloc method. } d) Still in the .m file, in the viewWillAppear method, setup and show the actual UIActionSheet with two buttons, "Do something" and "cancel" Be sure to replace "your app delegate name" with the app delegate name from your app. //setup an action sheet UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Please make a choice" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Do Something", nil]; [actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque]; //appDelegate your app delegate name *appDelegate = (your app delegate name *)[[UIApplication sharedApplication] delegate]; //is this a tabbed app? if([appDelegate.rootApp.tabs count] > 0){ [actionSheet showFromTabBar:[appDelegate.rootApp.rootTabBarController tabBar]]; }else{ if(self.mapToolbar != nil){ [actionSheet showFromToolbar:self.mapToolbar]; }else{ [actionSheet showInView:[self view]]; } } [actionSheet release]; That should do it. When the screen loads, the viewWillAppear method will show the UIActionSheet. When the user taps a button (on the sheet that slides up), the clickedButtonAtIndex method will fire. Use the debugger to see which button was tapped, add your code to button zero or one.
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
07/24/12 06:34 AM (13 years ago)
Wow. Awesome. Thanks David! I just started playing with Action Sheets and was having some success. I bet there is some key stuff in that post to digest that will help even more. many thanks!
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
07/24/12 10:14 AM (13 years ago)
Wow thanks David - that was way extremely informative. I followed your post exactly and got it working perfectly. I do have one question still - I want the result to a "No" selection to be the user being taken back to the menu screen. Is there a simple way to do this? //button 1 if(buttonIndex == 1){Takes the user back to menu list screen}
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
07/24/12 10:56 AM (13 years ago)
Nevermind I just copy-and-pasted this code from the ViewControllerManager.m and it worked great - //button 1 if(buttonIndex == 1) { //appDelegate remebers the screen we are unloading. onedirectionfanclubv2_appDelegate *appDelegate = (onedirectionfanclubv2_appDelegate *) [[UIApplication sharedApplication] delegate]; BT_item *previousScreenData = [appDelegate.rootApp previousScreenData]; //nav controller depends on layout BT_rotatingNavController *theNavController; if([appDelegate.rootApp.tabs count] > 0){ theNavController = (BT_rotatingNavController *)[appDelegate.rootApp.rootTabBarController selectedViewController]; }else{ theNavController = [appDelegate.rootApp rootNavController]; } //change this view controllers navigation bar background-color "back" to the value set in the "previous screen" [theNavController.navigationBar setTintColor:[BT_viewUtilities getNavBarBackgroundColorForScreen:previousScreenData]]; //our custom navigation controller has over-riden the popViewControllerAnimated method. It refers to the menu item that //was "remembered" in the rootApp when it was tapped. It uses this info to determine how to "reverse" the transition. [theNavController popViewControllerAnimated:YES];} }
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
07/24/12 09:47 PM (13 years ago)
Ok I thought I had everything figured out, but I am left with one last question - how do you get the "no" option to show on the iPad? The code you gave works perfectly on the iPhone, but for some reason when I launch it on an iPad it only shows "yes" as an option.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
07/24/12 09:50 PM (13 years ago)
@Absentia "No" doesn't exist on the iPad UIActionSheet. Modal Views (like the action sheet) are dismissed by tapping "anywhere" on the iPad. Common question. And, I struggled with it a few years ago and finally laughed when I figured it out. Crazy. Of course you could always add an additional button that reads "no" then capture that tap (button index 2, 3, whatever) then dismis the view then. Apple may not like this but you could try ?
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
07/24/12 10:38 PM (13 years ago)
Oh ok, well as long as Apple is fine with it I guess it works for me
 

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.