簡體   English   中英

在設備上運行時,GMSPlace Picker中的應用程序崩潰。(iOS 8.3)

[英]App Crash in GMSPlace Picker while running on device.(iOS 8.3)

我正在使用以下代碼按照Google的建議選擇位置

https://developers.google.com/places/ios-api/placepicker

    var placePicker: GMSPlacePicker?

    override func viewDidLoad()
    {
        super.viewDidLoad()
        self.pickPlace()
    }

  func pickPlace()
    {
        let center = CLLocationCoordinate2DMake(51.5108396, -0.0922251)
        let northEast = CLLocationCoordinate2DMake(center.latitude + 0.001, center.longitude + 0.001)
        let southWest = CLLocationCoordinate2DMake(center.latitude - 0.001, center.longitude - 0.001)
        let viewport = GMSCoordinateBounds(coordinate: northEast, coordinate: southWest)
        let config = GMSPlacePickerConfig(viewport: viewport)
        placePicker = GMSPlacePicker(config: config)

        placePicker?.pickPlaceWithCallback({ (place: GMSPlace?, error: NSError?) -> Void in
            if let error = error
            {
                print("Pick Place error: \(error.localizedDescription)")
                return
            }

            if let place = place
            {
                print("Place name \(place.name)")
                print("Place address \(place.formattedAddress)")
                print("Place attributions \(place.attributions)")
                self.navigationController?.popToRootViewControllerAnimated(true)


            } else
            {
                print("No place selected")
            }
        })
    }

在此處輸入圖片說明 此代碼的問題是它可以在模擬器上完美運行,但是在設備iOS 8.3上崩潰而沒有給出任何消息

將NSError更改為Error

placePicker?.pickPlaceWithCallback({ (place: GMSPlace?, error: Error?)

將它們都導入AppDelegate類中

import GoogleMaps
import GooglePlaces

並且,您需要在didFinishLaunchingWithOptions中同時設置它們

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        GMSServices.provideAPIKey("Your key")
        GMSPlacesClient.provideAPIKey("Your key")

        return true
    }

只有在模擬器中對其進行測試后,我才能使用設備看到錯誤消息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM