How to access documents of device - iphone

I want add documents (except images) in email by coding. i know we can access devices image gallery but i want to access documents of the device.
Can we access the documents just like imagepicker?

No you can not access Images from document directory same as device Library (by UIImagePickerView)
But if you want to get particular image from document directory then use following code.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *newPath = [documentsDirectory stringByAppendingPathComponent:#"NameOFImage"]; // put name of image which you want to get it from document directory
UIImage *myImage = [UIImage imageWithContentsOfFile:newPath];
Here myImage is image that you want to get it from document directory,

I understand that you want a visual file browser so try NSOutlineView.
Check this (similar) question
Using NSOutlineView as a file browser, starting from a given directory
or this tutorial:
http://www.alauda.ro/2012/04/30/nsoutlineview-inside-out/
Or manually handle the files using NSFileManager (but it seems this is not what you are looking for, but anyways...)
http://www.techotopia.com/index.php/Working_with_Directories_in_Objective-C#Getting__a_Directory_File_Listing
Actually, I don't believe there is anything as easy and simple as UIImagePicker for browsing files and folders so I guess the NSOutlineView will be the best choice for you.

Related

Auto upload camera roll in iPhone Application?

I am struggling to find something useful for automatically uploading photos from photo library to my server end.
In my iphone application i wan to automatically upload the photos to server as user captures a new photo.
The way facebook, Dropbox and google plus app doing.
Any help.
Mostly It's a 3 Step Process :
1) Get the photo. Store it to the Documents Directory. Apple has described it very well here : PhotoPicker
2) Fetch the Photo from Document Directory :
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:#"Images"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[dataPath stringByAppendingPathComponent:[NSString stringWithFormat:#"yourImage.png"]]];
3) Now , you can upload your Photo to the Server. The Process is well described Here :
upload image from iphone to the server folder

Pulling the images from the private app directory, select a few of those and send them to the next view

I am developing a camera app and whatever the pictures that i take using my app, those pictures should get stored in a private app directory.
If I click a button in the 1st view, it should go to the 2nd view showing the images retrieved from my private app directory.
I should be able to select a few of those images in the 2nd view and if I click the next button, the selected images should be displayed in the 3rd view.
So, first of all, how to create a private directory and how to retrieve images from that directory?
And how to select the images and send them to the next view?
Also, I should be able to change the order of those selected images in the 3rd view
simply by dragging them. How to do this as well?
First of all,
If you are thinking to create an app for storing images & using the images in other app, then you are choosing a wrong path. Apple will not allow you to do that.
What you can do is you can store the images in your application provided directories.
For directories, you can follow these directories:
There are three kinds of writable paths to consider - the first is Documents, where you store things you want to keep and make available to the user through iTunes (as of 3.2):
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
Secondly, and very similar to the Documents directory, there is the Library folder, where you store configuration files and writable databases that you also want to keep around, but you don't want the user to be able to mess with through iTunes:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths objectAtIndex:0];
Note that even though the user cannot see files in iTunes using a device older than 3.2 (the iPad), the NSLibraryDirectory constant has been available since iPhoneOS 2.0, and so can be used for builds targeting 3.0 (or even earlier if you are still doing that). Also the user will not be able to see anything unless you flag an app as allowing users to modify documents, so if you are using Documents today you are fine as long as you change location when updating for support of user documents.
Last there is a cache directory, where you can put images that you don't care exist for the long term or not (the phone may delete them at some point):
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [paths objectAtIndex:0];
BOOL isDir = NO;
NSError *error;
if (! [[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&isDir] && isDir == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:&error];
}
Note that you have to actually create the Caches directory there, so when writing you have to check and create every time! Kind of a pain, but that's how it is.
Then when you have a writable path, you just append a file name onto it like so:
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:#"SomeDirectory/SomeFile.txt"];
or
NSString *filePath = [cachePath stringByAppendingPathComponent:#"SomeTmpFile.png"];
Use that path for reading or writing.
Note that you can make subdirectories in either of those writable paths, which one of the example string above is using (assuming one has been created).
If you are trying to write an image into the photo library, you cannot use file system calls to do this - instead, you have to have a UIImage in memory, and use the UIImageWriteToSavedPhotosAlbum() function call defined by UIKit. You have no control over the destination format or compression levels, and cannot attach any EXIF in this way.
I Hope it helps you to fulfill your need & also make an understanding about directories.

How to upload the documents in the document path to iPad

It is the first time that I have tested my app on an iPad outside of the simulator. I have some files whose path is retrieved using:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
When running in the simulator everything is ok, but on the iPad it seems that the files in the document directory are not uploaded. How can I upload all of these files to the iPad?
iOS devices follow sandbox environment, so every app have its own Documents folder.
To save files in the documents folder, you can try the following:
//This will provide you path for the document folder of your app.
NSString *documentsPath = [NSHomeDirectory stringByAppendingPathComponent:#"Documents"];
Now, you can use this path to append path of your files and save your files.
Please let me know if any query.

Renaming the images in ipad and then saving that image to app bundle?

I am creating an app in which i am displaying images from photo library and app bundle by clicking on two separate action buttons.
Now what i want is that i want to create a new action button and its purpose will be to select an image from photo library and then save that image into my app bundle.
Can anyone guide me to right direction regarding this topic.
Thanks,
Christy
I don't think you can modify the application bundle once it's on the iPhone. The entire thing is code signed, and changing it would cause it to not run any more. You can try saving the image to documents directory.
So far as I know you cannot repackage the bundles on the iPhone once your app has been released to the App Store. So go the other way, and put the data from the bundle on the filesystem so you can change it at runtime.
My usual technique for this stuff is:
bundle up the initial data
have a routine that checks for the
presence of a versioned file on the
iPhone's filesystem at startup
if that routine doesn't find the
current version of the file, copy
all the data into the iPhone's
filesystem
reference the data from the
filesystem in my app, rather than
using the bundle path
So, essentially your bundle is just a delivery mechanism, a way to preload the filesystem with the stuff you are going to need. Once it's on the filesystem you can change anything you wish.
References
Downloading image into bundle?
How to save a UIImage to the application's Bundle?
UPDATE
- (IBAction)saveImage:(UIImage *)image {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:#"savedImage.png"];
NSData *imageData = UIImagePNGRepresentation(image);// Change according to your needs
[imageData writeToFile:savedImagePath atomically:NO];
}
You can make an NSData from the image you are picking from your photo library by using this -
NSData *imageData = UIImageJPEGRepresentation (UIImage *image,CGFloat compressionQuality);
then call
[imageData writeToFile:imgPath atomically:YES];
Here imgPath is the path for TMP dirextory where you want to write the file, get it as -
NSString *filename = #"a.png";
NSString *uniquePath = [TMP stringByAppendingPathComponent:filename];
and TMP is an enum
#define TMP NSTemporaryDirectory()

locating image files from hard disk to UIImageView

I have downloaded the image from ftp server ,the downloaded images are stored in hard disk , i want to locate those images files in my ImageView .
If this image will be bundled with your application, put it in the resource folder of you XCode project and add it to the main target. When done, you can load your setup the UIIMageView with :
myImgView.image = [UIImage imageNamed:#"mydownloadedimage.png"]
If the image should not be bundled with your App (i.e. because the image is downloaded by the application at runtime), it will probably ends in your document folder that you can access using :
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentFolder = [paths objectAtIndex:0];
then you can load the image using :
myImageView.image = [UIImage imageWithContentsOfFile:[documentFolder stringByAppendingPathComponent:#"mydonwloadedimage.png"]];
Good luck