UIWebView, Word office document and pagination - iphone

When UIWebView loads Microsoft word documents, it just loads it as if it's one whole strip of paper, disregarding the separation between pages. Any idea how to display it properly (pages separated from each other), I'm open to lower level programming, or alternatives to UIWebView for loading Office documents. I'm currently using IPhone OS 3.2 for IPad.
E.g. I tried creating a word document with 2 pages, and one paragraph on each page, when I load it in UIWebView, it's displayed in one page.
The code I used is from Apple Technical Q&A
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
// Calling -loadDocument:inView:
[self loadDocument:#"test1.doc" inView:self.myWebview];
As a side note, I'm thinking this should be possible because there are apps like Documents to Go and QuickOffice, I'm not sure how they implemented it.

At the current SDK, it's not possible. We ended up implementing our own and used UIScrollView to meet our requirements. This was a lot of work implementing our own renderer, own panning system, etc.

Related

Responsive site displaying too small in iPhone

Similar question have been posted here, but I've none of the solutions presented there help me. I have a site: http://cherryfieldmaine.us/
When I test the site with Firefox Responsive Design View, or other online responsive testing tool, the site looks fine - just as it should. However, when I view it on a real iPhone, the site fills up less than 1/2 of the screen.
I've never encountered this before and I'm at a loss for how to fix it. Suggestions?
This is my code
NSString *urlString = #"http://cherryfieldmaine.us/";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:urlRequest];

How to make vimeo video autoplay on iPhone/iPad?

I'm trying to embed a vimeo video into my app using UIWebView.
Currently my code looks like this and it plays the video fine if you press play, but I would like it to play when the UIWebView loads and I'm not sure how to make that happen.
NSURL *videoURL = [NSURL URLWithString:#"http://player.vimeo.com/video/123456?autoplay=1"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:videoURL];
UIWebView * SignUpVideo = [[UIWebView alloc] init];
MyVideo.frame = CGRectMake(0,125,781,481);
[self.view addSubview:SignUpVideo];
[MyVideo loadRequest:requestObj];
This is placed under -(void)viewDidLoad
The autoplay URL parameter doesn't work in Mobile Safari either. I'm thinking you may be out of luck unless you can get a URL for a direct stream. But in that case you could use the AVPlayer instead of a web view and have all of the flexibility you need.
Here is an interesting discussion about the vimeo direct link URLs: How can I find download links for vimeo videos? . However, according to that, vimeo doesn't allow that technique so you might want to take a look a the developer APIs here: https://developer.vimeo.com
Best regards.

Images not shown in my iphone web app

I'm creating a web app and have a problem. My images is shown in my Safari browser and in the Iphone simulator, but they are not shown on my Iphone.
Any ideas?
If HTML files and images are stored locally on device, you have to keep in mid that iOS filesystem is case sensitive. so iPhone.jpg and iphone.jpg can be two different files... make sure that all your tags and corresponding files have correct case...
Also when loading uiwebview and resources for it are in bundle folder you have to make sure that you set baseURL so that webkit can find relative linked files:
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:htmlString baseURL:baseURL];
this enables you to link relative to bundle:
<img src=iPhone.jpg">

Loading performance between a UIWebView and Safari is considerably different, any pointers?

I have a UIWebView in an iPhone application I am building. It's job is to load up a URL. The code I use is:
NSURL *url = [NSURL URLWithString:providedURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
This is in viewDidLoad.
I have noticed that it takes around 18 seconds for the page to load in my app....but when using Safari it takes 5-8 seconds. Has anyone run into this issue before? Does it have anything to do with how I'm forming my request?
It is likely because Safari has cached the resources of the site already. A basic UIWebView does not do any caching by itself. You'll have to implement that yourself. See a question about that here:
How to cache content in UIWebView for faster loading later on?

iPhone: How to download a full website?

what approach do you recommend me for downloading a website (one HTML site with all included images) to the iPhone?
The question is how to crawl all those tiny bits (Javascripts, images, CSS) and save them locally. It's not about the concrete implementation (I know how to use NSURLRequest and stuff. I'm looking for a crawl/spider approach).
Jail breaks won't work, since it is intended for an official (App Store) app.
Regards,
Stefan
Downloading? Or getting the HTML-source of the site and displaying it with a UIWebView?
If last, you could simply do this:
NSString *data = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://apple.com"] encoding:NSUTF8StringEncoding error:NULL];
// Load UIWebView with data
[webView loadHTMLString:data baseURL:[NSURL URLWithString:#"http://apple.com"]];
EDIT:
For this approach, you would probably be best off using a regex-library for iPhone to parse through the string and find needed objects.
You could use this: RegexKitLite, and do a couple of Regex-expressions to find, for example, <link rel="%" href="*"> and src="*". But you have to remember to store them and replacing the values of * with the new path.
Storing files:
You will get url's back from the regex-methods, and you can write the files from the url's like this:
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSString rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString pathToCurrentSite = [rootPath stringByAppendingPathComponent:[NSString stringWithFormat:#"/%#/", fullUrlToPage]];
for (urlString in urlStrings) {
NSData *stringData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
[fileManager createFileAtPath:[pathToCurrentSite stringByAppendingPathComponent:urlString] contents:stringData attributes:nil];
}
NSString *data;
NSData *pageData = [data dataUsingEncoding:NSASCIIStringEncoding];
[fileManager createFileAtPath:[pathToCurrentSite stringByAppendingPathComponent:#"index"] contents:pageData attributes:nil];
[fileManager release];
Install wget on your jail broken iPhone
Use the spanning hosts options to download everything from the site.
wget -rH -Dserver.com http://www.server.com/
But why do you want to do this on a mobile device? This is somthing that should be done on a real computer with lots of memory, disk space, bandwidth and multiple CPU cores.
Was looking for similar functionality and found this. Can't claim any credit for it, just wanted to make sure it was mentioned (as a drop-in solution) for people interested in it.
http://robnapier.net/offline-uiwebview-nsurlprotocol
You can't save websites to your phone, only view them (unless your jailbroken.)
Hope this clears up your confusion,
Lee.
Here is the Appstore link https://itunes.apple.com/us/app/sitesucker/id346896838?mt=8
The app downloads entire websites natively to the phone.