Created
December 23, 2011 21:04
-
-
Save benbahrenburg/1515352 to your computer and use it in GitHub Desktop.
Titanium : How to find the Private Directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function privateDocumentsDirectory(){ | |
Ti.API.info('We need to open a file object to get our directory info'); | |
var testFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory); | |
Ti.API.info('Now we remove the Documents folder reference'); | |
var privateDir = testFile.nativePath.replace('Documents/',''); | |
Ti.API.info('This is our base App Directory =' + privateDir); | |
Ti.API.info('Now we add the Private Documents Directory'); | |
privateDir+='Library/Private%20Documents/'; | |
Ti.API.info('Our new path is ' + privateDir); | |
return privateDir; | |
}; | |
var myDbName = 'foo123'; | |
Ti.API.info('We create a db to test our method') | |
var testDb = Ti.Database.open(myDbName); | |
var testNativePath = testDb.getFile().nativePath; | |
Ti.API.info('Our nativePath to test against is ' + testNativePath + ' this is what we need to end up with'); | |
var privateDocFolder = privateDocumentsDirectory(); | |
Ti.API.info('Our Private Document Folde is ' + privateDocFolder); | |
Ti.API.info("Let's see if we can find our database"); | |
var dbCheck = Ti.Filesystem.getFile(privateDocFolder, myDbName+ '.sql'); | |
Ti.API.info('Did we find it? ' + dbCheck.exists()); | |
Ti.API.info('Do our file paths match? ' + (dbCheck.nativePath==testNativePath)); | |
Ti.API.info('Example Finished'); |
Wondering if this is still valid. Guess I need to find that out.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This an example on how to find the Private Documents directory in Appcelerator Titanium. In iOS 5 and Titanium SDK 1.8+ your database will now be stored in this directory.