Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 24    Views: 236

Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
01/18/13 03:16 PM (13 years ago)

how to call viewcontroller.m methods?

I'm working on integrating a new SDK in my app - it isn't quite as user friendly as most SDK's. I was skyping with one of their guys for about an hour yesterday probably doing a terrible job of describing to him what the Buzztouch code looks like. Eventually I had to send him a blank BT project so he could figure it out for me. The documentation simply says to put this code - [ALInterstitialAd showOver:self.view.window]; - wherever I want to show the interstitial. Well as far as I can tell this code does not work anywhere unless it is used in the viewcontroller.m file. His solution was to put the following code block in viewcontroller.m - -(void) viewDidAppear:(BOOL)animated { [ALInterstitialAd showOver:self.view.window]; } that works, but the ad shows wayyy too much. It shows every time a screen is loaded. It's for this reason that I'm trying to figure out my own solution. My thought is to put a method in viewcontroller.m that I can call anytime from the appDelegate or from any of the plugin implementations. Now, since I usually only halfway know what I'm doing it's no surprise that this didn't work. I made this method in view controller.m - -(void)ALInterstitial{ [ALInterstitialAd showOver:self.view.window]; } and then I tried calling it in menuButtons.m viewWillAppear (my home screen) like this - [self ALInterstitial]; the above code autofills which usually makes me think I'm on the right track - it compiles fine but the method in viewcontroller.m doesn't run I took a wild shot after that failed and tried this in menuButtons.m - BT_viewController = theViewController; [theViewController ALInterstitial] that causes the app to immediately crash on launch any ideas?
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
01/18/13 03:35 PM (13 years ago)
Hmm. OK. If you put something in the BT_viewcontroller class all your other plugins are sub classes of that so it will be implemented across the board hence showing WAY to much. What did you add to the menuButtons.h? Did you add the method declaration in there?
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
01/18/13 03:51 PM (13 years ago)
I hadn't originally, but I just now tried that and it didn't seem to work... Isn't that only necessary if the method is inside of the corresponding .m file? - I declared it in viewController.h and implemented it in viewController.m, so I thought that I simply had to reference it from menuButtons.m I assumed this because, for example, the showProgress method definition is in viewController.m - in any of the plugins, if I want to show the loading animation all I have to do is type [self showProgress]; and it runs
 
ceerup
Code is Art
Profile
Posts: 1033
Reg: Oct 10, 2011
New York City
16,380
like
01/18/13 03:54 PM (13 years ago)
if you can call it to show in the viewcontroller.m and go to the subclasses like macapple said, but tell it not to show in those, that should accomplish your goal. i recall that happening with admob on eclipse, but that required different coding.
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
01/18/13 03:57 PM (13 years ago)
OK. Like I said, ignore me right now. When I read the above I thought that since it was referenced in the view controller it is showing in all sub screens. So implementing it only in the .h and .m of the screens you want it to show should in theory work. Or... if you do go via the viewcontroller method tell the screens you don't want it in not to show. My head hurts buddy. I shouldn't have chimed in! Friday yet?
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
01/18/13 04:03 PM (13 years ago)
Haha, well I'm definitely appreciating the help so far That brings me back to my initial problem...it's kind of a mystery (to me at least) -- if I put this code - [ALInterstitialAd showOver:self.view.window]; - in the viewDidLoad/viewWillAppear of any of my .m screens, nothing shows...but if I put that same code in my viewController.m it works fine I think my heads starting to hurt too
 
PSMDanny
Apple Fan
Profile
Posts: 1166
Reg: Dec 09, 2011
Heerlen
21,940
like
01/18/13 04:09 PM (13 years ago)
Hi Absentia, Love to help you out on this. Just had a look at their website but I'm not in the need to create an account. If you want my help send your Xcode project (zip) to info at bt-addons dot com Best Regards, Danny
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
01/18/13 04:12 PM (13 years ago)
Nice one @PSMDanny Can't he just dismiss it on the screens he doesn't want? You are in better hands than mine now @Absentia!
 
ceerup
Code is Art
Profile
Posts: 1033
Reg: Oct 10, 2011
New York City
16,380
like
01/18/13 04:15 PM (13 years ago)
yea he can macapple, it looks like he almost has it right, the -(void) viewDidAppear:(BOOL)animated { [ALInterstitialAd showOver:self.view.window]; } if he put this in other classes like for example an image gallery, it would work
 
