Auto upload camera roll in iPhone Application? - iphone

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

Related

How to access documents of device

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.

where is best place to save application files in IOS

I am programming for iOS using Objective-C
what is the best place (I mean path or local URL) to save my downloaded mp3 files that I download using my code and what is the best place to save the Plist file that contains information about the downloaded songs
Due to the nature of iOS (and app sandboxing), you can only save within your app's document directory. To obtain the path to this directory, you can use:
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];
One advantage of the sandbox approach is the fact that when your app is updated on the device, the files in the document directory will remain untouched and hence can be updated by the app as required.
I'd recommend a read of the File System Programming Guide, as it covers this topic (and a lot more), including iCloud file management, etc.
For Document Directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString* docDir = [paths objectAtIndex:0];
For Caches Directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *libDirectory = [paths objectAtIndex:0];
For tmp Directory:
NSString *tmpDirectory = NSTemporaryDirectory();

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