Downloading localize packages at runtime - ios

I have an app on the market, I would like to localize it to other languages, the process I would like to implement is:
User downloads the app
User selects language
language pack is downloaded to applications folder
my question is how to implement step #3 (and does it effect the app review process) using adobe air
Thanks

Download your bundle to Documents directory with name "Translations.bundle", then use this code
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths firstObject];
NSString *bundlePath = [documentsPath stringByAppendingPathComponent:#"Translations.bundle"];
NSBundle *translationsBundle = [NSBundle bundleWithPath:bundlePath];
NSString *message = NSLocalizedStringFromTableInBundle(#"Message", nil, translationsBundle, nil);

Related

Retrieve all pdf files store in iPhone memory iOS (Objective-C)

I want to retrieve all the pdf documents from my iPhone, including all the pdf files that are stored in other apps like Adobe Acrobat.
What I have now is:
NSString *path = [NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
for (NSString *fileName in directoryContent) {
if ([fileName hasSuffix:#"pdf"]) {
//add files to an array
}
}
Which only points to one directory.
Firstly you are only getting the first path to the first directory, so you're only searching that one. Secondly, apple suggests to use the NSFileManager to search. Thirdly, be aware that developers of other apps can save their documents in different places, that you can't access or are not returned by these functions (Just so you are aware of this).
If you want to get array of all pdf files in Document directory, then use below code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *arrPdfs = [[NSBundle bundleWithPath:[paths objectAtIndex:0]] pathsForResourcesOfType:#"pdf" inDirectory:nil];
arrPdfs will contain all pdfs in Document directory.

XCode - file not found in document directory

I am having random error while reading saved photos from document directory in iPhone. I save photos taken from my app to document directory and then read it from there next time when user come back. However, after XCode 6 & base SDK change to 8.1, this document directory path keeps changing. So sometime I found photos and sometime not.
I read few posts online thats says that not Apple differentiate App from Data and that's why this issue coming up. Anyone has any thoughts on this? Any solution?
This is how I save file to document Directory
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path firstObject];
NSString *filePath = [documentDirectory stringByAppendingPathComponent:#"key"];
[image writeToFile:path atomically:YES];
And this is how I read it:
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path firstObject];
NSString *filePath = [documentDirectory stringByAppendingPathComponent:#"key"];
UIImage *cellImage = [[UIImage alloc] initWithContentsOfFile:filePath];
Go to Product - Scheme - Edit Scheme - Options - Working Directory and specify working directory

how to get mac share folder path on iOS

I'm working on an app,now i used openssh find and get access to my mac's file system,I can access every folder at my app.That dangerous for my computer,I want to know is there any way I can only get the shared folder at my app,instead every folder.Just like use mac to connect other people's share folder,only get the share folder.what should i do,and i'm thinking get the share folder path and use it as an argument,is that right?
You can use
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSSharedPublicDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:#"Playlist"];
if you want path of Documents directory replace first line by this
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

Using directory to store information and keep this information in a App Update

I have an app that stores images from the user in the app/documents folder, I'm doing the following code determine the path to save it:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docs = [paths objectAtIndex:0];
NSString *imageFilename = [[[[NSNumber alloc] initWithInteger:self.nextID] stringValue] stringByAppendingFormat:#".jpg"];
NSString *dirPath = [docs stringByAppendingFormat:#"/Photos/"];
imagePath = [dirPath stringByAppendingString:imageFilename];
it gives me a path similar to (in simulator):
/var/mobile/Applications/C9C43CFD-6A5F-40CF-8BAE-20496B5A544A/Documents/Photos/1.jpg
I save this path to show this image when I need.
My problem is, when I sent an update in the app store, after update the app it cant show the images anymore.
My understand is the Documents folder cant change when update the app in AppStore.
My probably reason for that it the name between Applications folder and Documentar has changed, is it true when update a app version from AppStore?
Does anyone has any idea? is there any way to test this app update local?
Thanks
You need to save the relative path after the Documents directory, not the absolute path. The app's directory can change during an update but the structure inside the app's sandbox won't change.
Also, there is a slightly better way to build your path:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docs = [paths objectAtIndex:0];
NSString *imageFilename = [NSString stringWithFormat:#"%d.jpg", self.nextID];
NSString *dirPath = [docs stringByAppendingPathComponent:#"Photos"];
imagePath = [dirPath stringByAppendingPathComponent:imageFilename];
When the app is updated from the App Store, the contents of the Documents directory are unchanged. The app bundle and all its contents are replaced with the new version, but the Documents folder is a safe place to store content between app versions.

Finding the path of my documents folder in iOS

file://localhost/var/mobile/Application/EAC0BC34-6A82-41CB-AE44-9CD8E7D880C8/Documents
I get an alert this is my path, but i am unable to find where this location is all about. I am using iOS 5.0 to deploy my Application in ma device.
Thanks
Try this:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
Or as per your tag, maybe you're using Titanium? If so maybe this helps:
https://wiki.appcelerator.org/display/guides/Filesystem+Access+and+Storage - Ti.Filesystem.applicationDataDirectory

Resources