PSMDanny
Apple Fan
Profile
Posts: 1166
Reg: Dec 09, 2011
Heerlen
21,940
like
01/18/13 04:44 PM (13 years ago)
Thanks @MacApple: Better say "you are in more hands now" @ceerup: You could be right! But it's hard to tell if I can't see it for myself. As always there are multiple ways that will lead to Rome...... Best Regards, Danny
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
01/18/13 04:45 PM (13 years ago)
@PSMDanny - Love the Rome quote!
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
01/18/13 04:46 PM (13 years ago)
thanks a lot Danny! I sent it your way @ceerup - unfortunately, that doesn't work :(
 
ceerup
Code is Art
Profile
Posts: 1033
Reg: Oct 10, 2011
New York City
16,380
like
01/18/13 04:49 PM (13 years ago)
hmmm. lets see what Danny could find, ill look through the web also and see what i can come up with
 
PSMDanny
Apple Fan
Profile
Posts: 1166
Reg: Dec 09, 2011
Heerlen
21,940
like
01/18/13 04:50 PM (13 years ago)
Ok I'll wait for the package. Best Regards, Danny PS I don't say I have the answer to this but will at least try to help you out.
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
01/18/13 05:25 PM (13 years ago)
did you get it yet? I was having trouble sending the zip using email but I think it finally got through
 
PSMDanny
Apple Fan
Profile
Posts: 1166
Reg: Dec 09, 2011
Heerlen
21,940
like
01/18/13 05:27 PM (13 years ago)
Until now I haven't received anything! Best Regards, Danny
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
01/18/13 05:39 PM (13 years ago)
I sent you a message Danny (on Buzztouch)
 
PSMDanny
Apple Fan
Profile
Posts: 1166
Reg: Dec 09, 2011
Heerlen
21,940
like
01/18/13 06:32 PM (13 years ago)
This is what I've send in an email: Sorry to say I can't use your (downloaded) app. Maybe it has something to do with the xcode version I use (an older one since I'm waiting for a almost a month now I get my new iMac delivered) but it only gives me compiling errors. I tried to get rid of the errors but wasn't successfull in removing them. Maybe I'll sign up for an account at the framework in a couple of days and play with it myself. I'll let you know the results. Best Regards, Danny
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
01/18/13 07:16 PM (13 years ago)
Ok thanks..ill just keep tinkering in the meantime
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
01/18/13 08:03 PM (13 years ago)
ok I've at least gotten it to only show when the home screen loads by using the old "itemNickname" trick - -(void) viewDidAppear:(BOOL)animated { if ([[BT_strings getStyleValueForScreen:self.screenData:@"itemNickname":@""] isEqualToString:@"Home"]){ [ALInterstitialAd showOver:self.view.window]; } } Ideally I want it to show when the app initially launches and when it re-launches from the background...we'll see
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
01/18/13 08:52 PM (13 years ago)
Which sdk maybe I can take a crack at it too?
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
01/18/13 09:22 PM (13 years ago)
it's called applovin...they're in private beta right now so you need to request access - https://www.applovin.com/index
 
Absentia
buzztouch Evangelist
Profile
Posts: 960
Reg: Oct 20, 2011
Alaska
20,600
like
01/18/13 11:54 PM (13 years ago)
Got it! I've discovered a previously unknown method of doing this by using NSNotification center. I put a notification name in the applicationDidBecmeActive method of the appDelegate.m - [[NSNotificationCenter defaultCenter] postNotificationName:@"interstitial" object:nil]; Then I put an observer for that name in viewcontroller.m - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interstitial) name:@"interstitial" object:nil]; I never was aware of this method of doing things but it works great. It does have a couple of quirks I'm trying to figure out - as long as I stay on the home screen and keep closing the app and relaunching the app the ad will keep showing...which is what I want. For some reason though, when I load another screen from the home screen and then close the app to the background - the adss will stop showing. It's like it only stores the ad for the home screen view. hmm...I'll figure this out
 
PSMDanny
Apple Fan
Profile
Posts: 1166
Reg: Dec 09, 2011
Heerlen
21,940
like
01/19/13 09:20 AM (13 years ago)
Hi Absentia, Great you found a way.....Good luck with the last part and again sorry I couldn't help. (I did, by the way, sign up last night but haven't seen any message from them yet). Best Regards, Danny
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
01/20/13 05:03 PM (13 years ago)
thanks Absentia! i was approved today so I will be able to test it out and report back but most likely you've already figured it out :)
 

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.