Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 14    Views: 88

AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
06/17/12 07:01 AM (13 years ago)

Use shake to launch a specific page

I am using IOS and buzztouch 2.0. I would like to be able show a specific page when the user shakes the phone, from wherever they are in the app. I have created a Custom HTML / Text page and I have managed to implement the objective C shake code, which I found in the forum http://www.buzztouch.com/forum/thread.php?tid=C075D70763120E5C03C765F This code implements a 'back-button' type functionality, which works. The problem is I cannot figure out what I need to do to replace that with a link to my custom html page in the objective C shake code. Can anyone guide me please?
 
Stobe
buzztouch Evangelist
Profile
Posts: 1528
Reg: Mar 04, 2011
Fredericksburg,...
24,680
like
06/17/12 11:46 AM (13 years ago)
I'm not familiar with the specifics of 2.0, but in 1.5 there is a method called "handleTapToLoadScreen" found in the viewControllerManager (if I remember right). That's what you'd want the shake code to "fire". Then you'd tell it what screen to load by either using a itemID, nickname, or object.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
06/19/12 08:54 AM (13 years ago)
Thanks for your help Stobe, I am sure you pointed me in the right direction. I seem to have hit my next hurdle and being fairly clueless when it comes to objective C, I am not sure what I am doing wrong (but it feels as if I am close). I wanted to display a screen (called Events-HTML in my control panel). So I inserted the following line of code in the right place, but it crashes the app. My guess is it must be syntax, but I don't know what I've done wrong. The offending line of code is :- [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:NULL:"Events-HTML"]; My log extract may help somebody who speaks the language - 012-06-19 16:33:39.597 limepub[11227:307] Shake - the device is shaking... 2012-06-19 16:33:39.609 limepub[11227:307] -[limepub_appDelegate screenData]: unrecognized selector sent to instance 0x2118b0 2012-06-19 16:33:39.645 limepub[11227:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[limepub_appDelegate screenData]: unrecognized selector sent to instance 0x2118b0' Any idea's anyone ?.
 
Stobe
buzztouch Evangelist
Profile
Posts: 1528
Reg: Mar 04, 2011
Fredericksburg,...
24,680
like
06/19/12 09:31 AM (13 years ago)
yes, I think that line you pasted is not correct syntax. I'm not sure about the "NULL", I believe I have used "nil" in the past. And "Events-HTML" has to be declared and created before that statement. Do you have any lines above that where that variable is declared by its nickname?
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
06/19/12 10:28 AM (13 years ago)
My entire routine (with the handleTapToLoadScreen commented out to prevent crashing) is as follows :- // Start of Shake detection // Add a method like this to 'listen' for the events... - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{ double myThreshold = 1.8; if (fabsf(acceleration.x) > myThreshold || fabsf(acceleration.y) > myThreshold || fabsf(acceleration.z) > myThreshold) { NSLog(@"Shake - the device is shaking..."); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"LimePub" message:@"This is a test - we are shaking" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; //BT_viewControllerManager will launch the next screen // [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:NULL:"Events-HTML"]; [alert show]; [alert release]; } } // End of Shake detection The alert is visual debug to be removed later. btw, I also have 2 warnings on this line :- 1) - Incompatible pointer types sending the 'char(12) to parameter of type 'BT_item" and 2) - Instance method '_screenDAta' not found (return type defaults to 'id') I really appreciate your help here Stobe. Part of my reason for getting "shake to show a page" is to provide a phone related feature so the apple store doesn't reject the app, which they have done once to one of my other apps in the past.
 
Stobe
buzztouch Evangelist
Profile
Posts: 1528
Reg: Mar 04, 2011
Fredericksburg,...
24,680
like
06/19/12 10:58 AM (13 years ago)
I'm not an expert at this, and you may need to eventually visit the "mountain". But instead of using "Events-HTML" as your third parameter in your handleTap method, try something like this: This comes from v1.5, so you might have to do some reverse engineering. But if your app already has the handleTapToLoadScreen function in the viewCoontrollerManager, then you just need to give it the correct info first. This is going to be lengthy, but there are 2 or 3 lines in here that you can copy/paste into your app to probably make it work (don't you just love that word "probably") Here we go.... -(void)headerImageTap{ [BT_debugger showIt:self:@"headerImageTap"]; //appDelegate finning_appDelegate *appDelegate = (finning_appDelegate *)[[UIApplication sharedApplication] delegate]; //get possible itemId of the screen to load NSString *loadScreenItemId = [BT_strings getJsonPropertyValue:screenData.jsonVars:@"headerImageTapLoadScreenItemId":@""]; //get possible nickname of the screen to load NSString *loadScreenNickname = [BT_strings getJsonPropertyValue:screenData.jsonVars:@"headerImageTapLoadScreenNickname":@""]; //bail if load screen = "none" if([loadScreenItemId isEqualToString:@"none"]){ return; } //check for loadScreenWithItemId THEN loadScreenWithNickname THEN loadScreenObject BT_item *screenObjectToLoad = nil; if([loadScreenItemId length] > 1){ screenObjectToLoad = [appDelegate.rootApp getScreenDataByItemId:loadScreenItemId]; }else{ if([loadScreenNickname length] > 1){ screenObjectToLoad = [appDelegate.rootApp getScreenDataByNickname:loadScreenNickname]; }else{ if([screenData.jsonVars objectForKey:@"headerImageTapLoadScreenObject"]){ screenObjectToLoad = [[BT_item alloc] init]; [screenObjectToLoad setItemId:[[screenData.jsonVars objectForKey:@"headerImageTapLoadScreenObject"] objectForKey:@"itemId"]]; [screenObjectToLoad setItemNickname:[[screenData.jsonVars objectForKey:@"headerImageTapLoadScreenObject"] objectForKey:@"itemNickname"]]; [screenObjectToLoad setItemType:[[screenData.jsonVars objectForKey:@"headerImageTapLoadScreenObject"] objectForKey:@"itemType"]]; [screenObjectToLoad setJsonVars:[screenData.jsonVars objectForKey:@"headerImageTapLoadScreenObject"]]; } } } //load next screen if it's not nil if(screenObjectToLoad != nil){ //build a temp menu-item to pass to screen load method. We need this because the transition type is in the menu-item BT_item *tmpMenuItem = [[BT_item alloc] init]; //build an NSDictionary of values for the jsonVars property NSDictionary *tmpDictionary = [NSDictionary dictionaryWithObjectsAndKeys: @"unused", @"itemId", [self.screenData.jsonVars objectForKey:@"headerImageTapLoadScreenTransitionType"], @"transitionType", nil]; [tmpMenuItem setJsonVars:tmpDictionary]; [tmpMenuItem setItemId:@"0"]; //load the next screen [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:tmpMenuItem:screenObjectToLoad]; [tmpMenuItem release]; }else{ //show message [BT_debugger showIt:self:[NSString stringWithFormat:@"%@",NSLocalizedString(@"menuTapError",@"The application doesn't know how to handle this action?")]]; } } ---- ok, look at these lines: ----- //get possible nickname of the screen to load NSString *loadScreenNickname = [BT_strings getJsonPropertyValue:screenData.jsonVars:@"headerImageTapLoadScreenNickname":@""]; screenObjectToLoad = [appDelegate.rootApp getScreenDataByNickname:loadScreenNickname]; [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:tmpMenuItem:screenObjectToLoad]; ----- It looks like you can give it the screen nickname (rather than gather it from the JSON properties) and create the screenObjectToLoad from that. Then use that variable to argument the handleTap function. I wish I could give you a few lines to cut/paste and be done with it. But you may have to just play around with it a little bit. -Stobe
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
06/19/12 11:05 AM (13 years ago)
Thanks Stobe, your help and support is much appreciated. I'll try and get my head around that and give it a go in the morning. Football (England vs Ukraine) beckons...
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
06/20/12 04:37 AM (13 years ago)
I had a go, here is the updated code, with embedded comments. It still crashes the app if the last line is un-commented. My problem is there is a lot I do not know about objective C. But I'm having a go! // Attempt to have BT_viewControllerManager launch screen named "Events-HTML" // Not sure if I need this, so commented out :-tmpMenuItem setItemId:@"0"]; NSString *loadScreenNickname = @"Events-HTML"; // This is the page created in control panel BT_item *screenObjectToLoad = nil; // Found this, seems to be needed limepub_appDelegate *appDelegate = (limepub_appDelegate *)[[UIApplication sharedApplication] delegate]; // this fixed failure on screenObjectToLoad //get object to load from nickname - loadScreeNickname of the screen to load defined earlier screenObjectToLoad = [appDelegate.rootApp getScreenDataByNickname:loadScreenNickname]; // Next line causes crash. Warning on "self screenData", instance method not found, id defaults to zero, no idea what this means or how to get around it // [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:nil:screenObjectToLoad];
 
Stobe
buzztouch Evangelist
Profile
Posts: 1528
Reg: Mar 04, 2011
Fredericksburg,...
24,680
like
06/20/12 04:56 AM (13 years ago)
I'm in the same boat. Still learning.... My first suggestion is to look at the view controller in 2.0 to make sure the methods are named the same. I cut/pasted the above code from a 1.5 view controller, and I know some things have been built/named differently in 2.0 (but I didn't have any code handy to look at). Keep pluggin!
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
06/20/12 06:56 AM (13 years ago)
If you are learning too then I appreciate your help even more; this isn't easy. I've searched through v2.0 and it doesn't look very different. I'm at the point now where I have realised that a NSDIctionary needs to be built. I have added that in, but so far I think doing that incorrectly, which is causing the screen load to fail. Not giving up yet...
 
