                 self.completion(nil)
             })
         }
-
+        
+        cameraRoll.tap = importCameraRoll
         addCameraPreview()
     }
 
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
+        
+        //Animate guide on appear
         UIView.spring(0.8, animations: {
             self.guide.transform = .identity
         }, completion: { _ in })
     }
     
-    @available(iOS 11.0, *)
     override func viewSafeAreaInsetsDidChange() {
         toolbarHeightConstraint?.constant = toolbarHeight + view.safeAreaInsets.bottom
     }

            }
        }
    }

    override var prefersStatusBarHidden: Bool {
        return true

        }
    }
}

//Image Picker Delegate
extension ScanViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
        picker.dismiss(animated: true, completion: nil)
        var newImage: UIImage
        if let possibleImage = info[.editedImage] as? UIImage {
            newImage = possibleImage
        } else if let possibleImage = info[.originalImage] as? UIImage {
            newImage = possibleImage
        } else {
            return
        }

        if let features = detectQRCode(newImage), !features.isEmpty {
            for case let row as CIQRCodeFeature in features {
                if let message = row.messageString {
                    DispatchQueue.main.async { [weak self] in
                        self?.handleURI(message)
                    }
                }
            }
        }
    }
    
    func detectQRCode(_ image: UIImage?) -> [CIFeature]? {
        //sourced: https://stackoverflow.com/questions/35956538/how-to-read-qr-code-from-static-image
        if let image = image, let ciImage = CIImage.init(image: image) {
            var options: [String: Any]
            let context = CIContext()
            options = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
            let qrDetector = CIDetector(ofType: CIDetectorTypeQRCode, context: context, options: options)
            if ciImage.properties.keys.contains((kCGImagePropertyOrientation as String)) {
                options = [CIDetectorImageOrientation: ciImage.properties[(kCGImagePropertyOrientation as String)] ?? 1]
            } else {
                options = [CIDetectorImageOrientation: 1]
            }
            let features = qrDetector?.features(in: ciImage, options: options)
            return features

        }
        return nil
    }
}
