Принудительная синхронизация сохраненного изображения с iCloud Photo Stream
У меня есть приложение, которое периодически делает снимки, и я бы хотел, чтобы они загружались в Photo Stream iCloud сразу после того, как они были сняты.
Похоже, что определенные условия должны быть выполнены, чтобы это работало. Кажется, это работает только при использовании 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);
}];
}
При работе на моем iPad с iOS 8 ниже приведены записи, которые я вижу в системных журналах устройства:
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).
При работе на моем iPhone с iOS 9.1, у меня есть подобные записи журнала, за исключением того, что у меня есть дополнительные предупреждения / сообщения об ошибках на сервере кэширования, выделенном жирным шрифтом:
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. некоторыми системными настройками, которые активируются при представлении UIImagePickerController только в iOS8 или 2. некоторыми проблемами с серверами кэширования в iOS 9, как предлагается в записях журнала.
У кого-нибудь есть идеи, что происходит? Благодарим за любую идею! Спасибо!
1 ответ
Я думаю, что нашел решение. Похоже, что если AVCaptureSession запущен, iCloud Photo Stream не будет синхронизирован. Вызов метода stopRunning (как показано ниже), кажется, делает свое дело:
[self.cameraSession stopRunning];