2016-06-13 5 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() 
関連する問題