1

我正在尝试使用此单元测试在 iOS 13 beta 上获取 MKMapItem.pointOfInterestCategory:

func testPointOfInterests() {

    let request = MKLocalSearch.Request()
    let mkSearchExpectation = expectation(description: "MKLocalSearch")

    // Sagrada Família, Barcelone
    let coordinate = CLLocationCoordinate2D(latitude: 41.40359499, longitude: 2.17436157)
    request.region = MKCoordinateRegion.init(center: coordinate, latitudinalMeters: 1000, longitudinalMeters: 1000)
    request.naturalLanguageQuery = "Sagrada Família"
    if #available(iOS 13.0, *) {
        request.pointOfInterestFilter = MKPointOfInterestFilter(excluding: [.atm])
    }
    let search = MKLocalSearch(request: request)
    search.start { (response, error) in
        mkSearchExpectation.fulfill()
        XCTAssertNil(error)
        XCTAssertNotNil(response)
        guard let response = response else {
            return
        }

        for mapItem in response.mapItems {
            dump(mapItem)
            if #available(iOS 13.0, *) {
                if let category = mapItem.pointOfInterestCategory {
                    print(category)
                }
            }
        }


    }

    waitForExpectations(timeout: 10.0) {
        error in
        if let error = error {
            XCTFail(error.localizedDescription)
        }
    }

}

我得到一个相关的 mapItem,但 MKMapItem.pointOfInterestCategory 为零。

使用 Apples Maps 应用程序进行的类似测试表明,Apples 服务器知道巴塞罗那的圣家堂是一座教堂。

我究竟做错了什么?我想让 pointOfInterestCategory 在 iOS 13 beta 上运行。

4

0 回答 0