iOS照片扩展finishContentEditingWithCompletionHandler:无法保存更改

我的照片扩展程序应用可以访问相机和照片.
一切正常,但按完成后,无法保存图像.

标准完成处理程序代码:

- (void)finishContentEditingWithCompletionHandler:(void (^)(PHContentEditingOutput *))completionHandler {
    // Update UI to reflect that editing has finished and output is being rendered.

    // Render and provide output on a background queue.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^{
        PHContentEditingOutput *output = [[PHContentEditingOutput alloc] initWithContentEditingInput:self.input];

        NSError* error = nil;

        NSData *renderedJPEGData = UIImageJPEGRepresentation(filtered_ui_image,1.0);
        assert(renderedJPEGData != nil);
        //BOOL written_well = [renderedJPEGData writeToURL:output.renderedContentURL atomically:YES];

        BOOL written_well = [renderedJPEGData writeToURL:output.renderedContentURL options:NSDataWritingAtomic error:&error];
        assert(written_well);



        // Call completion handler to commit edit to Photos.
        completionHandler(output);
    });
}

renderedJPEGData不是nil,
错误是nil,因此函数[NSData writeToURL]成功,
written_well是,

逐行调试时,块完成后会出现一个警告:

output.renderedContentURL是/private/var/mobile/Containers/Data/PluginKitPlugin/509C1A04-D414-4DB7-B1E6-83C47FC88BC9/tmp/blah_blah_name.JPG

所以,我有权限,调试显示没有错误,我可以尝试检测问题的原因是什么?

解决方法

从iOS 10开始,调整数据必须至少有一个字节.这是iOS 9的重大变化,其中调整数据可以为零.我已经在iOS 9和iOS 10上对此进行了测试以确认.

附加文件:https://developer.apple.com/reference/photos/phcontenteditingoutput/1518684-adjustmentdata

PHContentEditingOutput* output = [[PHContentEditingOutput alloc] initWithContentEditingInput:self.input];
NSMutableData* adjustmentData = [NSMutableData data];
uint8_t byte = 1;
[adjustmentData appendBytes:&byte length:1];
output.adjustmentData = [[PHAdjustmentData alloc] initWithFormatIdentifier:@"com.yourcompany.yourapp" formatVersion:@"1.0f" data:adjustmentData];

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...