6

我尝试使用 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 中。然后我尝试保存或分享它。我使用 UIActivityViewController 类。像这样:

  if (self.livePhoto) {

    UIActivityViewController *activityViewController =
    [[UIActivityViewController alloc] initWithActivityItems:@[self.livePhotoView.livePhoto]
                                      applicationActivities:nil];
    [self presentViewController:activityViewController
                       animated:YES
                     completion:^{
                         // ...
                     }];


}

当我分享live photo时,我分享的只是静止图像。当我选择保存live photo时,我在相册中找不到任何东西。我在很多地方搜索了这个。我只是在这个https://github中找到了一些信息.com/genadyo/LivePhotoDemo/issues/3。但这并没有解决我的问题。

我在 AppStore 中发现了一个应用程序可以做到这一点。但我不明白它是如何工作的。https://itunes.apple.com/cn/app/livemaker-free-for-live-photo/id1053967828?mt=8

4

0 回答 0