我有一个定期拍摄图像的应用程序,我希望它们在拍摄完图片后立即上传到iCloud Photo Stream。
为了实现这一点,似乎需要满足某些条件。它似乎只在运行iOS 8时工作,设备连接到无线,并通过使用UIImagePickerController至少拍摄一次(而不是AVCapture)。似乎UIImagePickerController在呈现时会改变一些系统设置,允许随后自动将图像上传到iCloud Photo Stream。如果我只使用AVCapture拍照,它将无法正常工作。我已经确认"上传到我的照片流"在iCloud设置中启用,并且存在活动的无线连接。
以下是用于保存从UIImagePickerController获取的图像的方法:
- (void)saveImage : (UIImage *)image {
// Add image to the photo library
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *assetChangeRequest =
[PHAssetChangeRequest creationRequestForAssetFromImage:image];
} completionHandler:^(BOOL success, NSError *error) {
if (!success)
NSLog(@"Error creating asset: %@", error);
}];
}
在使用iOS 8的iPad上运行时,下面是我在设备系统日志中看到的条目:
Oct 22 21:11:06 iPad mstreamd[14409] <Notice>: (Note ) PS: MSPublisher - xxxxxxxx Submitting 1 asset collections for publication.
Oct 22 21:11:06 iPad mstreamd[14409] <Notice>: (Note ) PS: MSPublisher - xxxxxxxx Sending metadata...
Oct 22 21:11:10 iPad mstreamd[14409] <Notice>: (Note ) PS: MSPublisher - xxxxxxxx uploading 1 assets...
Oct 22 21:11:11 iPad mstreamd[14409] <Notice>: (Note ) PS: Received push notification for invitations topic: com.apple.mediastream.subscription.push userInfo: {
r = xxxxxxxx;
}
Oct 22 21:11:11 iPad mstreamd[14409] <Notice>: (Note ) PS: <MSIOSMediaStreamDaemon: 0x1662ad80>: Push notification received for My Photo Stream with targetPersonID xxxxxxxx.
Oct 22 21:11:12 iPad mstreamd[14409] <Notice>: (Note ) mstreamd: <MSPowerBudget: 0x1666fae0>: Plugged in to external power. Allowing file transfers.
Oct 22 21:11:12 iPad mstreamd[14409] <Notice>: (Note ) mstreamd: <MSPowerBudget: 0x1666fae0>: Push received. Allowing file transfers to continue for 60.00 seconds
Oct 22 21:11:12 iPad mstreamd[14409] <Notice>: (Note ) PS: MSPublisher - xxxxxxxx Sending metadata...
Oct 22 21:11:12 iPad mstreamd[14409] <Notice>: (Note ) PS: MSSubscriber - xxxxxxxx Found 1 new asset collections.
Oct 22 21:11:13 iPad assetsd[11536] <Warning>: Unable to open file to save extended attributes (No such file or directory).
在使用iOS 9.1的iPhone上运行时,我有类似的日志条目,除了我有关于缓存服务器粗线的其他警告/错误消息:
Oct 25 22:35:28 iPhone mstreamd[1735] <Notice>: (Note ) PS: MSPublisher - xxxxxxxx Submitting 1 asset collections for publication.
Oct 25 22:35:28 iPhone mstreamd[1735] <Notice>: (Note ) PS: MSPublisher - xxxxxxxx Sending metadata...
**Oct 25 22:35:28 iPhone AssetCacheLocatorService[1658] <Warning>: #df99fdd0 [I:AssetCacheLocatorService.queue] found no caching servers**
Oct 25 22:35:28 iPhone mstreamd[1735] <Notice>: (Note ) PS: MSPublisher - xxxxxxxx uploading 1 assets...
**Oct 25 22:35:28 iPhone mstreamd[1735] <Notice>: (Error) mmcs: __mmcs_proxy_locator_exists_block_invoke:167 might have caching server returned with error: Error Domain=NSPOSIXErrorDomain Code=60 "Operation timed out" UserInfo={com.apple.AssetCacheLocator.tag=#1963bd2d, NSLocalizedDescription=quick miss requested}**
**Oct 25 22:35:29 iPhone mstreamd[1735] <Notice>: (Note ) PS: MSPublisher - xxxxxxxx Sending metadata...**
Oct 25 22:35:29 iPhone mstreamd[1735] <Notice>: (Note ) PS: Received push notification for invitations topic: com.apple.mediastream.subscription.push userInfo: {
r = xxxxxxxx;
}
Oct 25 22:35:29 iPhone mstreamd[1735] <Notice>: (Note ) PS: <MSIOSMediaStreamDaemon: 0x157e0c530>: Push notification received for My Photo Stream with targetPersonID xxxxxxxx.
Oct 25 22:35:29 iPhone mstreamd[1735] <Notice>: (Note ) mstreamd: <MSPowerBudget: 0x157e84410>: Plugged in to external power. Allowing file transfers.
Oct 25 22:35:29 iPhone mstreamd[1735] <Notice>: (Note ) mstreamd: <MSPowerBudget: 0x157e84410>: Push received. Allowing file transfers to continue for 60.00 seconds
Oct 25 22:35:29 iPhone mstreamd[1735] <Notice>: (Note ) PS: MSSubscriber - xxxxxxxx Found 1 new asset collections.
Oct 25 22:35:30 iPhone assetsd[1624] <Warning>: Unable to open file to save extended attributes (No such file or directory).
在iOS 9的这种情况下,当我的应用处于活动状态时,图片不会上传,只有在应用进入后台时才会上传。
我怀疑问题是由于1.某些系统设置是通过仅在iOS8或2中呈现UIImagePickerController而激活的。根据日志条目的建议,在iOS 9中缓存服务器存在一些问题。
任何人都知道发生了什么事?任何想法将不胜感激!谢谢!
答案 0 :(得分:0)
我想我找到了解决方案。似乎如果AVCaptureSession正在运行,iCloud Photo Stream将不会同步。调用stopRunning方法(如下所示)似乎可以解决问题:
[self.cameraSession stopRunning];