title: Show images in Intents UI using SiriKit
body: <p>I'm developing a simple photo search using SiriKit. I'm able to search and display images on main viewcontroller but I'm not able to show images on Intents UI using IntentsUI framework. I followed this <a href="http://jamesonquave.com/blog/adding-siri-to-ios-10-apps-in-swift-tutorial/" rel="nofollow noreferrer">tutorial</a> but it lacks Intents UI implementation. Here what I' have done so far. </p>
  
  <p><strong>IntentHandler.swift</strong></p>
  
  <pre><code>class IntentHandler: INExtension, INSearchForPhotosIntentHandling {
  
      override func handler(for intent: INIntent) -&gt; Any {
  
          return self
      }
  
      // MARK: - INSearchForPhotosIntentHandling
  
      func resolveDateCreated(forSearchForPhotos intent: INSearchForPhotosIntent, with completion: @escaping (INDateComponentsRangeResolutionResult) -&gt; Void) {
  
          if intent.dateCreated != nil {
              completion(INDateComponentsRangeResolutionResult.success(with: intent.dateCreated!))
          }
          else{
              completion(INDateComponentsRangeResolutionResult.needsValue())
          }
      }
  
  
      func confirm(searchForPhotos intent: INSearchForPhotosIntent, completion: @escaping (INSearchForPhotosIntentResponse) -&gt; Void) {
  
          let response = INSearchForPhotosIntentResponse(code: .ready, userActivity: nil)
          completion(response)
      }
  
      func handle(searchForPhotos intent: INSearchForPhotosIntent, completion: @escaping (INSearchForPhotosIntentResponse) -&gt; Void) {
          let response = INSearchForPhotosIntentResponse(code:.continueInApp,userActivity: nil)
  
          if intent.dateCreated != nil {
              let calendar = Calendar(identifier: .gregorian)
              let startDate = calendar.date(from:(intent.dateCreated?.startDateComponents)!)
              response.searchResultsCount = photoSearchFrom(startDate!)
  
          }
          completion(response)
      }
  
  
      // MARK: - Search Photos 
  
      func photoSearchFrom(_ startDate: Date) -&gt; Int {
  
          let fetchOptions = PHFetchOptions()
          fetchOptions.predicate = NSPredicate(format: "creationDate &gt;= %@", startDate as CVarArg)
  
          let fetchResult = PHAsset.fetchAssets(with: PHAssetMediaType.image,
                                                options: fetchOptions)
          return fetchResult.count
      }
  
  }
  </code></pre>
  
  <p><strong>AppDelegate.Swift</strong></p>
  
  <pre><code>class AppDelegate: UIResponder, UIApplicationDelegate {
  func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -&gt; Void) -&gt; Bool {
  
          // implement to handle user activity created by Siri or by our SiriExtension
          let viewController = self.window?.rootViewController as! PhotoViewController
          viewController.handleActivity(userActivity)
  
          return true
      }
  }
  </code></pre>
  
  <p><strong>PhotoViewController.swift</strong></p>
  
  <pre><code>class ViewController: UIViewController {
  
      @IBOutlet weak var imageView: UIImageView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          INPreferences.requestSiriAuthorization { (status) in
              print(status)
          }
      }
  
      func handleActivity(_ userActivity: NSUserActivity) {
  
          let intent = userActivity.interaction?.intent as! INSearchForPhotosIntent
  
          if (intent.dateCreated?.startDateComponents) != nil {
              let calendar = Calendar(identifier: .gregorian)
              let startDate = calendar.date(from:(intent.dateCreated?.startDateComponents)!)
  
              self.displayPhoto(startDate!)
          }
      }
  
  
      func displayPhoto(_ startDate: Date) {
  
          let fetchOptions = PHFetchOptions()
          fetchOptions.predicate = NSPredicate(format: "creationDate &gt;= %@", startDate as CVarArg)
          let fetchResult = PHAsset.fetchAssets(with:
              PHAssetMediaType.image, options: fetchOptions)
  
          let imgManager = PHImageManager.default()
  
          imgManager.requestImage(for: fetchResult.firstObject! as PHAsset,
                                  targetSize: view.frame.size,
                                  contentMode: PHImageContentMode.aspectFill,
                                  options: nil, 
                                  resultHandler: { (image, _) in
                                      self.imageView.image = image
          })
      }
  }
  </code></pre>
  
  <p>Now here comes the <strong>IntentViewController.swift</strong></p>
  
  <pre><code>class IntentViewController: UIViewController, INUIHostedViewControlling {
  
      @IBOutlet weak var imageView:UIImageView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view.
  
          INPreferences.requestSiriAuthorization { (status) in
              print("From IntentViewController: \(status)")
          }
      }
  
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(true)
          print("IntentViewController-&gt; viewDidLoad")
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      // MARK: - INUIHostedViewControlling
  
      // Prepare your view controller for the interaction to handle.
      func configure(with interaction: INInteraction!, context: INUIHostedViewContext, completion: ((CGSize) -&gt; Void)!) {
  
          print("From configure")
  
          let intent = interaction?.intent as! INSearchForPhotosIntent
  
          if (intent.dateCreated?.startDateComponents) != nil {
              let calendar = Calendar(identifier: .gregorian)
              let startDate = calendar.date(from:(intent.dateCreated?.startDateComponents)!)
              self.displayPhoto(startDate!)
          }
  
          if let completion = completion {
              completion(self.desiredSize)
          }
      }
  
      var desiredSize: CGSize {
          return self.extensionContext!.hostedViewMaximumAllowedSize
      }
  
      func displayPhoto(_ startDate: Date) {
  
          let fetchOptions = PHFetchOptions()
          fetchOptions.predicate = NSPredicate(format: "creationDate &gt;= %@", startDate as CVarArg)
          let fetchResult = PHAsset.fetchAssets(with:
              PHAssetMediaType.image, options: fetchOptions)
  
          let imgManager = PHImageManager.default()
  
          imgManager.requestImage(for: fetchResult.firstObject! as PHAsset,
                                  targetSize: view.frame.size,
                                  contentMode: PHImageContentMode.aspectFill,
                                  options: nil,
                                  resultHandler: { (image, _) in
                                      self.imageView.image = image
          })
      }
  }
  </code></pre>
  
  <p>Do I have to write any extra code inside the handle method of <em>IntentHandler.swift</em> file to show images using Intents UI? I don't wanna continue in the app actually I want results in the Intents UI. Thanks in advance.</p>