PrefPanes & Plist Save Location in 10.7 - osx-lion

I'm writing a preference pane & this prefpane saves a plist file with settings & I used to store this in the /Library/Preferences/ folder; This worked fine in OS X 10.6 but now we switched to 10.7 & apples has revoked the rights to write in the /Library/Preferences folder (without an administrator password) i.e. the prefpane can't write there. Is there a better location that is accessible by all the system where I can save my prefpane's plist file.

You should probably not explicitly write to Library/Preferences, but instead use NSUserDefaults. If that's not enough for you, I believe ~/Library/Application Support is an allowable option.

Related

Save PDF file to a user-defined default directory in iCloud Drive

I'm asking this question because I did not find any answer, and I'm starting to believe that it's not possible, due to security reasons. But who knows?
In my app, I simply let the user save a PDF file using UIActivityViewController. The user then chooses Save to file, then selects iCloud Drive.
Now, users ask me to be able to select a default location once and for all.
Is it possible? This location would of course be outside the app container, then I suppose iOS won't grant access unless the user selected it itself.
Yes you can. Using UIDocumentPickerViewController you can ask for a directory, and you can save it in your app. This is explained in detail in Providing Access to Directories. iOS 13 and later.
See also What's New in File Management and Quick Look for sample code saving a directory URL and then reusing it to set the base directory for a subsequent call to UIDocumentPickerViewController

Can't Find iPhone Simulator's SQLite Database : Using Magical Record

