Accessing Document directory in iOS storing and retrieving data [closed] - ios

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm building a data which can store images into iOS document directory. I'm able to store the data in the document directory but how can I access it.And what is purpose of directory in iOS apps when there is persistent data store technologies like core data.Whether I can use directory to get persistent storage or I should go for core data.

I think, document directory is better solution in your case. Core data is useful for maintaining records corresponding to multiple fields.
Just use NSFileManager, something like this:
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];
It will give you an array with all the file paths for all files in the given path.
This is how you load the images from the array of URLs.
NSArray *paths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];
for (NSURL *url in paths)
{
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
}

Have you tried using UIDocumentPickerViewController?
This is Apple documentation: https://developer.apple.com/documentation/uikit/uidocumentpickerviewcontroller
Here is a tutorial:
https://medium.com/flawless-app-stories/a-swifty-way-to-pick-documents-59cad1988a8a

Related

download web page source code on iphone [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I need to download a particular webpage on my iphone.
It redirects me if i use a desktop.
Any tools out there that could help me to do this?
I have tried sitesucker but it didnt work.
Thanks!
If it redirects you when you use a desktop to access it, you can right click the link and download page as source. But since you want to do it on the iPhone, you can do the following:
// Download webpage
NSURL *url = [NSURL URLWithString:#"https://yourURL.here"];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
And you can access the data through your simulator folder or you directly get the NSString.
NSURL *url = [NSURL URLWithString:#"https://yourURL.here"];
NSString *source = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL]

Add a PDF from Internet(URL) to NSArray [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
How can I add a PDF from the Internet(URL) to a NSArray?
So that I can print this PDF out with the ActivityViewController.
I will not save the URL in the Array specially the PDF itself.
EDIT;
NSArray *items = #[self.background.request.URL.absoluteString];
I use this code, but this saves only the URL and not the pdf itself.
Actually it's not a good idea to store file contents for multiple PDF files into an array, as that would consume ways too much memory (and very likely the most of the time you don't even need it).
It's better to download the files to your app's cache or documents folder and load/print files from there. Of course you can download files into memory, but this will definitely fail with big files.
So in the array you probably just want to have URL's or filenames. Once you know which file you need, you actually load it (from your download location or from the URL) and do whatever you need to do with it.
However the answer to your question would be:
// CAUTION: This will block the thread while downloading
NSArray *items = [NSArray arrayWithObject:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.background.request.URL]]];
This statement will store the contents of the PDF file as NSData and put it in an array. To put more files in the array you can use [NSArray arrayWithObjects:..., nil].

How to access phone memory from application - iOS [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have an music application that plays songs from urls using AVPlayer. According to new requirement user should be able to listen their local songs (contines in phone memory) also through this music app. I want to know few things about this.
1) How to access local memory within my application.
2) Can I use already exists AVPlayer to play local songs too.
Any tutorial or examples uch appreciated.
Thanks
1) It depends on what you mean by 'local memory'. You app's local folder, or the device's iPodLibrary?
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSHomeDirectory()
stringByAppendingPathComponent:#"Documents"];
NSLog(#"Content of local documents directory: %#",
[fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil]);
This will print out all the files that's currently in your app's document-folder. You can store files here too. This is only for your app, not shared by any other app on your device. I do not think you're able to find the .m4a-audio files from your iPod from your application, I'm guessing Apple has hidden them so developers can't mess with them, or start pirating etc.
2) As it turns out, it looks like you can! Take a look at this answer.

Storage folder for video files and video "description" files in iOS - Apple Guidelines [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Currently I'm developing an app which will download some videos from a "computer device".
These videos will be played in the app -> for proper sync. another file is needed (each video has its coresponding file).
I have done some research on where should I store this... but there is no certain anwser (at least for me at this point).
Read this Guide to some point
I assumed the "/cache" folder is suitable?
Which folder should I use in this case? I want the video to be playable in an "offline" situtaion. These videos can "weight" a little thus I don't want any iCloud sync for them.
While items in the caches directory do not get backed up to iCloud they can be purged by the system if under pressure to reclaim disk space. You could potentially store it in the users documents directory if it's "user generated" data.
An appropriate place to store downloaded content that your app needs offline would be the Application Support directory (Library/Application Support).
NSArray *appSupportURLs = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask];
NSURL *applicationSupportDirectory = appSupportURLs[0];
You should also set attributes on files located elsewhere (Application Support, Documents, etc.) if you do not want them to be backed up. You can find more on it here: http://developer.apple.com/library/ios/#qa/qa1719/_index.html
Use NSCachesDirectory. It won't be backed up in iTunes or iCloud.
NSArray *cachedirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachedir = cachedirs[0];

How to use MPMediaPickerController with Local Files in Documents Directory? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I want to be able to use the MPMediaPickerController on local files that were downloaded in the Documents directory.
However, there is no option to set the source of the files that the controller looks in, which defaults of course to the iPod music library.
Are there any methods to load local files, or any alternate libraries available to provide the media picking functionality? Or will I have to reinvent the wheel here :(
You might want to take a look at AVAudioPlayer instead, seeing as MPMediaPickerController is a class designed to play music stored only in the iTunes media folder. It's also very easy to play media with from the doc directory:
NSString *soundFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]stringByAppendingPathComponent:#"mySong.m4a"];
NSURL *fileURL = [NSURL URLWithString:soundFilePath];
NSError *error;
AVAudioPlayer* audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
if(!error){
audioPlayer.delegate = self;
[audioPlayer play];
}else{
NSLog(#"Error loading clip: %#", [error localizedDescription]);
}

Resources