how to get mac share folder path on iOS - 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);

Related

Read and Write the MetaData contents as a File in Documents Directory

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* arrayText = [MetaDataArray componentsJoinedByString: #"\n"];
NSString *path = [documentsDirectory stringByAppendingPathComponent:#"EmployeeData.txt"];
[arrayText writeToFile:path atomically:YES];
MetaData Array first Object look like this :
{fileSize:"9385033" labels:{viewed,starred,restricted,trashed,hidden}
originalFilename:"Chamak Challo - Ra.One (2011) [MP3-320Kbps-CBR].mp3" mimeType:"audio/mpeg"
title:"Chamak Challo - Ra.One (2011) [MP3-320Kbps-CBR].mp3" parents:[1]
md5Checksum:"51d598c750102dd4bca09addf4d8212d" quotaBytesUsed:"9385033"
lastModifyingUserName:"shadow.hibrise" copyable?:1
headRevisionId?:"0B7v4X9XjauwJR3dZM1FQWlpHeEFOZGYyYzR2NUdtLzhmb2FNPQ" kind:"drive#file"
writersCanShare:1 appDataContents?:0 modifiedDate:"2014-03-04T11:13:32.649Z" shared?:0
id:"0B7v4X9XjauwJdTUyeW5zTVRNTU0" ownerNames:[1] userPermission:{etag,kind,id,type,role}
createdDate:"2014-03-04T11:13:32.649Z" fileExtension:"mp3"
iconLink?:"https://ssl.gstatic.com/docs/doclist/images/icon_10_audio_list.png"
modifiedByMeDate:"2014-03-04T11:13:32.634Z" downloadUrl:"https://doc-10-3s-
docs.googleusercontent.com/docs/securesc/0ijvatgpdej0qafpk7qtp7n2jgndtb3d/ifb42us5ai6ae9ah4kalfu4cnrtl6j3n/1398153600000/18240796891762319987/18240796891762319987/0B7v4X9XjauwJdTUyeW5zTVRNTU0?h=16653014193614665626&e=download&gd=true" lastModifyingUser?:{kind,displayName,permissionId,isAuthenticatedUser} editable:1 etag:""fgLq6vWOgR-hiHy-psxfsLtIDgQ/MTM5MzkzMTYxMjY0OQ"" webContentLink:"https://docs.google.com/uc?id=0B7v4X9XjauwJdTUyeW5zTVRNTU0&export=download" owners?:[1] alternateLink:"https://docs.google.com/file/d/0B7v4X9XjauwJdTUyeW5zTVRNTU0/edit?
usp=drivesdk"}
I want to store Array of Objects as a file and vice versa.
You can use Sqllite or core data instead of filesystem.
For core-data please refer this link
For filesystem this can be useful

Downloading localize packages at runtime

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);

SQLite data fetch from Document directory

I have a sqlite db stored in the Document directory and images name in one of the column of table ..and Image are store in app bundle.Images are coming directly by giving the names of imgaes in the column by using code..means no need to specify any path..just name is fine.
now if i store images dynamically in the document directory and give the name of the image in image column of Sqlite db directly as above I am unable to fetch it. Do i need to specify any path to reach there..as In app bundle images are coming directly.
Yes. You need to specify the path to the sqlite file in the document directory.
Or use the following code with corresponding image name (Images are in document directory):
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:#"img.png"];
yourImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:imagePath]];
You can get directory path as below:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
and to get image you have to append image name after this path. You have data in your database, so from that you can get imagename.
If the value in the database is just the name of the image (such as "someimage.png") then you have two possibilities:
1) If the image is in the app bundle then use the value from the database with the UIImage imageNamed: method. I believe you already have this working.
2) If the image is in the Documents directory then you have a little more to do. You need to obtain the full path to the Documents directory and then append the filename (from the database) to the path. This will give you a full path to the image in the Documents directory. Then to load the image you need to use the UIImage imageWithContentsOfFile: method passing in the full file path.
Use this code .
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory35 = [paths objectAtIndex:0];
//Essential Info
NSString *fullPathEssentialInfo = [documentsDirectory35 stringByAppendingPathComponent:#"EssentialInfo.txt"];
This is implemented code.Thanks
There is an example project for accessing SQLite here: https://github.com/AaronBratcher/ABSQLite

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