ios persistent storage framework [closed] - ios

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 9 years ago.
Improve this question
I'm looking to save a bunch of 'recently accessed' information in my iOS app. For example, if a user views 5 articles, those 5 articles will persistently appear in a recently viewed section.
I was looking into core data and property lists but it all seems pretty complex for such a simple feature. Is there some sort of framework (like Lockbox for keychain) to help make persistent storage a bit easier?

The simplest way has to be to use the NSUserDefaults class. This class stores app-specific preferences to a property list, but all file handling is encapsulated by the class.
To get the object:
NSUserDefaults* settings = [NSUserDefaults standardUserDefaults];
To read a setting:
NSArray* mru = [settings valueForKey:#"MostRecentlyUsed"];
NSLog(#"Setting: %#", mru);
To write a setting:
[settings setValue:#[#"A", #"B", #"C", #"D", #"E", #"F"] forKey:#"MostRecentlyUsed"];
[settings synchronize];
(The synchronize method writes the changes to the file, it is useful to do this once you have set all your settings to avoid losing them if the app terminates unexpectedly)

For very simple storage of single objects, look at NSUserDefaults
For basic storage of non-basic objects, look at NSFileManager for accessing your App's document directory and NSCoder for serialization data.

Related

ORM-like feature on iOS [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I was wondering if there was a framework of some kind that enable us to create classes that will mainly fetch data from an API to populate itself.
I was looking at core data, but I don't think core data is what I'm looking for since it aims to persist data inside the app.
In case I wasn't clear enough, I want an easy way to do this:
#interface MyUser{
NSUInteger id; // user id form the database
NSString *first_name;
NSString *last_name;
...
}
#end
Is there anything inside(or outside) iOS that would help me with that, or I'll just have to fetch a JSON and populate it myself?
I wouldn't bother using any framework, you'll struggle to find one that suits your needs exactly.
Better to roll your own system, it's pretty simple.
Make a subclass of NSObject, give it an NSMutableDictionary or NSCache object to store data fetched from the remote server.
Implement -resolveInstanceMethod: to read/write to the data in the dictionary/cache/remote server.
There's a good example here showing roughly what you want: https://github.com/davedelong/Demos/blob/master/DynamicStorage/DynamicStorage/DDDynamicStorageObject.m follow through that code, read the documentation for anything you don't understand. It's fairly simple stuff once you get your head around it.

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].

When the variables saved as NSUserDefaults get released? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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
Closed 9 years ago.
Improve this question
Can i save more variables as NSUserDefaults?
When these variables get released?
Thank you.
When you remove the app from the device then only the data in the NSUserDefaults will be erased .
NSUserDefaults is not a mechanism for extending the lifetime of objects. It may not retain them at all (specifically, it may copy them and retain the copy instead)! It may save them to disk at arbitrary and unknowable intervals, and release them then. It may release them in response to memory pressure, or it may not.
NSUserDefaults is, only, a mechanism for storing and retrieving preferences. It's extremely good at that. Don't use it for other things.

On-the-fly encryption volume for iOS similar to TrueCrypt [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 9 years ago.
Improve this question
Does anyone know if there is library like TrueCrypt or EncFS for iOS.
Purpose is to create an encrypted volume to store large files like video's securely on the device, and play them whilst decrypting at runtime.
Want to be able to do this without relying on use entering a PIN for the inbuilt file protection. and be able to make use of AES-256 for the encryption.
If there is nothing, how would I go about writing or porting my own?
iOS architecture doesn't allow "disk encryption". However, if your code can do custom playback by passing the actual data to the player (in opposite to passing file name to the player), you can make use of our Solid File System product. This is a virtual file system with encryption and compression which you can embed into your application. Maybe that will work for you.
But encryption is just one side of the story - as you are passing the data and supposedly the encryption key to the users' hands, you need to take special actions to protect that key. This means that the key should be obfuscated within your application (or better streamed from the server) and also the parts of the data should better be encrypted with different keys.

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.

Resources