我尝试使用JPG文件和MOV文件制作实时照片。就像这样:
CGSize targetSize = CGSizeZero;
PHImageContentMode contentMode = PHImageContentModeDefault;
__weak NSURL *videoUrl;
__weak NSURL *photoUrl;
// Call private API to create the live photo
self.livePhotoView.livePhoto = nil;
self.livePhoto = nil;
self.livePhoto = [[PHLivePhoto alloc] init];
SEL initWithImageURLvideoURL = NSSelectorFromString(@"_initWithImageURL:videoURL:targetSize:contentMode:");
if ([self.livePhoto respondsToSelector:initWithImageURLvideoURL]) {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self.livePhoto methodSignatureForSelector:initWithImageURLvideoURL]];
[invocation setSelector:initWithImageURLvideoURL];
[invocation setTarget:self.livePhoto];
[invocation setArgument:&(photoURL) atIndex:2];
[invocation setArgument:&(videoUrl) atIndex:3];
[invocation setArgument:&(targetSize) atIndex:4];
[invocation setArgument:&(contentMode) atIndex:5];
[invocation invoke];
}
// Set the live photo
self.livePhotoView.livePhoto = self.livePhoto;
最后,我获得了实时照片并在livePhotoView中显示。然后我尝试保存或分享它。我使用Class UIActivityViewController.Like this:
if (self.livePhoto) {
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:@[self.livePhotoView.livePhoto]
applicationActivities:nil];
[self presentViewController:activityViewController
animated:YES
completion:^{
// ...
}];
}
当我分享实时照片时,我分享的只是静止图像。当我选择保存实时照片时,我无法在相册中找到任何内容。我在很多地方搜索。我只是在这里找到一些信息https://github.com/genadyo/LivePhotoDemo/issues/3。但它并没有解决我的问题。
我发现一个应用程序可以在AppStore中执行。但我无法理解它是如何工作的。https://itunes.apple.com/cn/app/livemaker-free-for-live-photo/id1053967828?mt=8