Cannot load module 'visionKit' as 'VisionKit' - ios

Im trying to build a simple app to scan documents, but faced this error when trying to import VisionKit module, how can i solve this error ?
My code:
import UIKit
import VisionKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
#IBAction func openCameraButtonTaped(_ sender: Any) {
configureDocumentView()
}
private func configureDocumentView() {
let scaningDocumentViewController = VNDocumentCameraViewController()
scaningDocumentViewController.delegate = self
self.present(scaningDocumentViewController, animated: true, completion: nil)
}
}
extension ViewController: VNDocumentCameraViewControllerDelegate {
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
for pageNum in 0..<scan.pageCount {
let image = scan.imageOfPage(at: pageNum)
print(image)
}
controller.dismiss(animated: true, completion: nil)
}
}

You are giving a hard time for the compiler, your project name conflicts with Apple's VisionKit. Create a new your project with a different name.

Related

How to make initial view controller present again in iOS?

I have an app that uses a main screen (below) and then a barcode scanner framework to scan in a barcode and then I will code an action to perform. However, the problem I am having is that in the code it takes me back to the scanning screen. I have tried to use present(VC1, animated: true, completion: nil) and it does not know what VC1 is.
I assigned VC1 in Xcode under storyboard id (see below):
Below is my code here for view controller.swift. Now the code takes you back to the scanning screen, but I want to go back to VC1 the main view controller.
import UIKit
import BarcodeScanner
var presentedViewController: UIViewController?
final class ViewController: UIViewController {
#IBOutlet var pushScannerButton: UIButton!
//Present view and handle barcode scanning
#IBAction func handleScannerPush(_ sender: Any, forEvent event: UIEvent) {
let viewController = makeBarcodeScannerViewController()
viewController.title = "Barcode Scanner"
present(viewController, animated: true, completion: nil)
}
private func makeBarcodeScannerViewController() -> BarcodeScannerViewController {
let viewController = BarcodeScannerViewController()
viewController.codeDelegate = self
viewController.errorDelegate = self
viewController.dismissalDelegate = self
return viewController
}
}
// MARK: - BarcodeScannerCodeDelegate
extension ViewController: BarcodeScannerCodeDelegate {
func scanner(_ controller: BarcodeScannerViewController, didCaptureCode code: String, type: String) {
print("Barcode Data: \(code)")
print("Symbology Type: \(type)")
controller.dismiss(animated: true, completion: nil)
// DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
// controller.resetWithError()
// }
}
}
// MARK: - BarcodeScannerErrorDelegate
extension ViewController: BarcodeScannerErrorDelegate {
func scanner(_ controller: BarcodeScannerViewController, didReceiveError error: Error) {
print(error)
}
}
// MARK: - BarcodeScannerDismissalDelegate
extension ViewController: BarcodeScannerDismissalDelegate {
func scannerDidDismiss(_ controller: BarcodeScannerViewController) {
controller.dismiss(animated: true, completion: nil)
}
}

firebase authentication ios use of unresolved identifier 'handle'

I'm trying to follow this tutorial for Firebase authentication.. I kinda just followed the code but keep having the Use of unresolved identifier 'handle' error.
Code:
import UIKit
import Firebase
import FirebaseAuth
class SignInViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
handle = Auth.auth().addStateDidChangeListener { (auth, user) in // ERROR HERE
// ...
}
}
override func viewWillDisappear(_ animated: Bool) {
Auth.auth().removeStateDidChangeListener(handle!) // ERROR HERE
}
}
Any clue what I should do? Thanks!
#IBAction func createAccount(_ sender: Any) {
let emailTextD = self.emailText.text!
let passwordTextD = self.passwordText.text
Auth.auth().createUser(withEmail: emailTextD, password: passwordTextD!) { (authResult, error) in
// ...
}
}
Add the variable declaration into the class like this:
var handle: AuthStateDidChangeListenerHandle?

Make static cell in tableviewcontroller bring up composed mail when pressed

I would like to make the "Leave a Suggestion" static cell open the mail and allow me to compose a message with a set subject. How would I accomplish this?
EDIT:
import UIKit
import MessageUI
class AccountViewController: UITableViewController, MFMailComposeViewControllerDelegate {
#IBOutlet var Logout: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
#IBAction func emailButtonAction(_ sender: UIButton) {
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(["example#gmail.com"])
mail.setSubject("Example Subject")
mail.setMessageBody("<p>Test</p>", isHTML: true)
present(mail, animated: true)
}
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true)
}
}
UIButton does not work with any of my cells

Swift google autocomplete with local search

I am trying to do Google Autocomplete using Google Places in Swift 3.0. But I need to search depending upon my current location. Example, If I am in Kolkata, India and I type search keyword "Ko" it will show the results of Kolkata first .
Can anyone help me.
Here is my code.I import GooglePlaces in my class
#IBAction func txtFieldLocationDidStartEditing(_ sender: Any) {
self.placeAutocomplete()
}
func placeAutocomplete() {
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self
present(autocompleteController, animated: true, completion: nil)
}
// MARK: - autoComplete Delegates
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
print("Place name: \(place.name)")
dismiss(animated: true, completion: nil)
}
func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
// TODO: handle the error.
print("Error: ", error.localizedDescription)
}
// User canceled the operation.
func wasCancelled(_ viewController: GMSAutocompleteViewController) {
dismiss(animated: true, completion: nil)
}
// Turn the network activity indicator on and off again.
func didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = true
}
func didUpdateAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}
Please anyone help me to solve it out.
Thanks in advance.
The only API provided by GMSAutocompleteViewController is to set the GMSCoordinateBounds like so (reference):
func placeAutocomplete() {
let visibleRegion = mapView.projection.visibleRegion()
let bounds = GMSCoordinateBounds(coordinate: visibleRegion.farLeft, coordinate: visibleRegion.nearRight)
let autocompleteController = GMSAutocompleteViewController()
acController.autocompleteBounds = bounds
autocompleteController.delegate = self
present(autocompleteController, animated: true, completion: nil)
}

ios Swift - API GoogleMaps - not conform protocol GSMAutocompleteViewControllerDelegate

I'm trying to use API GoogleMaps in an ios app to make an auto-completion, but I can't get my hand on the problem, I search for it but it seems I'm the only one to have it.
MyViewController doesn't conform to protocol GSMAutocompleteViewControllerDelegate
class MyViewController: UIViewController {
#IBAction func onLaunchClicked(sender: AnyObject) {
let acController = GMSAutocompleteViewController()
acController.delegate = self
self.presentViewController(acController, animated: true, completion: nil)
}
}
extension MyViewController: GMSAutocompleteViewControllerDelegate {
func viewController(viewController: GMSAutocompleteViewController!, didAutocompleteWithPlace place: GMSPlace!) {
// The user has selected a place.
self.dismissViewControllerAnimated(true, completion: nil)
}
func viewController(viewController: GMSAutocompleteViewController!, didAutocompleteWithError error: NSError!) {
self.dismissViewControllerAnimated(true, completion: nil)
}
func wasCancelled(viewController: GMSAutocompleteViewController!) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}
It seems like I don't have all the protocol required, but can't get my hand on it.
Thanks for helping :)
Try adding:
func viewController(viewController: GMSAutocompleteViewController!, didFailAutocompleteWithError error: NSError!) {
}

Resources