Discussion Forums  >  Uncategorized

Replies: 12    Views: 308

Going-Viral
Apple Fan
Profile
Posts: 120
Reg: Jun 13, 2011
Doncaster
1,200
10/05/11 12:22 PM (14 years ago)

HTML DOC - HTML Link to switch screen???

Is it possible to code a html link within an HTML DOC (internal to the app) that opens the email function, text or call functions that have already been declared in the app?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
10/05/11 11:28 PM (14 years ago)
You can do this but it's a bit nerdy. The idea is that you can trigger an Objective C method from your html click event. Have a look at this: http://tetontech.wordpress.com/2008/08/14/calling-objective-c-from-javascript-in-an-iphone-uiwebview/ The challenge for most folks is that they don't understand what buzztouch method to trigger when the click something. After getting your own method firing from your click (using the tips in that article), have a look at the BT_viewControllerManager.m file in your Xcode project. It's in the BT_Layout folder. You'll want to trigger two methods. First, you'll need instantiate a new screen object from your list of screens using the initViewControllerForScreen method. Then, you'll need to pass this screen object to handleTapToLoadScreen method.
 
Going-Viral
Apple Fan
Profile
Posts: 120
Reg: Jun 13, 2011
Doncaster
1,200
like
10/06/11 02:29 AM (14 years ago)
Sounds like I have my work cut out. I'm finally going on an iOS Developer cause in 2 weeks, lets hope to God, it all becomes a little more clearer, I hope I can then help you guys out a little more :-)
 
Going-Viral
Apple Fan
Profile
Posts: 120
Reg: Jun 13, 2011
Doncaster
1,200
like
10/10/11 08:46 AM (14 years ago)
Hi David, am I right in saying I don't need to add the QuickConnectiPhone Framework as the UIWebView the article refers to as it seems to be part of the UIKit.framework.
 
Going-Viral
Apple Fan
Profile
Posts: 120
Reg: Jun 13, 2011
Doncaster
1,200
like
10/24/11 07:07 AM (14 years ago)
Scratch my previous comment, I've figured out how to capture the URL schema and host to determine a custom set of interactions, onto the next bit and I'll post as soon as I've got things working tomorrow.
 
Going-Viral
Apple Fan
Profile
Posts: 120
Reg: Jun 13, 2011
Doncaster
1,200
like
10/25/11 02:46 AM (14 years ago)
Hi David, despite my course I'm still struggling. I have the following code in my HTML DOC file: <a href=click://contact style=color:#376372>here</a> I have the following code on the method -(BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType: if (navigationType == UIWebViewNavigationTypeLinkClicked) { if ([[url scheme] isEqualToString:@click]) { // Write to Log if click has been received NSLog(@A url has been clicked %@, url); if ([request.URL.host isEqualToString:@contact]) { // Navigate to Contacts screen NSLog(@Open Contact interface.); } } return NO; } else { return YES; } I have added the following code to BT_screen_webView.m: +(id)initViewControllerForScreen:(BT_item *)theScreen{ if([theScreen itemId] == nil){ [BT_debugger showIt:self:[NSString stringWithFormat:@initViewControllerForScreen: ERROR finding screen with itemId: %@, [theScreen itemId]]]; }else{ if([theScreen.itemNickname length] > 1){ [BT_debugger showIt:self:[NSString stringWithFormat:@initViewControllerForScreen nickname: \%@\ itemId: %@ type: %@, [theScreen itemNickname], [theScreen itemId], [theScreen itemType]]]; }else{ [BT_debugger showIt:self:[NSString stringWithFormat:@initViewControllerForScreen nickname: \%@\ itemId: %@ type: %@, @no nickname?, [theScreen itemId], [theScreen itemType]]]; } } Instantiate a view controller with ClassName == BT_item.itemType. If the itemType is a custom plug-in we need to get the type of view controller to allocate from the JSON data... */ //return this view controller. NSObject *theViewController = nil; NSString *theClassName = [theScreen itemType]; //are we loading a custom plugin? if([[theScreen itemType] isEqualToString:@BT_screen_plugIn]){ //get the class name of the custom UIViewController we want to load... theClassName = [BT_strings getJsonPropertyValue:theScreen.jsonVars:@classFileName:@]; } //screenType required if([theClassName length] > 0){ Class theClass = NSClassFromString(theClassName); if(theClass != nil){ if([theClass respondsToSelector:@selector(alloc)]){ theViewController = [[theClass performSelector:@selector(alloc)] initWithScreenData:theScreen]; return theViewController; } } }//screenType length if(theViewController == nil){ [BT_debugger showIt:self:[NSString stringWithFormat:@initViewControllerForScreen: ERROR, could not initialize view controller for screen with itemId: %@, [theScreen itemId]]]; } //should not be here. return theViewController; } But I'm a little unsure how I pass the values of the BT_config.txt (itemNickname:Contact Us, itemId:71648251F9A736205A9C8C8) to the above method which in turn should be triggered by the handleTapToLoadScreen method, any help would be much appreciated.
 
