Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 8    Views: 43

Bonzo
Apple Fan
Profile
Posts: 783
Reg: Jan 30, 2012
Basingstoke
13,530
09/02/14 10:06 AM (9 years ago)

Do a command depending on screen name?

I know this is probably easy.....but not for me :) i am using a plugin and want to perform an action depending on which version of the screen is loaded. I have my code that works. i just don't know how to control the screen? If screen name = "a" then //Perform my code version a else if screen name = "b" then //Perform my code version b else if screen name = "c" then //Perform my code version c else do nothin and carry on as normal :) I will perform this as the screen loads. Thanks
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
09/02/14 10:43 AM (9 years ago)
use the screenNickname property: **Objective-C** NSString *screenNickname = self.screenData.itemNickname; if ([screenNickname isEqualToString:@"Screen A"] { //do something } **JAVA** String screenNickname = screenData.getItemNickname(); if (screenNickname.equalsIgnoreCase("Screen A") { //do something }
 
Bonzo
Apple Fan
Profile
Posts: 783
Reg: Jan 30, 2012
Basingstoke
13,530
like
09/02/14 10:58 AM (9 years ago)
Perfect! I'll give it ago, thanks! On the same subject, is it possible to find out which screen it's come from? So as a screen closes you write the nickname to a variable and then when the new screen opens you check where it came from and decide whether to perform an action or not? Basically if you are going 'forward' in your app, do the action, but if someone is navigating backwards, you don't perform it. Thanks
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
09/02/14 11:06 AM (9 years ago)
Would be easier to tell if you're coming back from *something* rather than from a particular screen. Look at how the menu simple plugin uses the didInit flag. Otherwise you're looking at hacking up the core a bit.
 
Bonzo
Apple Fan
Profile
Posts: 783
Reg: Jan 30, 2012
Basingstoke
13,530
like
09/02/14 01:09 PM (9 years ago)
Chris, Thanks for the help so far. Ive created my whole app using your screen creator plugin. took a while for me to get my head around it but now its unbelievably awesome! Using your above code I'm manage to implement this: NSString *screenNickname = self.screenData.itemNickname; if ([screenNickname isEqualToString:@"Page 3"]) { [BT_debugger showIt:self message:@"Play Page 3"]; NSString *path = [NSString stringWithFormat:@"%@/main.mp3", [[NSBundle mainBundle] resourcePath]]; NSURL *soundUrl = [NSURL fileURLWithPath:path]; // Create audio player object and initialize with URL to sound _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil]; [_audioPlayer play]; } if ([screenNickname isEqualToString:@"Option 1"]) { [BT_debugger showIt:self message:@"Play Option 1"]; NSString *path = [NSString stringWithFormat:@"%@/option1.mp3", [[NSBundle mainBundle] resourcePath]]; NSURL *soundUrl = [NSURL fileURLWithPath:path]; // Create audio player object and initialize with URL to sound _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil]; [_audioPlayer play]; } if ([screenNickname isEqualToString:@"Option 2"]) { [BT_debugger showIt:self message:@"Play Option 2"]; NSString *path = [NSString stringWithFormat:@"%@/option2.mp3", [[NSBundle mainBundle] resourcePath]]; NSURL *soundUrl = [NSURL fileURLWithPath:path]; // Create audio player object and initialize with URL to sound _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil]; [_audioPlayer play]; } This works perfect, playing 3 different audio files depending on which screen i am loading. Ive also added this right at the bottom of the .m: - (void)viewWillDisappear:(BOOL)animated{ [BT_debugger showIt:self message:@"Hitting my code!"]; [_audioPlayer stop]; } this stops the audio if someone clicks a forward and/or back button. This is where my question comes: Do you know if i can hide a button that i have put on the screen until the audio finishes? i don't mind the back button being there, but would rather hide the 'next' until the audio completes many thanks in advance STeve
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
09/02/14 01:13 PM (9 years ago)
You need to assign the plugin as a delegate to each AVAudioPlayer you create so you can detect when it is finished playing.
 
Bonzo
Apple Fan
Profile
Posts: 783
Reg: Jan 30, 2012
Basingstoke
13,530
like
09/02/14 01:16 PM (9 years ago)
if only that meant something to me :) I've been a lucky copy and paster so far i might be able to find how to manage whether the audio has finished but hiding and unhiding a button on your plugin google won't help me with :)
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
09/02/14 01:22 PM (9 years ago)
lol, well frankly this would be a GREAT way to learn how iOS works. Research how to implement a delegate method and how to hide an object. It's something that will take you about 45 seconds to write the actual code, but will teach you a lot in the process of learning.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
09/02/14 06:49 PM (9 years ago)
I haven't used it before, but there is a BT_item called 'previousScreenData' that might have the information you want. It's found in the BT_application.h/.m files... Cheers! -- Smug
 

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.