This is a snippet from Apple's sample code AVCamManualExtendingAVCamtoUseManualCaptureAPI where the DNG data has to be temprorily written in to a file:
[PHPhotoLibrary requestAuthorization:^( PHAuthorizationStatus status ) {
if ( status == PHAuthorizationStatusAuthorized ) {
NSURL *temporaryDNGFileURL;
if ( self.dngPhotoData ) {
temporaryDNGFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%lld.dng", resolvedSettings.uniqueID]]];
[self.dngPhotoData writeToURL:temporaryDNGFileURL atomically:YES];
}
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCreationRequest *creationRequest = [PHAssetCreationRequest creationRequestForAsset];
if ( self.jpegPhotoData ) {
[creationRequest addResourceWithType:PHAssetResourceTypePhoto data:self.jpegPhotoData options:nil];
if ( temporaryDNGFileURL ) {
PHAssetResourceCreationOptions *companionDNGResourceOptions = [[PHAssetResourceCreationOptions alloc] init];
companionDNGResourceOptions.shouldMoveFile = YES;
[creationRequest addResourceWithType:PHAssetResourceTypeAlternatePhoto fileURL:temporaryDNGFileURL options:companionDNGResourceOptions];
}
}
else {
PHAssetResourceCreationOptions *dngResourceOptions = [[PHAssetResourceCreationOptions alloc] init];
dngResourceOptions.shouldMoveFile = YES;
[creationRequest addResourceWithType:PHAssetResourceTypePhoto fileURL:temporaryDNGFileURL options:dngResourceOptions];
}
} completionHandler:^( BOOL success, NSError * _Nullable error ) {
if ( ! success ) {
NSLog( @"Error occurred while saving photo to photo library: %@", error );
}
if ( [[NSFileManager defaultManager] fileExistsAtPath:temporaryDNGFileURL.path] ) {
[[NSFileManager defaultManager] removeItemAtURL:temporaryDNGFileURL error:nil];
}
[self didFinish];
}];
}
else {
NSLog( @"Not authorized to save photo" );
[self didFinish];
}
}];In above code, the line creates the DNG file name using resolvedSettings.uniqueID:
temporaryDNGFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%lld.dng", resolvedSettings.uniqueID]]];Above line creates a file named, for example, 23lld.dng. This becomes a problem when users want consecutive file names along with JPEG's and other asset file names in the photo library.
If the users last asset's file name is IMG_0155.jpg, the DNG file being created should be IMG_0156.dng in this case.
How would I be able to get the proper name for the DNG file?