如何将相机胶卷图像自动上传到服务器?同样的事情在 Dropbox 和 Google Photos 以及其他一些应用程序中也实现了。我应该怎么做才能在我的应用程序中实现这种功能?
3 回答
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
你问的不是一个单一的问题,而是一个范式。一个完整的过程,包括:
获得访问照片库的授权。
访问用户图库中的资产(图像/视频)。
上传到服务器。
如果您想实现这一目标,请阅读所有这三个方面。简而言之,如下所示:
您用于ALAssetsLibrary
访问资产(用户图库中的照片和视频)。如果用户尚未授权,将自动询问用户。如果用户具有授权访问权限,您可以请求资产。如果用户明确拒绝访问,则不应尝试访问资产。
请参阅此答案以了解如何使用ALAssetsLibrary
.
在成功块中,您可以使用以下命令访问图像:
UIImage* image = [UIImage imageWithCGImage:asset.defaultRepresentation.fullResolutionImage];
获得图像后,您可以使用任何技术(NSURLSession、AFNetworking 等)上传它
您是否尝试这样做,以便当您使用 iOS 相机拍照时,它会自动上传到您的服务器?
我不相信你能做到这一点,我对你 iOS 设备上的 Dropbox 和 google 的理解是,他们的应用程序必须打开才能上传图片。从那里访问用户的照片并允许他们上传一张或多张照片没什么大不了的。
Dropbox 和 google 也有在 OS X 上运行的桌面应用程序,这些应用程序会在设备插入计算机后自动上传图像,但我假设这不是你要问的。