gpt4 book ai didi

ios - GMSAutoCompleteViewController 崩溃 - Swift 3

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:27:05 25 4
gpt4 key购买 nike

我最近将我的应用程序升级到 swift 3,每当它尝试调用谷歌地图中的自动完成 View Controller 时,它就会崩溃。我知道 api key 不是问题,因为在我升级到 swift 3 和 xcode 8 之前使用它时它工作正常。我也知道这一点,因为该应用程序仍然能够显示谷歌地图。这是我的代码:

extension AdditionalSetupViewController: GMSAutocompleteViewControllerDelegate {

func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
let locationCoordinate = place.coordinate

if homeClicked {
homeAddress = [locationCoordinate.latitude, locationCoordinate.longitude]
}

else if homeAddress == [] {
}

else {

let coordString = "\(locationCoordinate.latitude) \(locationCoordinate.longitude)".replacingOccurrences(of: ".", with: ",")

// let coordString = "\(locationCoordinate.latitude) \(locationCoordinate.longitude)".stringByReplacingOccurrencesOfString(".", withString: ",")

ref = FIRDatabase.database().reference()

let currentUser: String = (FIRAuth.auth()?.currentUser?.uid)!
let address = ref.child("schoolOrWorkAddress").child(coordString)
let childUpdates = [currentUser: homeAddress]
address.updateChildValues(childUpdates)

finishButton.alpha = 1
finishButton.isEnabled = true
}

let schoolorWorkCoords = "\(locationCoordinate.latitude) \(locationCoordinate.longitude)".replacingOccurrences(of: ".", with: ",")

// let schoolorWorkCoords = "\(locationCoordinate.latitude) \(locationCoordinate.longitude)".stringByReplacingOccurrencesOfString(".", withString: ",")
let userID = (FIRAuth.auth()?.currentUser?.uid)!
_ = ref.child("posts").child(userID).key
let additionalBasicInfo = ["schoolOrWorkAddress": schoolorWorkCoords, "homeAddress": homeAddress] as [String : Any]
let usersRef = ref.child("users/\(userID)")
usersRef.updateChildValues(additionalBasicInfo as [NSObject : AnyObject])

self.dismiss(animated: true, completion: nil)

}


func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
print(error)
}

func wasCancelled(_ viewController: GMSAutocompleteViewController) {
self.dismiss(animated: true, completion: nil)
}

func didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = true
}

func didUpdateAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}

}

这是错误输出:

[Pars2.AdditionalSetupViewController addYourSchoolOrWorkAddress:]: unrecognized selector sent to instance 0x7fc4c8d7f200
2016-11-12 13:55:31.755 Pars2[3065:191093] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Pars2.AdditionalSetupViewController addYourSchoolOrWorkAddress:]: unrecognized selector sent to instance 0x7fc4c8d7f200'
*** First throw call stack:
(
0 CoreFoundation 0x00000001068f534b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010635621e objc_exception_throw + 48
2 CoreFoundation 0x0000000106964f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010687ac15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010687a798 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000104b095b8 -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x0000000104c8eedd -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000104c8f1f6 -[UIControl _sendActionsForEvents:withEvent:] + 444
8 UIKit 0x0000000104c8e0f2 -[UIControl touchesEnded:withEvent:] + 668
9 UIKit 0x0000000104b76ce1 -[UIWindow _sendTouchesForEvent:] + 2747
10 UIKit 0x0000000104b783cf -[UIWindow sendEvent:] + 4011
11 UIKit 0x0000000104b2563f -[UIApplication sendEvent:] + 371
12 UIKit 0x000000010531771d __dispatchPreprocessedEventFromEventQueue + 3248
13 UIKit 0x00000001053103c7 __handleEventQueue + 4879
14 CoreFoundation 0x000000010689a311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x000000010687f59c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x000000010687ea86 __CFRunLoopRun + 918
17 CoreFoundation 0x000000010687e494 CFRunLoopRunSpecific + 420
18 GraphicsServices 0x0000000108f02a6f GSEventRunModal + 161
19 UIKit 0x0000000104b07964 UIApplicationMain + 159
20 Pars2 0x00000001010a078f main + 111
21 libdyld.dylib 0x00000001078d468d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

我不知道这是否有帮助,但这里还有我的 View Controller 其余部分的代码:

class AdditionalSetupViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {


override func viewDidLoad() {
finishButton.alpha = 0.4
finishButton.isEnabled = false

navigationController?.navigationBar.barTintColor = UIColor(red: 46, green: 204, blue: 113, alpha: 0)
}


@IBOutlet weak var mapView : GMSMapView!
var homeClicked = false
var homeAddress: [Double] = []

@IBAction func addYourHomeAddress(sender: AnyObject) {
homeClicked = true
createGMSViewController()
}

@IBAction func addYourSchoolOrWorkAddress(sender: AnyObject) {
homeClicked = false
createGMSViewController()
}

func createGMSViewController() {
let searchAutoCompleteController = GMSAutocompleteViewController()
searchAutoCompleteController.delegate = self
self.present(searchAutoCompleteController, animated: true, completion: nil)
}

@IBOutlet weak var finishButton: UIButton!

@IBAction func finishButton(sender: AnyObject) {

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

let nextViewController = storyBoard.instantiateViewController(withIdentifier: "TableView") as! UITabBarController
self.present(nextViewController, animated:true, completion:nil)

}


}

我不知道为什么它在调用它时会崩溃,但我们将不胜感激!

最佳答案

好吧,事实证明,GMS 自动完成 View Controller 工作正常,而不是 socket 问题。解决方案是简单地删除当前的 xcode 7 或您拥有的先前版本的 socket ,然后创建一个新的 socket ,因为 xcode 8 中的 socket 略有不同。

关于ios - GMSAutoCompleteViewController 崩溃 - Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40568299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com