Offline with webarchive

25 views
Skip to first unread message

Dirk Holtwick

unread,
Sep 11, 2008, 4:54:28 AM9/11/08
to phon...@googlegroups.com
Hi,

that's easy! I tried to load a local webarchive in Big5 (same as
PhoneGap) and it worked. The only thing to be aware of is not to
include post loading stuff in the page, if you want to remain
completely offline.

So, how does it work?

1 You surf to your page via Safari
2 Go to "save as" and choose "webarchive"
3 Add the webarchive to your PhoneGap bundle

The code in PhoneGap has to be something like:

NSString *urlPathString;
NSBundle * thisBundle = [NSBundle bundleForClass:[self class]];
if (urlPathString = [thisBundle pathForResource:@"demo"
ofType:@"webarchive"]){
NSLog(@"my app: loading local url %@", urlPathString);

[webView loadRequest:[NSURLRequest
requestWithURL:[NSURL fileURLWithPath:urlPathString]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0
]];
}

Dirk

Dirk Holtwick

unread,
Sep 11, 2008, 8:02:54 AM9/11/08
to phon...@googlegroups.com
Okay, I cracked the offline stuff. It is so very simple!

Just drag and drop the whole folder of your WebApp from finder to
XCode Resources. Make sure that "Create Folder References for any
added folders" is selcted, because otherwise Groups are created which
do not result into subfolders. So lets say you added a folder called
"webapp", you may access it like this:

if (urlPathString = [thisBundle pathForResource:@"index"
ofType:@"html" inDirectory:@"webapp"]){


NSLog(@"my app: loading local url %@", urlPathString);

[viewController.gWebView loadRequest:[NSURLRequest


requestWithURL:[NSURL fileURLWithPath:urlPathString]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0
]];
}

That's it. It is so simple, I am really surprised :)

Dirk

Blackwind

unread,
Sep 12, 2008, 1:38:47 AM9/12/08
to phonegap
Hey Dirk,

Congrats on getting it to work! I'm having a bit of trouble getting
the offline stuff working.
I pasted in your code and it just keeps crashing (auto closing) in
simulator. So I'm not sure what to do.
What should I input in my txt file (or should I do it at all?)

Also, if you don't mind, could you host a sample of your project just
to help.
Thanks in advance I really appreciate. I'm so excited by your
discovery, congratulations, and thank you for the effort!

Regards,

David

Dirk Holtwick

unread,
Sep 12, 2008, 1:56:07 AM9/12/08
to phon...@googlegroups.com
Blackwind schrieb:

> Congrats on getting it to work! I'm having a bit of trouble getting
> the offline stuff working.
> I pasted in your code and it just keeps crashing (auto closing) in
> simulator. So I'm not sure what to do.
> What should I input in my txt file (or should I do it at all?)

Sorry, the example was based on Big Five. For PhoneGap you have to
modify this file:

http://github.com/sintaxi/gap/tree/master/Classes/GlassAppDelegate.m

This part:

if (urlPathString = [thisBundle pathForResource:urlFileName
ofType:@"txt"]){

NSString * theURLString = [NSString
stringWithContentsOfFile:urlPathString];
NSURL * anURL = [NSURL URLWithString:theURLString];
NSURLRequest * aRequest = [NSURLRequest requestWithURL:anURL];
[webView loadRequest:aRequest];
}

has to be replaced by this:

if (urlPathString = [thisBundle pathForResource:@"index" ofType:@"html"
inDirectory:@"webapp"]){

[webView loadRequest:[NSURLRequest
requestWithURL:[NSURL fileURLWithPath:urlPathString]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0
]];
}

I haven't tested it. But that's more or less the idea.

The url.txt file is not needed any mo

> Also, if you don't mind, could you host a sample of your project just
> to help.
> Thanks in advance I really appreciate. I'm so excited by your
> discovery, congratulations, and thank you for the effort!

Okay, I will try to publish a recent version of Big Five somewhere. But
this may take until Monday, because I will not publish it totally to the
public because of the Apple NDA. I will keep you updated.

Dirk

Blackwind

unread,
Sep 12, 2008, 2:32:57 AM9/12/08
to phonegap
Never mind, just figured it out! Thanks for the sample code Dirk,
couldn't have done it without your help!

Chris Blown

unread,
Oct 5, 2008, 9:40:02 PM10/5/08
to phon...@googlegroups.com
thanks for the code snippet dirk. I had problems using the web archive file as saved from safari ( single file? ) though i found just dragging my local folder ( all links relative ) into resources and ticking create folder references worked fine.

if you haven't seen http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/ i suggest you take a look, though i wish position:fixed just worked as it should.. apple?.

thx
chris

Dirk Holtwick

unread,
Oct 8, 2008, 7:16:55 AM10/8/08
to phon...@googlegroups.com
Chris Blown schrieb:

> if you haven't seen
> http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/
> i suggest you take a look, though i wish position:fixed just worked as
> it should.. apple?.

Thats a good example. I asked the developer of the WebApps.Net tool to
implement something similar ;)

http://webapp.net.free.fr/

BTW: Does someone know other good frameworks like Dashcode and
WebApps.Net? Dashcode is a little bit limited if you really need to
mimic an iPhone App with toolbars etc. What are you using?

Dirk

Lieven Gekiere

unread,
Oct 8, 2008, 3:20:59 PM10/8/08
to phon...@googlegroups.com
That webapp.net does really look good and is quite advanced (according
to the documentation on http://webapp.net.free.fr/Doc/Menu.html )

L.

Reply all
Reply to author
Forward
0 new messages