PHAssetChangeRequest.creationRequestForAsset() Crashes

There is a crash on the closing brace of the photo capture completion handler where commented below.

// Initiate image capture:
cameraController.captureImage(){ ( image: UIImage?, error: Error? ) in
// This closure is the completion handler, it is called when
//  the picture taking is completed.
  print( "camera completion handler called." )

  guard let image = image else {
    print(error ?? "Image capture error")
    return
 }
                
 try? PHPhotoLibrary.shared().performChangesAndWait { 
   PHAssetChangeRequest.creationRequestForAsset(from: image)
   } // crash here
}

When step through pauses on that closing brace, and the next step is taken, there is a crash. Once crashed what I see next is assembly code as shown in the below disassembly:

libsystem_kernel.dylib`:
    0x1e7d4a39c <+0>:  mov    x16, #0x209
    0x1e7d4a3a0 <+4>:  svc    #0x80
->  0x1e7d4a3a4 <+8>:  b.lo   0x1e7d4a3c4               ; <+40>   Thread 11: signal SIGABRT
    0x1e7d4a3a8 <+12>: pacibsp 
    0x1e7d4a3ac <+16>: stp    x29, x30, [sp, #-0x10]!
    0x1e7d4a3b0 <+20>: mov    x29, sp
    0x1e7d4a3b4 <+24>: bl     0x1e7d3d984               ; cerror_nocancel
    0x1e7d4a3b8 <+28>: mov    sp, x29
    0x1e7d4a3bc <+32>: ldp    x29, x30, [sp], #0x10
    0x1e7d4a3c0 <+36>: retab  
    0x1e7d4a3c4 <+40>: ret    

Obviously I have screwed up picture taking somewhere. I would much appreciate suggestions on what diagnostics will lead to the resolution of this problem. I can make the entire picture taking code available on request as an attachment. It is too lengthy to post here.

Accepted Reply

This problem is solved. I finally noticed I was getting the message that the application crashed because I did not have in my P-List the right key to give the user the reason why the app needs to access the Photo Library. I thought the key: "Privacy - Camera Usage Description" was sufficient. After adding also the keys: "Privacy - Photo Library Usage Description", and for good measure "Privacy - Photo Library Additions Usage Description", the app no longer crashed.

  • I recommend that you evaluate whether your app actually needs full Photo library access or not. If your app only adds photos, then you do not need the "Privacy - Photo Library Usage Description" key, you would only need the "Privacy - Photo Library Additions Usage Description" key.

Add a Comment

Replies

This problem is solved. I finally noticed I was getting the message that the application crashed because I did not have in my P-List the right key to give the user the reason why the app needs to access the Photo Library. I thought the key: "Privacy - Camera Usage Description" was sufficient. After adding also the keys: "Privacy - Photo Library Usage Description", and for good measure "Privacy - Photo Library Additions Usage Description", the app no longer crashed.

  • I recommend that you evaluate whether your app actually needs full Photo library access or not. If your app only adds photos, then you do not need the "Privacy - Photo Library Usage Description" key, you would only need the "Privacy - Photo Library Additions Usage Description" key.

Add a Comment