In my application's documents folder, I do not find my SQLite database
Library/Application Support/iPhone Simulator/6.1/"random app
id"/Documents/
^This folder is empty
MagicalRecord seems to be working, I just have no idea how to find the database.
I use the following to set up Magical Record
[MagicalRecord setupAutoMigratingCoreDataStack];
So where does MagicalRecord store its database?
MagicalRecord stores, by default, all data stores in the following location:
{App Folder}/Library/Application Support/{App Name from Info.plist}/{storeName.sqlite}
This is easily accessible from the simulator as well as documents.
You can log your SQlite file location using the following NSPersistentStore MR addition :
[NSPersistentStore MR_urlForStoreName:[MagicalRecord defaultStoreName]]
If you know the name of the sqlite file then just do a search in OSX for that file to find the directory. Otherwise the file was never created.
Make sure you are setting up the CoreData stack correctly as per the documents.
+ (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName;
Swift + Xcode 7 + simulator 9.0
Please go to your AppDelegate.swift
change
MagicalRecord.setupCoreDataStackWithStoreNamed("yourDBName.sqlite")
to
MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStoreNamed("yourDBName.sqlite")
Now you can locate the yourDBName.sqlite at
/Users/userName/Library/Developer/CoreSimulator/Devices/"random app id"/data/Containers/Data/Application/"random app id"/Library/Application Support/ProjectName
There is a useful tool: simPHolders2 (http://simpholders.com)
simPHolders easy to access all application folders

Security of string resources

Recently i've asked about the security implications of storing sensitive info in the xml string resources in Android: the answer? Heavy security implications, is really easy to get the contents of every xml file with a simple command line tool, so it is almost mandatory to have important info encrypted.
Now, how is it like in iOS? How secure it is to have a certain data in a plist or a .strings localizable file, in plain text, non encrypted?
Still not very secure.
There is nothing stopping a user from unzipping an application stored on their computer in iTunes and viewing the contents. Its very easy to do, even without a jail broken phone. Any strings resources, plist files etc will be immediately accessible.
Even hard coded string literals are visible in the compiled binary when one views it with the strings utility. And going a set further, using the nm utility one can see all your applications symbols, such as method names, constants, etc.
I would recommend against storing anything that could be considered sensitive in plain text.
You can access any file on a jailbroken iPhone, so you'll need to encrypt sensitive data.
If your app ships with a .plist file, then the end user can unzip the .ipa app file and see the .plist file and do whatever they want with it.
The exact same problems, a plist is a very common file for Mac OSX and iOS and it is just a XML file. Secure your sensitive data on ALL platforms!
I would like to add that apple does provide a way to securely store sensitive information in the Keychain.

How to view data stored in Core Data?

I'm creating a Core Data model for my application. I would like to be able to look inside it to see what I have stored in there.
Is there an easier way than searching for the backing store (mine should be SQLite) and reading it from there? Doesn't seem very Apple-esque.
Once your app has run in the simulator and created the persistent store file, you can find the file in your app's Documents directory.
Your app data will be folder inside (~ is your home directory):
~/Library/Developer/CoreSimulator/<device>
In versions prior to XCode 6, the path was:
~/Library/Application Support/iPhone Simulator/User/Applications/
I sort by "Date Modified" to find the app that I just built.
For viewing a SQLite file, check out Base and/or Core Data Editor.
You can also use FireFox's Add-on tool SQLite Manager (FREE). I use it and it works well.
If you are using iOS 10 & Swift get it into your AppDelegate.swift:
let container = NSPersistentContainer(name: "***")
print(container.persistentStoreDescriptions.first?.url)
Then you'll see something like that:
Optional(file:///Users/<SomeUser>/Library/Developer/CoreSimulator/Devices/956F0003-5DA4-4588-97C1-A9A83767F341/data/Containers/Data/Application/9765FDE1-6971-4706-987B-96FBD3F462BF/Library/Application%20Support/***.sqlite)
You can try a little free tool called CoreDataPro. Pretty nice. Here
Core Data Lab is a dedicated Core Data viewer that offers everything to view and analyze the Core Data database of your app, like automatic search for databases, data change tracker, simulator browser, a predicate editor, data editor, a built-in web and image content viewer, and much more.
Info page: https://betamagic.nl/products/coredatalab.html
Free 14-trial: https://betamagic.nl/downloads/Core%20Data%20Lab%20Trial.zip
Diclaimer: I'm the creator of this tool.
I found a free version here:
http://sourceforge.net/projects/sqlitebrowser/files/sqlitebrowser/2.0%20beta1/sqlitebrowser_200_b1_osx.zip/download
Update to this thread, The iphone simulator location has been moved to a different location in Xcode7 and Xcode8. It is now in:
~/Library/Developer/CoreSimulator/...
where ~ is your home directory.
Any of the previous solutions will still work, but you won't be able to find the correct folder if you use the previous links.
Also try sqlite database browser. its free and reflects that fact. very useful though!
cheers.bo
I created a macOS app to browse your Core Data content. It hides Core Data implementation as you see when you use a SQLite browser. Also you can list all your latest run apps and simulators, with this you can easily find the app you are looking for. More info here:
http://www.microedition.biz/simMagnifier
It has other features like access Simulator's folders such as Documents, Application Support, etc. You can check the content of NSUserDefaults too.
The app is not free sorry! but at least you have a 7 days trial.
Here is the full path, apparently it changed since gerry3's answer
~/Library/Application Support/iPhone Simulator/<Simulator>/Applications/<ApplicationID>/Documents/<NAME>.sqlite
So a correct path would like this:
~/Library/Application Support/iPhone Simulator/7.1-64/Applications/C1F3C2E5-987A-4DF7-91EF-955AE6E52621/Documents/TestApp.sqlite
3 Easy Steps
install liya application, its free, Size 3.1 MB, so installs in 1 minute.
Link https://itunes.apple.com/us/app/liya/id455484422?mt=12.
Open Finder, Press "Ctrl + G" OR "CMD + Ctrl + G", Paste ~/Library/Developer/
In Developer Folder, search for your Core Data model name (eg. MyProjectModel).
Open MyProjectModel.d file Or 'MyProjectModel.sqlite' using liya. In liya, select a table, Click on "Run SQL Command".
Done.

Is there a way to access AddressBook db file programmatically?

i need to copy this database file and save it in someother location or i can take backup of the db file. is there a way to do this programmatically.
Thanks
Satish
Unless you've jailbroken your iPhone, there's no way of accessing the sqlite3 database directly on the phone.
If you're talking about getting access to the database from your computer, you can do it by grabbing the database files out of the iPhone backup files. To do that, you'll need to grab a copy of Erica Sadun's mdhelper (binary file) command line utility, and run it from the PC you sync your laptop with like so:
mdhelper -files "AddressBook.sqlitedb" -extract -glob
This will create a "~/Desktop/Recovered iPhone Files" directory containing a file called AddressBook.sqlitedb, which you can access directly or query using your programming language of choice.
If you don't trust downloading and running binary files without knowing what they do, you can look at the source on Github and compile it yourself.
the SQL database can be extracted from an iphone backup. I used this software to grab mine and the SMS database.
If you have lots of images/videos in camera roll it can take a while to run.
http://www.supercrazyawesome.com/
Yeah sorry abt that. ok thanks probably i will create a new database using AddressBook Apis
-Satish
You can also take a backup of your iphone and than use one of tools discribed here to identify the file you need.