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">
Related
how to import *.pdf all pdf from my iphone to my app like this add music file. http://developer.apple.com/library/ios/#samplecode/AddMusic/Introduction/Intro.html .Thanks in advance .New to iphone dev.Really appreciate any help.
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSFileManager *mgr = [[NSFileManager alloc] init];
NSArray *allFiles = [mgr contentsOfDirectoryAtPath:bundlePath error:NULL];
for (NSString *fileName in allFiles)
{
if ([[fileName pathExtension] isEqualToString:#"pdf"])
{
NSString *fullFilePath = [bundlePath stringByAppendingPathComponent:fileName];
// fullFilePath now contains the path to your pdf file
// DoSomethingWithFile(fullFilePath);
NSLog(#"file: %#",fullFilePath);
}
}
NSURL *url = [[NSBundle mainBundle] URLForResource:#"" withExtension: #"pdf"];
NSLog(#"File: %#",url);
You can just email the pdf file as attachment and the iphone can read it on its own. That feature already exists within the iOS of the iPhone or you could upload them somewhere (on your server) and send the links.
You can't just browse all the files on the phone from within your App.
As I said to you in the comment on your other questions (which, by the way is almost exactly the same as this one, but in the other question you ask about csv files rather than pdf), you need to read up about the App Sandbox.
In a nutshell, Apps can only see their own files and those that are written by the App. All apps have their own storage space and they can only see in that area.
Having said that, it is possible to pass some files around between apps, but they have to be written to support that. There is no such concept as a global file system on iOS devices.
READ THIS
I am writing a small POC to play the video in iPhone app. I would like to do so in UIWebView with the help of HTML5. I dont want to use standard players like AVPlayer or MPMoviePlayerController.
Can someone throw some light on it?..
I am new to this HTML5 environment on iPhone. So, any help to start this POC would be appriciated.
I forget to add that i would like to play h264 live stream on server.
Thanks in advance.
Yes, you can do that:
NSString *bundleDirectory = [[NSBundle mainBundle] pathForResource:#"mov" ofType:nil];
NSString *filePath = [bundleDirectory stringByAppendingPathComponent:#"loopvideo.html"];
NSString *HTMLData = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
[self.web loadHTMLString:HTMLData baseURL:[NSURL fileURLWithPath:bundleDirectory]];
In your HTML, you can embed the <video> tag and it should play.
I want to play a movie in my app and the video is stored in my ipad library.
Can anyone provide me the necessary guidance for it?
Get the MPMediaItem of the video you want using MPMediaQuery
Get the Asset URL like this:
NSURL *videoURL = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
Instantiate an MPMoviePlayerViewController using videoURL as the content URL.
If the video is stored in your App's bundle then do this to get the URL:
NSURL *videoURL = [[NSBundle mainBundle] URLForResource:#"nameoffile" withExtension:#"mp4"];
See a sample of a custom view/viewController combo in Pragmatic iPad Programming. Check the source code for chapter 8 (free download from that page). They use a video provided as a file inside the project. Btw, if the file in the video appears red in XCode, you'll have to remove it and re add it, I think the project definition is a bit screwed.
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.
Using MontoTouch for .NET C# iPhone development. (though should not matter)
In the iPhoneSimulator, I use UIImage.FromFile (#"images/Bahai.png"); to get the Bahai.png from the images folder.
However, when I run it in debug mode on my iTouch, the function returns a null.
Only if I put the image file in the root does it work in the iTouch.
Is there a different relative path I need to use?
Ian
Not sure if this will help, but in objective-C, I would load an image from the app bundle like this:
UIImage *image = [UIImaged imageNamed:#"Bahai.png"];
For other types of files, I would get the absolute path like this:
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"Bahai" ofType:#"png"];