iOS photo extension finishContentEditingWithCompletionHandler: Unable to Save Changes

前端 未结 2 1892
猫巷女王i
猫巷女王i 2021-02-08 18:28

My photo extension app has access to both Camera and Photos. All is ok, but when pressing Done, it can not save image.

Code of standard completion handl

相关标签:
2条回答
  • 2021-02-08 18:45

    Even though the header implies that adjustmentData can be nil, the documentation states:

    If you write new asset content to the URL specified by the renderedContentURL property, you must also provide a new, distinct PHAdjustmentData object describing your edit. Passing a preexisting adjustment data object (that describes an earlier edit) results in undefined behavior.

    So do something like this before calling the completion handler:

    output.adjustmentData = [[PHAdjustmentData alloc] initWithFormatIdentifier:@"com.whatever.app" formatVersion:@"1.0" data:[NSData data]];
    
    0 讨论(0)
  • 2021-02-08 19:04

    As of iOS 10, the adjustment data must have at least one byte. This is a breaking change from iOS 9, where the adjustment data can be nil. I've tested this on both iOS 9 and iOS 10 to confirm.

    Additional documentation: 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];
    
    0 讨论(0)
提交回复
热议问题