• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - GMSAutoCompleteViewController 崩溃 - Swift 3

[复制链接]
菜鸟教程小白 发表于 2022-12-12 22:48:04 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我最近将我的应用程序升级到了 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)

    }


}

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



Best Answer-推荐答案


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

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

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap