【问题标题】:Auto upload camera roll in iPhone Application?在 iPhone 应用程序中自动上传相机胶卷?
【发布时间】:2013-03-18 22:43:16
【问题描述】:

我正在努力寻找一些有用的东西来自动将照片从照片库上传到我的服务器端。 在我的 iphone 应用程序中,我想在用户拍摄新照片时自动将照片上传到服务器。 facebook、Dropbox 和 google plus 应用的做法。

任何帮助。

【问题讨论】:

    标签: iphone ios objective-c camera


    【解决方案1】:

    主要是一个 3 步流程:

    1) 获取照片。将其存储到文档目录。苹果在这里描述得很好:PhotoPicker

    2)文档目录获取照片:

    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) 现在,您可以将照片上传到服务器了。该过程在这里得到了很好的描述: upload image from iphone to the server folder

    【讨论】:

    • 感谢您的回复。我的问题是如何跟踪哪些照片已经上传到服务器,哪些是我需要上传的新照片。同样根据某处的评论,他们说我们需要在后台执行此过程以将照片继续流式传输到服务器。那么当应用程序进入后台时会发生什么?
    • 有没有办法在不将资产复制到Documents 目录的情况下进行上传?我知道 NSURLSession 会将上传放在后台,但是您可以在不创建本地副本的情况下上传资产吗?
    • @AlexSpencer: ALAssetRepresentation represent = assets.defaultRepresentation;无符号长代表大小=(无符号长)代表大小;字节 *buffer = (Byte)malloc(representSize); NSUInteger buffered = [represent getBytes:buffer fromOffset:0.0 length:representSize error:nil]; // 你应该检查错误! // 获取数据 NSData *dataUpload = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
    • alasset 隐蔽到 NSData(如上面的评论)否则你将无法获得位置等 Exif 信息。
    猜你喜欢
    • 1970-01-01
    • 2019-06-19
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多