2016-06-13 3 views
2

내가 작업하고있는 응용 프로그램의 스냅 샷을 구성 하려는데 이미 영어 버전에서 작동하지만 현지화 된 버전에서는 접근성 식별자를 할당하는 방법을 모르겠습니다. MKMapView의 Map 핀에, 누군가는 이것을 어떻게 해야할지 알고 있습니까?MKMapView 객체에 접근성 식별자 할당

감사합니다.

답변

3

접근성 식별자는 응용 프로그램의 언어를 Xcode UI 테스트와 구분하는 좋은 방법입니다. 식별자는 UIView이 이미 준수하는 UIAccessibilityIdentification에서옵니다. 그러나 NSObjectMKAnnotation도 프로토콜을 준수하지 않습니다. 따라서 당신은 당신 자신의 적합성을 설정해야합니다.

class Annotation: NSObject, MKAnnotation, UIAccessibilityIdentification { 
    let coordinate: CLLocationCoordinate2D 
    let title: String? 
    var accessibilityIdentifier: String? 

    init(title: String?, coordinate: CLLocationCoordinate2D) { 
     self.title = title 
     self.coordinate = coordinate 
    } 
} 

let coordinate = CLLocationCoordinate2DMake(40.703490, -73.987770) 
let annotation = Annotation(title: "BeerMenus HQ", coordinate: coordinate) 
annotation.accessibilityIdentifier = "Custom Identifier" 
let mapView = MKMapView() 
mapView.addAnnotation(annotation) 

그러면 테스트를 통해 otherElements을 통해 특수 효과를 참조 할 수 있습니다.

let app = XCUIApplication() 
let annotation = app.maps.element.otherElements["Custom Identifier"] 
annotation.tap()