Stobe
buzztouch Evangelist
Profile
Posts: 1528
Reg: Mar 04, 2011
Fredericksburg,...
24,680
like
06/20/12 07:03 AM (13 years ago)
The dictionary that you found is for creating a dynamic/temporary screen. You could surely do it this way, but you already have a screen, you just need to link to it. The only reason you'd want to do it that way is if you wanted to go to a screen that didn't exist in your configuration. I think you're close... I feel your frustration.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
06/20/12 07:10 AM (13 years ago)
I was going on the theory that I need a tmpMenuItem (some kind of array?)for the handleTaptoLoadScreen statement, but I don't think I am creating that correctly, hence that line crashes.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
06/20/12 07:11 AM (13 years ago)
I was going on the theory that I need a tmpMenuItem (some kind of array?)for the handleTaptoLoadScreen statement, but I don't think I am creating that correctly, hence that line crashes.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
06/21/12 02:10 AM (13 years ago)
handleTapToLoadScreen needs me to prepare three parameters to pass to it:- 1) screenData - The BT_item data object for the screen displaying the menu/button that was tapped 2) tmpMenuData - the BT_item data object for the menu/button that was tapped 3) screenObjectToLoad - the BT_item data object holding the info about screen we want to load / launch. I have 2) and 3) sorted, however I don't understand how to create the first parameter (or quite why I need it). references to "self screenData" throws xcode errors and attempts to use NSDictionary *tmpDictionary = [NSDictionary dictionaryWithObjectsAndKeys: @"unused", @"itemId", [self.screenData.jsonVars objectForKey:@"headerImageTapLoadScreenTransitionType"], @"transitionType", nil]; throws errors. I have tried to move past this temporarily by substituting/reusing the 3rd parameter where screenData goes, just to see what happens. This clears the errors, but xcode doesn't like [self handleTapToLoadScreen:screenObjectToLoad:tmpMenuData:screenObjectToLoad]; The warning is Instance method'-handleTapToLoadScreen:::' not found return type defaults to 'id') I have no idea what this means and I have been going round in circles for hours! If anyone can shed some light on this I would be soooo pleased!
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
12/02/13 01:36 PM (12 years ago)
For anyone looking for this functionality in a plugin: https://www.buzztouch.com/plugins/plugin.php?pid=FAD3221726833083625AFA1 Cheers! David https://buzztouchmods.com/market
 

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.