问题
How I can upload a camera roll image automatically to server? This same thing implemented in Dropbox and Google Photos and some other apps also. What should I do to achieve such kind of functionality in my app?
回答1:
What you are asking is not a single question, but a paradigm. An entire process, that includes:
Obtaining authorisation to access the photo library.
Accessing assets (images/videos) in the user's gallery.
Uploading to a server.
Read up on all the three, if you want to achieve this. In a nutshell it is as follows:
You use ALAssetsLibrary
to access assets (the photos and videos in the user's gallery). If the user has not authorized yet, the user will be asked automatically. If the user has authorised access, you can request for assets. If the user has denied access explicitly, you should not attempt to access assets.
See THIS answer to see how you can access images using the ALAssetsLibrary
.
In the success block, you can access the images with :
UIImage* image = [UIImage imageWithCGImage:asset.defaultRepresentation.fullResolutionImage];
Once you have the image, you can upload it using any technique (NSURLSession, AFNetworking, etc)
回答2:
dropbox not upload the camera roll images automatically to server or there is no application in iOS which automatically upload images until user give it access permission.
Dropbox not working until user enable photo access permission.
if you want to upload the images first take all images access using ALAssetsLibrary than send the images to server in background using GCD or NSOperationQueue
回答3:
are you trying to make it so that when you take a picture with the iOS camera it auto uploads to your server?
I don't believe you can do that, my understanding with dropbox and google on your iOS device is that their app has to be open to upload pictures. From there it's no big deal to access a user's photos and allow them to upload one or many pictures.
Dropbox and google also have desktop apps that run on OS X that will auto upload images after the device is plugged into the computer, but I am assuming that isn't what you are asking.
来源:https://stackoverflow.com/questions/29405903/how-we-can-upload-camera-roll-image-automatically-to-server