iOS15.1 无法合成livePhoto

目前发现iOS15.1之前的版本合成livePhoto都没问题,对于刚发的iOS15.1就是合不成livePhoto

原因:发现图片信息metadata中makerApp里面的“17”写入不进去。

- (NSData *)dataByRemovingExifAndAddMakerApple:(NSString *)uuid
{
    NSData *data = self;
    CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)data, NULL);
    NSMutableData *mutableData = nil;
    
    if (source) {
        CFStringRef type = CGImageSourceGetType(source);
        size_t count = CGImageSourceGetCount(source);
        mutableData = [NSMutableData data];
        
        CGImageDestinationRef destination = CGImageDestinationCreateWithData((CFMutableDataRef)mutableData, type, count, NULL);
        
        NSDictionary *removeExifProperties = @{(id)kCGImagePropertyExifDictionary: (id)kCFNull,
                                               (id)kCGImagePropertyGPSDictionary : (id)kCFNull,
                                               (id)kCGImagePropertyMakerAppleDictionary:@{@"17":uuid?uuid:@""}};
        
        if (destination) {
            for (size_t index = 0; index < count; index++) {
                CGImageDestinationAddImageFromSource(destination, source, index, (__bridge CFDictionaryRef)removeExifProperties);
            }
            
            if (!CGImageDestinationFinalize(destination)) {
                //                NSLog(@"CGImageDestinationFinalize failed");
            }
            
            CFRelease(destination);
        }
        
        CFRelease(source);
    }
    
    return mutableData;
}

上面是以前的写法

- (NSData *)dataByRemovingExifAndAddMakerApple:(NSString *)uuid {
    NSMutableData *data = self.mutableCopy;
    UIImage *image = [UIImage imageWithData:data];
    CGImageRef imageRef = image.CGImage;
    NSDictionary *imageMetadata = @{(NSString *)kCGImagePropertyMakerAppleDictionary : @{@"17" : uuid}};
    CFStringRef type = CGImageGetUTType(imageRef);
    CGImageDestinationRef dest = CGImageDestinationCreateWithData((CFMutableDataRef)data, type, 1, nil);
    CGImageDestinationAddImage(dest, imageRef, (CFDictionaryRef)imageMetadata);
    CGImageDestinationFinalize(dest);
    return data;
}

上面是修正后的写法

你可能感兴趣的:(iOS15.1 无法合成livePhoto)