ios - GMSAutoCompleteViewController 崩溃 - Swift 3
<p><p>我最近将我的应用程序升级到了 swift 3,每当它尝试调用谷歌地图中的自动完成 ViewController 时,它就会崩溃。我知道 apikey 不是问题,因为在我升级到 swift 3 和 xcode 8 之前使用它时它工作正常。我也知道这一点,因为该应用程序仍然能够显示谷歌地图。
这是我的代码:</p>
<pre><code>extension AdditionalSetupViewController: GMSAutocompleteViewControllerDelegate {
funcviewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
let locationCoordinate = place.coordinate
if homeClicked {
homeAddress =
}
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 =
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
let usersRef = ref.child("users/\(userID)")
usersRef.updateChildValues(additionalBasicInfo as )
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
}
}
</code></pre>
<p>这是错误输出:</p>
<pre><code>: unrecognized selector sent to instance 0x7fc4c8d7f200
2016-11-12 13:55:31.755 Pars2 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-: 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 - + 132
3 CoreFoundation 0x000000010687ac15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010687a798 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000104b095b8 - + 83
6 UIKit 0x0000000104c8eedd - + 67
7 UIKit 0x0000000104c8f1f6 - + 444
8 UIKit 0x0000000104c8e0f2 - + 668
9 UIKit 0x0000000104b76ce1 - + 2747
10UIKit 0x0000000104b783cf - + 4011
11UIKit 0x0000000104b2563f - + 371
12UIKit 0x000000010531771d __dispatchPreprocessedEventFromEventQueue + 3248
13UIKit 0x00000001053103c7 __handleEventQueue + 4879
14CoreFoundation 0x000000010689a311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15CoreFoundation 0x000000010687f59c __CFRunLoopDoSources0 + 556
16CoreFoundation 0x000000010687ea86 __CFRunLoopRun + 918
17CoreFoundation 0x000000010687e494 CFRunLoopRunSpecific + 420
18GraphicsServices 0x0000000108f02a6f GSEventRunModal + 161
19UIKit 0x0000000104b07964 UIApplicationMain + 159
20Pars2 0x00000001010a078f main + 111
21libdyld.dylib 0x00000001078d468d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
</code></pre>
<p>如果这可能有帮助,我不知道,但这里也是我的 ViewController 其余部分的代码:</p>
<pre><code>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: = []
@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)
}
}
</code></pre>
<p>我不知道为什么它在调用它时会崩溃,但我们将不胜感激!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>好吧,事实证明,GMS 自动完成 ViewController 工作正常,但这是一个导出问题。解决方案是简单地删除您拥有的当前 xcode 7 或以前版本的 socket ,然后创建一个新的 socket ,因为 socket 在 xcode 8 中略有不同。</p></p>
<p style="font-size: 20px;">关于ios - GMSAutoCompleteViewController 崩溃 - Swift 3,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/40568299/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/40568299/
</a>
</p>
页:
[1]