Discussion Forums  >  WebViews and HTML for Mobile

Replies: 9    Views: 448

juk
Aspiring developer
Profile
Posts: 29
Reg: Feb 16, 2014
York, UK
890
04/12/14 04:16 AM (8 years ago)

Custom HTML with Query String (Locally)

Hi all. Just a quick question which I can't seem to find the answer to... I would like to pass a query string to a local Custom HTML file (basically so that I can pass merge fields to be processed by some Javascript included in the HTML file). For example, I have a Custom HTML screen with Document Location set as follows: File Name in Project: test.htm?page=12&post=M123 I get an error, "Data for this screen has not been downloaded". However, I've also set an equivalent screen up without the query string and it loads fine - i.e. the HTML file is available in the app. So the "localFileName" doesn't seem to accept filename plus query string? Any suggestions/alternatives please?
 
juk
Aspiring developer
Profile
Posts: 29
Reg: Feb 16, 2014
York, UK
890
like
04/12/14 05:44 AM (8 years ago)
By the way, I know the conventional thing to do is pass the merge fields to a hosted PHP file, but that's not what I want to do. The HTML file accepts the query string when run locally on my computer. There must be some way to do this... I suspect the Custom HTML plugin does something weird with the ? = and & in the URL and thinks it's just one big file name which it can't find. I reckon it might take a modification to the "BT_screen_htmlDoc.m", but that's a bit out of my comfort zone... Thanks, James.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
Fourm StarFourm StarFourm Star
like
04/12/14 06:50 AM (8 years ago)
An alternative is to add variables in your file like so: var myProperty = "%@"; Then load the entire file into an NSString. Then load that string into a new string using the stringWithFormat method, adding NSString objects for each %@ in your file. Then load that new string into the web view.
 
juk
Aspiring developer
Profile
Posts: 29
Reg: Feb 16, 2014
York, UK
890
like
04/13/14 09:49 AM (8 years ago)
Thanks for the reply Chris. Kind of makes sense but that's all pretty new to me...will give it a go but if anyone knows of another way using Buzztouch functionality then feel free to chip in!
 
Niraj Shah
buzztouch Evangelist
Profile
Posts: 2942
Reg: Jul 11, 2012
Cerritos
37,920
Fourm StarFourm Star
like
04/13/14 10:29 AM (8 years ago)
Start with the Custom URL Scheme, look in the How-To section of this web site. In Section 2.2.2 of that document, add into it the Query parts. Use this page to help get the right syntax: http://www.idev101.com/code/Objective-C/custom_url_schemes.html Next you will have to pass the Query string to the HTML Doc plugin. One way to pass information from screen to screen is to use NSUserDefaults. Look for "NSUserDefaults" in your Xcode project. Within the non-plugin section, you will see two methods for saving values to NSUserDefaults and reading values from NSUserDefaults. (I forget the names of those methods, not currently at a computer) Invoke the "Save To NSUserDefaults" method as part of your extension of Section 2.2.2 --------------- Ignore Section 2.2.3 of the document. BT has done that already for you. And made it better! --------------- Modify the HTML Doc plugin to fetch the query string from NSUserDefaults. Then modify that plugin to pass the Query string from ObjC over to HTML/JavaScript. ---------------- Let us know how you solve it! When you get it solved, we can improve the plugins accordingly. -- Niraj
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
Fourm StarFourm StarFourm Star
like
04/13/14 12:15 PM (8 years ago)
Note: if you check out my Match 3 plugin, you can see an example of how to do what I'm talking about. Shouldn't need to mess with NSUserDefaults.
 
juk
Aspiring developer
Profile
Posts: 29
Reg: Feb 16, 2014
York, UK
890
like
04/15/14 01:20 PM (8 years ago)
Guys, sorry I've not had chance to reply. I'm working on this so thank you for your advice - it wasn't wasted effort as I am using it.
 
Niraj Shah
buzztouch Evangelist
Profile
Posts: 2942
Reg: Jul 11, 2012
Cerritos
37,920
Fourm StarFourm Star
like
04/15/14 08:37 PM (8 years ago)
Hey there James in UK, did ya figure it out? You will learn loads in tackling this one!
 
juk
Aspiring developer
Profile
Posts: 29
Reg: Feb 16, 2014
York, UK
890
like
04/16/14 11:32 AM (8 years ago)
Hi Niraj. Thanks for checking. I've not cracked it yet, but I feel kind of close! Not sure if this is the recommended approach but I've actually ended up duplicating the HTML Doc plugin and I've been trying to append a query string to the URL which opens in the web view. Something like this... http://stackoverflow.com/questions/1226363/send-parameters-to-a-local-file-in-a-uiwebview But it doesn't seem to be working yet. I feel like I'm on the verge of a breakthrough though?!
 
Niraj Shah
buzztouch Evangelist
Profile
Posts: 2942
Reg: Jul 11, 2012
Cerritos
37,920
Fourm StarFourm Star
like
04/16/14 07:31 PM (8 years ago)
Keep at it ... You will get there! :-)
 

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.