title: How to get an authorized PHAsset from UIImagePickerController?
body: <p>I have this code: </p>
  
  <pre><code>@IBAction func importButtonPressed(_ sender: Any) {
          self.imagePicker.sourceType = .photoLibrary
          self.imagePicker.allowsEditing = true
          self.imagePicker.mediaTypes = [kUTTypeMovie as String, kUTTypeImage as String]
  
          self.present(self.imagePicker,animated: true, completion: nil)
  }
  </code></pre>
  
  <p>This presents the UIImagePicker perfectly. Then when I want to use the picked item to get say the date of the PHAsset: </p>
  
  <pre><code>func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
          guard info[UIImagePickerControllerMediaType] != nil else { return }
          let mediaType = info[UIImagePickerControllerMediaType] as! CFString
          switch mediaType {
          case kUTTypeImage:
              if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
                  ...
              }
              break
          case kUTTypeMovie:
              if let videoURL = info[UIImagePickerControllerMediaURL] as? URL, let pickedAsset = info[UIImagePickerControllerPHAsset] as? PHAsset {
                  print("kUTTypeMovie")
                  MyVariables.isScreenshot = false
                  let creationDate = pickedAsset.creationDate
                  print(creationDate,"creationDate")
              }
              break
          case kUTTypeLivePhoto:
              print("livePhoto")
              dismiss(animated: true, completion: nil)
  
              break
          default:
              dismiss(animated: true, completion: nil)
  
              print("something else")
              break
          }
      }
  </code></pre>
  
  <p>Now, when I pick a video for instance,<code>print("kUTTypeMovie")</code> fails I think because <code>let pickedAsset = info[UIImagePickerControllerPHAsset] as? PHAsset</code> fails</p>
  
  <p>Elsewhere (<a href="https://stackoverflow.com/questions/47316909/uiimagepickercontrollerdelegate-get-date-from-picked-image-in-ios-11">UIImagePickerControllerDelegate get date from picked image in iOS 11</a>) I have seen that perhaps this is because I need authorization to pick PHAssets. </p>
  
  <p>So I change my first block of code to: </p>
  
  <pre><code>@IBAction func importButtonPressed(_ sender: Any) {
  
          let status = PHPhotoLibrary.authorizationStatus()
  
          switch status {
          case .authorized:
              PHPhotoLibrary.requestAuthorization({status in
                  if status == .authorized {
                      self.imagePicker.sourceType = .photoLibrary
                      self.imagePicker.allowsEditing = true
                      self.imagePicker.mediaTypes = [kUTTypeMovie as String, kUTTypeImage as String]
  
                      self.present(self.imagePicker,animated: true, completion: nil)
                  }
              })
          case .denied:
              print("denied")
          // probably alert the user that they need to grant photo access
          case .notDetermined:
              print("not determined")
          case .restricted:
              print("restricted")
              // probably alert the user that photo access is restricted
          }
  
      }
  </code></pre>
  
  <p>However now when I press the import button it crashes with an lldb error: </p>
  
  <pre><code>libsystem_kernel.dylib`__abort_with_payload:
      0x1854f7040 &lt;+0&gt;:  mov    x16, #0x209
      0x1854f7044 &lt;+4&gt;:  svc    #0x80
  -&gt;  0x1854f7048 &lt;+8&gt;:  b.lo   0x1854f7060               ; &lt;+32&gt;
      0x1854f704c &lt;+12&gt;: stp    x29, x30, [sp, #-0x10]!
      0x1854f7050 &lt;+16&gt;: mov    x29, sp
      0x1854f7054 &lt;+20&gt;: bl     0x1854d8bdc               ; cerror_nocancel
      0x1854f7058 &lt;+24&gt;: mov    sp, x29
      0x1854f705c &lt;+28&gt;: ldp    x29, x30, [sp], #0x10
      0x1854f7060 &lt;+32&gt;: ret    
  </code></pre>
  
  <p>So clearly I am not doing that correctly. How am I supposed to do this? </p>