Going-Viral
Apple Fan
Profile
Posts: 120
Reg: Jun 13, 2011
Doncaster
1,200
like
10/25/11 05:39 AM (14 years ago)
I've got a little further, I've copied the the handleTapToLoadScreen method and now my link is now opening a new View Controller but the title is showing Screen not found, any thoughts. Here is my amended code for the theWebView shouldStartLoadWithRequest method, if this makes things a little clearer: if (navigationType == UIWebViewNavigationTypeLinkClicked) { if ([[url scheme] isEqualToString:@click]) { // Write to Log if click has been received NSLog(@A url has been clicked %@, url); if ([request.URL.host isEqualToString:@contact]) { // Navigate to Contacts screen NSLog(@Attempts to open Contact interface.); BT_item *screenObjectToLoad = nil; BT_item *tmpMenuItem = [[BT_item alloc] init]; [tmpMenuItem setItemId:@71648251F9A736205A9C8C8]; [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:tmpMenuItem:screenObjectToLoad]; NSLog(@ScreenObjectToLoad is: %@, screenObjectToLoad); NSLog(@tmpMenuItem is: %@, tmpMenuItem); } } return NO; } else { return YES; } Can't see wood for the trees comes to mind :-)
 
Going-Viral
Apple Fan
Profile
Posts: 120
Reg: Jun 13, 2011
Doncaster
1,200
like
11/13/11 01:54 AM (14 years ago)
I'm still no further forward this messing with my noodle, any help would be much appreciated :-)
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
11/13/11 03:29 AM (14 years ago)
Ah... I been awhile. Have a look at your post...the screenObjectToLoad variable is set to nil to start. Next, a menu item object is created. Then the handleTapToLoadScreen method is called. That method takes three parameters. Some folks call these arguments. It takes a screen object for the current screen the buttons on, it takes a menu item object, and it takes a screen object. You'r passing it the first two, but the third is a nil screen object. Remember, we set it to nil a few lines above. Ironically, you can send nil as the menu item but not the screen item. This just means you need to create a new screen object to load. You can do this a few ways. Forum may break syntax: To create a screen object using the ID from the BT_config.txt file.... BT_item *myNewScreenObject = [yourAppDelegate.rootApp getScreenDataByItemId:the id of the screen you want from your list in BT_config.txt] To create a screen object using the nickname from the BT_config.txt file.... BT_item *myNewScreenObject = [yourAppDelegate.rootApp getScreenDataByNickname:the nickname of the screen you want from your list in BT_config.txt] OR...like you did with the menu item above, you can create it manually... BT_item *myNewScreenObject = [[BT_item alloc] init]; [myNewScreenObject setItemId:@12345]; [myNewScreenObject setItemType:BT_screen_webView]; The itemType of the screen you create is the name of the UIViewController class you want to load. BT_screen_webView, BT_screen_map, BT_screen_quiz, etc. Or, of course you can load your own class to. See if you can get it with this new info.
 
Going-Viral
Apple Fan
Profile
Posts: 120
Reg: Jun 13, 2011
Doncaster
1,200
like
11/13/11 05:02 AM (14 years ago)
It has indeed been a while, in your absence, I stripped back all previous code to start again: NSURL *url = request.URL; NSString *urlString = [url absoluteString]; NSString *urlScheme = [url scheme]; [BT_debugger showIt:self:[NSString stringWithFormat:@shouldStartLoadWithRequest: URL: %@, urlString]]; [BT_debugger showIt:self:[NSString stringWithFormat:@shouldStartLoadWithRequest: SCHEME: %@, urlScheme]]; if (navigationType == UIWebViewNavigationTypeLinkClicked) { if ([[url scheme] isEqualToString:@click]) { // Write to Log if click has been received NSLog(@A url has been clicked %@, url); if ([request.URL.host isEqualToString:@contact]) { // Navigate to Contacts screen NSLog(@Attempts to open Contact interface.); //BT_item *screenObjectToLoad = nil; BT_item *tmpMenuItem = [[BT_item alloc] init]; [tmpMenuItem setItemId:@Contact Us]; BT_item *itemNickname = [[BT_item alloc] init]; [itemNickname setItemId:@Contact Us]; BT_item *screenObjectToLoad = [[BT_item alloc] init]; [screenObjectToLoad setItemId:@71648251F9A736205A9C8C8]; screenObjectToLoad = [[BT_item alloc] init]; [screenObjectToLoad setItemId:@71648251F9A736205A9C8C8]; [screenObjectToLoad setItemNickname:@Contact Us]; [screenObjectToLoad setItemType:@BT_screen_menuList]; [screenObjectToLoad setJsonVars:0]; [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:tmpMenuItem:screenObjectToLoad]; NSLog(@ScreenObjectToLoad is: %@, screenObjectToLoad); NSLog(@tmpMenuItem is: %@, tmpMenuItem); } } return NO; } else { return YES; } I now get a blank screen appear with a back button, but no contents on screen, I'm not sure if thats better than an error LOL. I have copied the output console to show what is happening: 2011-11-13 11:48:12.575 tangled[250:207] BT_screen_webView: shouldStartLoadWithRequest: URL: click://contact 2011-11-13 11:48:12.575 tangled[250:207] BT_screen_webView: shouldStartLoadWithRequest: SCHEME: click 2011-11-13 11:48:12.575 tangled[250:207] A url has been clicked click://contact 2011-11-13 11:48:12.576 tangled[250:207] Attempts to open Contact interface. 2011-11-13 11:48:12.579 tangled[250:207] BT_viewControllerManager: handleTapToLoadScreen 2011-11-13 11:48:12.579 tangled[250:207] BT_viewControllerManager: the parent screen nickname: Services itemId: CA60B6C0070C12D831B30EC itemType: BT_screen_webView 2011-11-13 11:48:12.579 tangled[250:207] BT_viewControllerManager: the menu/button tapped is itemId: Contact Us 2011-11-13 11:48:12.580 tangled[250:207] BT_viewControllerManager: the screen to load is nickname: Contact Us itemId: 71648251F9A736205A9C8C8 itemType: BT_screen_menuList 2011-11-13 11:48:12.580 tangled[250:207] BT_viewControllerManager: initViewControllerForScreen nickname: Contact Us itemId: 71648251F9A736205A9C8C8 type: BT_screen_menuList 2011-11-13 11:48:12.581 tangled[250:207] BT_screen_menuList: INIT 2011-11-13 11:48:12.582 tangled[250:207] BT_viewUtilities: setting nav-bar background for (null) color: #000000 2011-11-13 11:48:12.582 tangled[250:207] BT_rotatingNavController: pushViewController for screen: 71648251F9A736205A9C8C8 2011-11-13 11:48:12.583 tangled[250:207] BT_screen_menuList: viewDidLoad 2011-11-13 11:48:12.584 tangled[250:207] BT_viewUtilities: getTableViewForScreen with nickname: no nickname? and itemId: (null) and type: (null) 2011-11-13 11:48:12.585 tangled[250:207] BT_screen_menuList: viewWillAppear 2011-11-13 11:48:12.585 tangled[250:207] BT_viewUtilities: configureBackgroundAndNavBar for screen with nickname: no nickname? and itemId: (null) and type: (null) 2011-11-13 11:48:12.589 tangled[250:207] BT_fileManager: File does exist in Xcode bundle: blank.png 2011-11-13 11:48:12.590 tangled[250:207] BT_background_view: Image for background view exists in Xcode bundle - not downloading. 2011-11-13 11:48:12.590 tangled[250:207] BT_background_view: setImage 2011-11-13 11:48:12.592 tangled[250:207] ScreenObjectToLoad is: <BT_item: 0x87dc930> 2011-11-13 11:48:12.592 tangled[250:207] tmpMenuItem is: <BT_item: 0x8771b10> 2011-11-13 11:48:12.694 tangled[250:207] BT_screen_menuList: loadData 2011-11-13 11:48:12.695 tangled[250:207] BT_screen_menuList: using menu items from the screens configuration data. 2011-11-13 11:48:12.695 tangled[250:207] BT_screen_menuList: layoutScreen 2011-11-13 11:48:12.695 tangled[250:207] BT_screen_menuList: This menu has no list items? Is this making any sense?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
11/14/11 01:35 AM (14 years ago)
It's making sense and you're super close. The JSON data property of the screen object you create with code needs to be filled. The type of data you use depends on the screen type you're loading. In this case, you're trying to load a menu list without any child-items. Have a look at the last few lines of the console message you posted, it shows you that 'this menu has no list items' Look at the docs, each screen type has an expected type of JSON data. The best way to do this is to define this in your BT_config.txt file then use the getScreenDataByItemId. You could see the other screen types in the BT_config.txt file to see how the JSON data looks for each type of screen.
 
Going-Viral
Apple Fan
Profile
Posts: 120
Reg: Jun 13, 2011
Doncaster
1,200
like
11/15/11 02:45 PM (14 years ago)
Hi David, thank you for your patience. Does the JSON data need to be added manually to BT_screen_webView.m, what i'm struggling to determine is that the BT_config.txt file stores all the JSON and is merely referenced by id, nickname, etc... with various code passing and parsing the data accordingly. I noticed that I have set [screenObjectToLoad setJsonVars:0]; should I have passed something link NSDictionary *tmpDictionary at this point? I keep banging my head against a brick wall, arrggh!!
 
Going-Viral
Apple Fan
Profile
Posts: 120
Reg: Jun 13, 2011
Doncaster
1,200
like
11/17/11 02:38 PM (14 years ago)
I'm desperate to find a conclusion to this puzzle, any help would be much appreciated :-)
 

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.