이라도 인식 할 수없는 선택기인데 사용자를 위치로 탐색하는 앱을 만들기 위해 MapBoxNavigation.swift을 사용하고 있습니다. 네비게이션이 시작될 때까지 모든 것이 잘 작동합니다. 그러나 탐색이 시작 MapBoxNavigation.swift이 NSNotification
가 (어떻게 라이브러리 작품에 대한 설명서를 참조), 내가 쓴 옵서버이 오류 메시지를 던져 게시물 방출 때선택기의 이름이
app[49184:2686603] -[__NSCFConstantString navProgressDidChange:]: unrecognized selector sent to instance 0x1096dfdb0
이 코드가를 그 게시물 MapBoxNavigation의 통지입니다. SWIFT :
import Foundation
import UIKit
import Mapbox
import MapboxDirections
import MapboxNavigation
import CoreLocation
import Alamofire
import SWXMLHash
import DateTimePicker
//Primary ViewController, used for basically everything
class ViewController: UIViewController, MGLMapViewDelegate, CLLocationManagerDelegate, UITextFieldDelegate, UIGestureRecognizerDelegate {
lazy var geocoder = CLGeocoder()
@IBOutlet weak var addressTextField: SearchTextField! //SearchTextField
@IBOutlet var mapView: MGLMapView! //MapView of MapBox
@IBOutlet weak var BookingUIView: UIView!
@IBOutlet weak var BookingView: UIView!
//Used to geocode the Addresses
let locationManager = CLLocationManager()
var searched = false
var keyboardEnabled = false
var navigationStarted = false
//Getting the route object
let directions = Directions.shared
let waitForInterval: TimeInterval = 5
@IBOutlet weak var arrivalTimeLabel: UILabel!
@IBOutlet weak var arrivalTimeButton: UIButton!
@IBOutlet weak var leaveTimeButton: UIButton!
@IBOutlet weak var searchAddressButton: UIButton!
/* Overriding Super-Functions */
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// This is needed.... i don't know why..
mapView.delegate = self
//Delegate textField to Self
addressTextField.delegate = self
//Dismiss Keyboard on view Touch
//Looks for single or multiple taps.
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
self.mapView.addGestureRecognizer(tap)
//Delegate GestureRecognizer to self
tap.delegate = self
//Get the users current location and zoom to it
//Authorization stuff #privacy
self.locationManager.requestWhenInUseAuthorization()
//initialize the updating of the location
if(CLLocationManager.locationServicesEnabled()){
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
locationManager.startUpdatingLocation()
}
//Adding TextViewListener
addressTextField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
//Registering PresentNavigationViewControllerObserver :3
NotificationCenter.default.addObserver(self, selector: #selector(self.enableNavigationMode), name: NSNotification.Name(rawValue: "StartNavigation"), object: nil)
}
func enableNavigationMode(){
//Hiding some elements here
startNavigation() //Gets called properly
}
func navProgressDidChange(_ userInfo: NSNotification){
print("depart")
print(userInfo)
}
func startNavigation(){
//Get the JSON File via the MapBox API
var lat = locationManager.location?.coordinate.latitude
var long = locationManager.location?.coordinate.longitude
var depart = CLLocation(latitude: lat!, longitude: long!)
var start = Waypoint(coordinate: CLLocationCoordinate2D(latitude: lat!, longitude: long!))
var end = Waypoint(coordinate: CLLocationCoordinate2D(latitude: Shared.shared.selectedParkhouse.latitude, longitude: Shared.shared.selectedParkhouse.longitude))
var string = "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/" + String(describing: long!) + "%2C" + String(describing: lat!) + "%3B" + String(describing: Shared.shared.selectedParkhouse.longitude) + "%2C" + String(describing: Shared.shared.selectedParkhouse.latitude) + ".json?access_token=mykey;)&steps=true"
//Alamofire request works properly
Alamofire.request(string).responseData { response in
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
let jsoninput = self.convertToDictionary(text: utf8Text)!
let jsonroute = (jsoninput["routes"] as! [AnyObject]).first as! [String:Any]
let route = Route(json: jsonroute, waypoints: [start, end], profileIdentifier: MBDirectionsProfileIdentifierAutomobileAvoidingTraffic)
let routecontroller = RouteController(route: route)
print("regging")
NotificationCenter.default.addObserver(RouteControllerAlertLevelDidChange, selector: #selector(self.navProgressDidChange(_:)), name: RouteControllerAlertLevelDidChange, object: routecontroller)
print("resuming")
routecontroller.resume()
print("updating(?)")
//Everything is fine until this function gets called and
//MapBoxNavigation.swift posts a Notification
routecontroller.locationManager(routecontroller.locationManager, didUpdateLocations: [depart])
}
}
}
내가
NotificationCenter
몇 팀을 사용 :
NotificationCenter.default.post(name: RouteControllerAlertLevelDidChange, object: self, userInfo: [
RouteControllerAlertLevelDidChangeNotificationRouteProgressKey: routeProgress,
RouteControllerAlertLevelDidChangeNotificationDistanceToEndOfManeuverKey: userDistance,
RouteControllerProgressDidChangeNotificationIsFirstAlertForStepKey: isFirstAlertForStep
])
이 필요한 모든 코드가 있어야한다 이미 도움을 청하러오고 있어요. 또한 다른 코드의 함수 이름과 매개 변수를 navProgressDidChange(userInfo: Notification)
이상의 매개 변수에서 현재 내 코드에있는 매개 변수로 시도했습니다. 나는 이런 일이 일어나는 이유를 모르며, 선택자가 나에게 잘 보이기 때문에 내 마음에 이해가 가지 않는다.
더 많은 정보가 필요하면 질문하십시오. 이미 모든 답변 주셔서 감사합니다 !! 여기
'self'또는 'ViewController' (ClassName)없이 모두 시도 XCode는 함수를 직접 식별 할 수 없으므로 오류를보고합니다. 또한 앞에서'ViewController'를 사용하면 작동하지 않습니다. – njoye
이름은'ViewController'이고, 보내는 클래스는'RouteController'입니다. – njoye