我正在开发一款应用,并将GoogleMaps和GooglePlaces SDK集成到其中。当我在基于iOS 10的设备上打开它时,单击搜索栏会使应用程序崩溃。我还添加了GMSAutocompleteResultsViewController。我附上了代码
var mapView: GMSMapView?
var resultsViewController: GMSAutocompleteResultsViewController?
var searchController: UISearchController?
override func viewDidLoad() {
super.viewDidLoad()
mapView = GMSMapView()
mapView.frame = CGRectMake(0, 0, width, height)
mapView.mapType = kGMSTypeNormal
self.view.addSubview(mapView)
mapView.delegate = self
resultsViewController = GMSAutocompleteResultsViewController()
resultsViewController?.delegate = self
searchController = UISearchController(searchResultsController: resultsViewController)
searchController?.searchResultsUpdater = resultsViewController
searchController!.view.frame = CGRectMake(0, 0, width, height)
let subView = UIView(frame: CGRectMake(0, 0, width, 45.0))
subView.addSubview((searchController?.searchBar)!)
self.view.addSubview(subView)
searchController?.hidesNavigationBarDuringPresentation = false
searchController?.modalPresentationStyle = UIModalPresentationStyle.Popover
self.definesPresentationContext = true
searchController?.searchBar.delegate = self
}
extension ViewController: GMSAutocompleteResultsViewControllerDelegate {
func resultsController(resultsController: GMSAutocompleteResultsViewController, didAutocompleteWithPlace place: GMSPlace) {
searchController?.active = false
mapView.animateToLocation(place.coordinate)
}
func resultsController(resultsController: GMSAutocompleteResultsViewController, didFailAutocompleteWithError error: NSError){
print("Error: ", error.description)
}
func didRequestAutocompletePredictions(viewController: GMSAutocompleteViewController) {
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
}
func didUpdateAutocompletePredictions(viewController: GMSAutocompleteViewController) {
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
}
}
extension ViewController: UISearchBarDelegate {
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
searchBar.resignFirstResponder()
}
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
searchBar.resignFirstResponder()
searchController?.active = false
}
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
let doneBtn = self.navigationItem.rightBarButtonItem
doneBtn?.enabled = false
}
func searchBarTextDidEndEditing(searchBar: UISearchBar) {
let doneBtn = self.navigationItem.rightBarButtonItem
doneBtn?.enabled = true
}
}
每当我点击searchBar时,应用程序会在输入任何字符时崩溃。我没有看到任何结果,甚至不能输入单个单词。我得到的错误是
* thread #1: tid = 0x43622b, 0x1ca0f050 libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2
* thread #1: tid = 0x4382b9, 0x1ca0f050 libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2
* frame #0: 0x1ca0f050 libobjc.A.dylib`objc_exception_throw
frame #1: 0x1d7a9d4c CoreFoundation`+[NSException raise:format:] + 108
frame #2: 0x00933772 AppName`+[GMSPlacesClient sharedClient] + 122
frame #3: 0x0092f702 AppName`-[GMSAutocompleteFetcher requestAutocompleteResultsWithText:] + 202
frame #4: 0x0092f55a AppName`-[GMSAutocompleteFetcher sendOrDelayRequest:] + 82
frame #5: 0x0092f4fa AppName`-[GMSAutocompleteFetcher sourceTextHasChanged:] + 82
frame #6: 0x0093ad6a AppName`-[GMSAutocompleteTableDataSource sourceTextHasChanged:] + 234
frame #7: 0x00943d7e AppName`-[GMSAutocompleteResultsViewController updateSearchResultsForSearchController:] + 202
frame #8: 0x2321d736 UIKit`-[UISearchController _searchBar:textDidChange:] + 84
frame #9: 0x229e202a UIKit`-[UISearchBar(UISearchBarStatic) _searchFieldEditingChanged] + 268
frame #10: 0x22823b5c UIKit`-[UIApplication sendAction:to:from:forEvent:] + 76
frame #11: 0x22823aea UIKit`-[UIControl sendAction:to:forEvent:] + 62
frame #12: 0x2280dc86 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 470
frame #13: 0x229e1da8 UIKit`-[UITextField fieldEditorDidChange:] + 218
frame #14: 0x2282dd02 UIKit`-[UITextInputController _sendDelegateChangeNotificationsForText:selection:] + 122
frame #15: 0x229b2c7a UIKit`-[UITextInputController _insertText:fromKeyboard:] + 822
frame #16: 0x229b2008 UIKit`-[UITextInputController insertText:] + 406
frame #17: 0x22b3d142 UIKit`-[UIFieldEditor insertFilteredText:] + 540
frame #18: 0x231da3f0 UIKit`-[UITextField insertFilteredText:] + 96
frame #19: 0x229b1d98 UIKit`-[UIKeyboardImpl insertText:] + 136
frame #20: 0x22bf6e94 UIKit`-[UIKeyboardImpl performKeyboardOutput:] + 524
frame #21: 0x22bf6ab6 UIKit`__55-[UIKeyboardImpl handleKeyboardInput:executionContext:]_block_invoke_2 + 334
frame #22: 0x2281831a UIKit`-[UIKeyboardTaskQueue continueExecutionOnMainThread] + 400
frame #23: 0x1e0cb3da Foundation`__NSThreadPerformPerform + 386
frame #24: 0x1d765c8a CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
frame #25: 0x1d765794 CoreFoundation`__CFRunLoopDoSources0 + 438
frame #26: 0x1d763a6a CoreFoundation`__CFRunLoopRun + 762
frame #27: 0x1d6b3072 CoreFoundation`CFRunLoopRunSpecific + 486
frame #28: 0x1d6b2e80 CoreFoundation`CFRunLoopRunInMode + 104
frame #29: 0x1ee5bbfc GraphicsServices`GSEventRunModal + 156
frame #30: 0x22859cce UIKit`-[UIApplication _run] + 574
frame #31: 0x22854400 UIKit`UIApplicationMain + 150
frame #32: 0x00232110 AppName`main + 172 at AppDelegate.swift:28
frame #33: 0x1ce7e50a libdyld.dylib`start + 2
该项目使用Swift 2.3在Xcode 8上。
我不知道为什么我收到此错误而无法解决此错误。请仔细研究一下。任何帮助将不胜感激。
答案 0 :(得分:1)
替换以下内容:
旧:
#import <GoogleMaps/GooglePlaces.h>
[GMSServices provideAPIKey:GoogleAPIKey]
更新了工作代码:
@import GooglePlaces;
[GMSPlacesClient provideAPIKey:GoogleAPIKey];
最新的SDK指向GooglePlaces / GooglePlaces.h,而不是GoogleMaps / GooglePlaces.h 检查此链接: https://developers.google.com/places/migrate-to-v2
答案 1 :(得分:0)
objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2
有些异常断点似乎是由GoogleMaps或GooglePlaces SDK的部分内容触发的,当您点击搜索栏时就会显而易见。
禁用所有异常的异常断点。