Hi I have my iPhone app which will be run on a jailbroken iPhone and I want to download a file from the web and place it in another apps directory.
I am new to iOS development and have successfully downloaded the file and placed it in the Documents folder but how do I search for the UID of the app and place it in the library folder of another app? Keeping in mind this is on JB iPhone and have access to the filesystem.
Here is what I have so far.
NSString *stringURL = #"http://testfile.plist";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#%#", documentsDirectory,#"/testfile.plist"];
[urlData writeToFile:filePath atomically:YES];
Thanks
You can do documentation interaction controller make sure you develop custom url scheme and you should be able to pass around with user consent .
Related
I have a scenario in my application that I need to download mp3, pdf, text files using my application.
How can I download, and where to store, data using my application?
NSString *stringURL = #"http://www.somewhere.com/thefile.png";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", documentsDirectory,#"filename.png"];
[urlData writeToFile:filePath atomically:YES];
}
You can store in Document directory,Below is example to store a image .Below is link explained to store audio video file
How to download audio/video files from internet and store in iPhone app?
Document Directory is best to store data.
NSString *path = [[self applicationDocumentsDirectory].path
stringByAppendingPathComponent:#"fileName.txt"];
[sampleText writeToFile:path atomically:YES
encoding:NSUTF8StringEncoding error:nil];
- (NSURL *)applicationDocumentsDirectory {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
}
It depends on what will you need to do with data. If data can be recreated or downloaded, save it in temp o cacje directory. If data is created by user and have to be backed up, you can use Documents to sync with iCloud.
I recommend you to read Apple documentation because if you this wrong way, your App could be rejected.
https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html
You can exclude your files to be backed up (and stored in Documents folder)
https://developer.apple.com/library/ios/qa/qa1719/_index.html
Thanks to thelaws I've fixed the exhibiting problem in the device. But I still need to fix the images issue. Gotta download them along with the HTML and exhibit as well, any hints?
EDIT:
-FIXED Actually I am using this code, i got from Anne in another thread. It works (not showing images nor anything else than html) on iOS Simulator but fails to exhibit anything (not even console errors) when i try to run in my device, what's the problem?
// Determile cache file path
NSString *path = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", path, #"index.html"];
// Download and write to file
NSURL *url = [NSURL URLWithString:#"http://www.google.nl"];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
// Load file in UIWebView
[web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
Fixed the path to:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
This is because you can't write to the bundle on a Device, although it works on the simulator.
Please see Technical Q&A QA1662 for more details straight from Apple
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 have a sqlite file on a server
i want to connect to that server via objective-c on just after user successfully login to the application. then download the file to the bundle of app and then use it in other views.
First i want to ask is it possbile? if it is possible is there any tutorial or example for this?
Yes it is possible.
There are many ways to download files from a server this is one of them:
NSString *stringURL = #"http://www.somewhere.com/thefile.sqlite";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", documentsDirectory,#"filename.sqlite"];
[urlData writeToFile:filePath atomically:YES];
}
Here is a tutorial for SQLite:
SQLite Tutorial
Yes its possible. The file would can be stored in Application Document / Library directory.
The same can be achieved by using NSURLConnection.
A sample tutorial explaining NSURLConnection tutorial-how-to-use-ios-nsurlconnection-by-example
Hope this helps.
Hey guys a quick question!
I am making an iPad app which uses the dropbox sync api. Now I am wondering how to play movie files within my dropbox filesystem in the MPMovieplayer. Since the dropbox filesystem is not the same as the local sandbox and I don't know how to retrieve a nsurl of the file I can't play the video.
This is something I tried (my last hope) but it doesn't work:
+(NSString*)loadMovie : (DBPath*)path
{
DBFile *file = [self openFileAtPath:path];
NSData *data = [[NSData alloc] initWithData:[file readData:nil]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *vpath = [documentsDirectory stringByAppendingPathComponent:file.info.path.name];
[[NSFileManager defaultManager] createFileAtPath:vpath contents:data attributes:nil];
return vpath;
}
You'll need to write the file out to local storage first. See https://forums.dropbox.com/topic.php?id=110085 on the Dropbox forum.