NimbleKit - fast iOS app development

If (iPad) then { insert HTML file }?

Anything about NimbleKit SDK

If (iPad) then { insert HTML file }?

Postby bnlv » Sat Jul 23, 2011 4:28 am

Perhaps a silly question, but I couldn't find it answered in the forums here and HTML5 suggestions via Google didn't work for me. The scenario is... I have a single page servicing iPad and iPhone, but displaying different external (in the app) HTML files. Instead of having to do document.write everywhere, I'd far prefer pulling in a pre baked HTML segment instead.
Do-able?


// find out device type
var device = NKGetDeviceType(); var isiPad = (device.match(/iPad/i) != null);

if (isiPad) {
// it's an iPad

// insert an iPad friendly HTML file here

} else {
// it's an iPhone

// insert an iPad friendly HTML file here

}
User avatar
bnlv
 
Posts: 17
Joined: Mon Mar 07, 2011 3:24 am

Re: If (iPad) then { insert HTML file }?

Postby cactuscraig » Sat Jul 23, 2011 6:26 am

I would use an NKWebIew on a page to show the "include.HTML" or "include-iPad.HTML"

Use NKGetDeviceType to find out iPad or iPhone.

I can give sample on Monday if need be. My Mac is at the office.

.
User avatar
cactuscraig
 
Posts: 846
Joined: Thu Feb 03, 2011 5:15 pm
Location: Scottsdale, AZ

Re: If (iPad) then { insert HTML file }?

Postby Big-O » Sat Jul 23, 2011 7:30 am

NKWebView is the NK way of doing that. It's a lot like working with iFrames.

Problem is, I despise iFrames. *shudder*

So personally, I would MUCH rather grab the external html with AJAX and pop the results into a div on the page. I always use jQuery in my apps and jQuery turns that into one line of code:

Code: Select all
$('#DivInMyApp').load('http://website.com/htmlThatIWant.html');


Though be wary, because jQuery can cause performance issues on iPhone depending on what you are doing with your app. Always test on a physical device.
-- Big-O
-- Nimblekit Guru, Web Developer, Hopeless Geek

I do freelance!
http://realisticweb.com
User avatar
Big-O
NimbleKit Guru
 
Posts: 1231
Joined: Thu Sep 24, 2009 4:02 am

Re: If (iPad) then { insert HTML file }?

Postby bnlv » Sat Jul 23, 2011 1:49 pm

Thanks for the quick responses Gents... I think the JQuery route might do the trick.

On JQuery (lazy question, but I've not have experience using either in iOS Safari)... would this be functionality contained within JQuery Mobile, or should I stick to plain ol' JQuery?
User avatar
bnlv
 
Posts: 17
Joined: Mon Mar 07, 2011 3:24 am

Re: If (iPad) then { insert HTML file }?

Postby HughJohnson » Sat Jul 23, 2011 5:07 pm

If the only thing you are using it for is one Ajax call then any framework is overkill.
Image
User avatar
HughJohnson
NimbleKit Expert
 
Posts: 286
Joined: Thu Jun 18, 2009 4:44 pm

Re: If (iPad) then { insert HTML file }?

Postby bnlv » Sat Jul 23, 2011 6:00 pm

Side note: var device = NKGetDeviceType(); returns x86_64 in simulator, regardless of device type being simulated. No choice but to develop using attached iPad.
User avatar
bnlv
 
Posts: 17
Joined: Mon Mar 07, 2011 3:24 am

Re: If (iPad) then { insert HTML file }?

Postby cactuscraig » Sat Jul 23, 2011 11:33 pm

I don't recall that being the case with nimble kit unless it is a change with Xcode 4.1 for lion.
User avatar
cactuscraig
 
Posts: 846
Joined: Thu Feb 03, 2011 5:15 pm
Location: Scottsdale, AZ

Re: If (iPad) then { insert HTML file }?

Postby Big-O » Sun Jul 24, 2011 3:29 am

jQuery mobile isn't very mature yet. I'm very excited about it, but I don't trust it for production use, personally.

But yes, I'd be willing to bet that function is in there already.

And about it being overkill...to each his own really. Doing it all by hand seems like overkill to me vs one line to import the file, and one line to execute the ajax.

But then, I'm not ashamed to admit that I'm a jQuery junkie and love makes people blind.
-- Big-O
-- Nimblekit Guru, Web Developer, Hopeless Geek

I do freelance!
http://realisticweb.com
User avatar
Big-O
NimbleKit Guru
 
Posts: 1231
Joined: Thu Sep 24, 2009 4:02 am

Re: If (iPad) then { insert HTML file }?

Postby HughJohnson » Sun Jul 24, 2011 6:14 pm

Jquery is awesome I agree. There are many cases where jquery does make sense to me, but using it for only one function doesn't seem like one of them. I'm just saying that adding hundreds of lines of code to your project in order to save you from writing 8 lines of code seems like overkill to me.
Image
User avatar
HughJohnson
NimbleKit Expert
 
Posts: 286
Joined: Thu Jun 18, 2009 4:44 pm

Re: If (iPad) then { insert HTML file }?

Postby ChimpWorks » Sat Aug 27, 2011 2:25 pm

I'm using jquery in the app I'm developing at present to load html pages into a div, it works well and means that loads of html pages aren't getting cached. Just avoid using jquery for any animations as its too slow, better to use webkit animations where possible.
Image
User avatar
ChimpWorks
 
Posts: 41
Joined: Tue Aug 09, 2011 2:03 am

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests