i want to play video from html 5 file by zipping and unzip file programmatically of this link
http://enhancelearning.co.in/downloads/HTML5.zip
this file contain 4 html file
zip and unzip successfully created but video not playing in web view
here is th my code
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docspath = [paths objectAtIndex:0];
paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
// NSString *cachePath = [paths objectAtIndex:0];
NSString *zipFile = [docspath stringByAppendingPathComponent:#"001.html"];
NSURL *url = [NSURL fileURLWithPath:zipFile];
[webVew loadRequest:[NSURLRequest requestWithURL:url]];
Try first to put this html file somewhere in the net and see if the video playing when you go to this page from safari.
It's probably HTML-Safari-ios problem, and this way it easier to debug.
Related
In one of my activity, I displayed a PDF using WebView on screen and tried to save this PDF using this code:
_pageSize = CGSizeMake(width, height);
NSString *newPDFName = [NSString stringWithFormat:#"%#", name];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:newPDFName];
UIGraphicsBeginPDFContextToFile(pdfPath, CGRectZero, nil);
NSLog(#"path=%#",pdfPath);
When I run this code in iOS simulator (using Xcode) and show the path and I opened this PDF file successfully in documents folder, but when I run this code in an iPhone, I got this path:
/var/mobile/Applications/0AF98361-C8DF-4C35-9E9F-EE48555185BC/Library/354746396.pdf
So where are PDF files stored in iPhone?
"..InDomains(NSLibraryDirectory, NSUserDomainMask, YES);"
"../Library/354746396.pdf"
Your paths is looking in the NSLibraryDirectory, it should be looking in the NSDocumentDirectory like this:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
If still fail, try this code:
NSString *documents = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
NSString *savePath = [documents stringByAppendingPathComponent:#"filename.pdf"];
NSLog(#"savePath: %#", savePath);
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 367)];
webView.scalesPageToFit = YES;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:#"myPDF11.pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
}
my coding is right but i will not find the pdf file.i will solve my problem.i will find my pdf file in device.
there are two ways to find the pdf file.
1)install the iexplorer filemanager software.than open document folder.
2)connect your device in to the mac.select window menu and click the device in xcode.than after select your device name.select your app.
select show container.than after you can see the document folder....
I have an ipad app in which i show PDF documents in a UIWebView from my server.I want users to be able to download these documents so that they can read them offline. However i want them to read it only in the app.Basically my question is: Is it possible to have a folder that is only accessible from the app but not by users.
you can save it in the app bundle.
NSDate *date = [NSDate new];
NSString *docName = [NSString stringWithFormat:#"%lld.pdf", (long long)[date timeIntervalSince1970]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
dataPath = [documentsDirectory stringByAppendingPathComponent:docName];
EDIT: acording your comments question i think the solution would be something like this:
NSString *str = #"http://myserver.com/myfile.ext";
NSURL *url = [NSURL URLWithString:str];
NSData *content = [NSData dataWithContentsOfURL:url];
if (content) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [NSString stringWithFormat:#"%#/%#", documentsDirectory,#"myfile.ext"];
[content writeToFile:dataPath atomically:YES];
}
Steps:
Create password to PDF file and Open PDF programatically with password.
You can Make Own DRM for PDF files.
Refer Following Link:
iPhone Documents Folder Library/Caches Security issue
I am writing an app that can access the iOS root system, the user should be able to save files to his document directory. I am using this code to save the file to the document directory.
For Text:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
[self.filePath writeToFile:[NSString stringWithFormat:#"%#/%#", documentsDirectory, [self.filePath lastPathComponent]]
atomically:YES
encoding:NSUTF8StringEncoding error:nil];
For other files:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
[self.filePath writeToFile:[NSString stringWithFormat:#"%#/%#", documentsDirectory,[self.filePath lastPathComponent]]
atomically:YES];
My problem is I can save .txt files, but not other files, If I save for example .plist files with the save text methods, the contact is replaced by the directory path of the file. When I save a picture, or any other file it isn't readable. Is there a good method to save files without destroying them?
You're calling [self.filePath writeToFile:], thus writing the contents of the filePath variable to a file.
You should do something like:
[contents writeToFile:...]
Here you have an example of saving the image:
assuming you get the content of the image into NSData object:
NSData *pngData = UIImagePNGRepresentation(image);
then write it to a file:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
NSString *filePath = [documentsPath stringByAppendingPathComponent:#"image.png"]; //Add the file name
[pngData writeToFile:filePath atomically:YES]; //Write the file
Have a look into these questions for more detailed explanations:
Write a file on iOS
Save An Image To Application Documents Folder From UIView On IOS
I'm trying to make a txt log file with the actions that happens in my app. I want to save some text whenever the app is connecting to the server o displaying new info.
Well, how do I write to a file? I've tried using the method writeToFile: but it's not working because fileExistsAtPath: is returning NO.
My code is:
NSString *file_path = #"mylog.txt";
NSString *log = #"Hello World!!\n";
[log writeToFile:file_path atomically:YES encoding:NSUnicodeStringEncoding error:nil];
Thanks!
PS: Oh, would it be readable through Organizer with the iPhone plugged in?
You should use the < App_Home >/Documents folder for storing Documents
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *file_Path = [documentsDirectory stringByAppendingPathComponent:#"log.txt"];
[log writeToFile:file_path atomically:YES encoding:NSUnicodeStringEncoding error:nil];
But normally if you want to see and dump things while running the app,
you could just use NSLog() which outputs it in the console.
Try this method I wrote:
+(NSString*)createPath:(NSString*)fileName{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localizedPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"%#",fileName]];
//NSLog(#"%#",localizedPath);
return localizedPath;
}
It will return you a path for your file. You only need to give it a name.
How can I read a .txt file inside documents directory? Can you show me code?
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:#"txtFile.txt"];
NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
You can also use NSFileHandle for writing data in file and save to document directory:
You can follow: NSFileHandle