PHAssetCreationRequest DNG File Name

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?

To understand your question:

- how are you sure the last asset name ends with a number ?

- what should you do if it ends with something else ?

- do you want to change extension from jpg to dng ?


If so, what is the problem to parse the last asset's file name, get extension out, find the number, add 1 and rebuild temporaryDNGFileURL ?

I am not sure if the last asset ends with a number or not. But I have users complaining how DNG's have a different naming sheme ('37.dng' instead of 'IMG_12323') compared to JPEGS.


Is there a way to get the default name for the next asset?

On this link, he has this line:

https://forums.developer.apple.com/message/265953#265953


NSString* filename = [PHPhotoLibrary sharedPhotoLibrary].nextAssetFilename;


However, that .nextAssetFilename is no where to be found in API's.


If I know the regular name would be, I can attach that to .dng.

nextAssetFilename seems to be a func defined by the app, not an API.


Found this : www.hyperrealm.com/blip/apidocs/classblip_1_1AssetManager.html

where they explain:

blip is a C++ framework for developing pure-native applications for the Android platform.

PHAssetCreationRequest DNG File Name
 
 
Q