From 296b25da5d135bf08d9d5a7cddfcff1c42ab1d28 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Fri, 16 Jun 2023 13:41:26 +0300 Subject: [PATCH 01/31] Removed `acceptedTypes` from the AddressAutofill query --- Sources/Demo/AddressAutofillResultViewController.swift | 7 +++---- .../Use Cases/Address Autofill/AddressAutofill.swift | 6 ------ .../Address Autofill/AddressAutofill+Tests.swift | 10 +++------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/Sources/Demo/AddressAutofillResultViewController.swift b/Sources/Demo/AddressAutofillResultViewController.swift index 5307ec0e9..45f940aaa 100644 --- a/Sources/Demo/AddressAutofillResultViewController.swift +++ b/Sources/Demo/AddressAutofillResultViewController.swift @@ -184,15 +184,14 @@ private extension AddressAutofillResultViewController { if let first = suggestions.first { self.addressAutofill.select(suggestion: first) { [weak self] result in guard let self = self else { return } - - if case .success = result { + + if case let .success(suggestionResult) = result { + self.result = suggestionResult self.updateViewState(to: .result) } else { self.updateViewState(to: .empty) } } - - self.updateViewState(to: .result) } else { self.updateViewState(to: .empty) } diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift index 28e542f95..19e94df4e 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift @@ -65,7 +65,6 @@ public extension AddressAutofill { countries: options?.countries.map { $0.countryCode }, languages: options.map { [$0.language.languageCode] }, limit: Constants.defaultSuggestionsLimit, - filterTypes: acceptedTypes, ignoreIndexableRecords: true ).toCore(apiType: Self.apiType) @@ -81,7 +80,6 @@ public extension AddressAutofill { let searchOptions = ReverseGeocodingOptions( point: coordinate, - types: acceptedTypes, countries: options?.countries.map { $0.countryCode }, languages: options.map { [$0.language.languageCode] } ).toCore() @@ -151,10 +149,6 @@ private extension AddressAutofill { // MARK: - Text query private extension AddressAutofill { - var acceptedTypes: [SearchQueryType] { - [.country, .region, .postcode, .district, .place, .locality, .neighborhood, .address, .street, .poi] - } - func fetchSuggestions(for query: String, with options: CoreSearchOptions, completion: @escaping (Swift.Result<[Suggestion], Error>) -> Void) { searchEngine.search( forQuery: query, diff --git a/Tests/MapboxSearchTests/Use Cases/Address Autofill/AddressAutofill+Tests.swift b/Tests/MapboxSearchTests/Use Cases/Address Autofill/AddressAutofill+Tests.swift index 23f25adb5..825462715 100644 --- a/Tests/MapboxSearchTests/Use Cases/Address Autofill/AddressAutofill+Tests.swift +++ b/Tests/MapboxSearchTests/Use Cases/Address Autofill/AddressAutofill+Tests.swift @@ -30,10 +30,8 @@ final class AddressAutofillTests: XCTestCase { func testThatCorrectAcceptedTypesAreUsedForSuggestionsByQuery() { addressAutofill.suggestions(for: .init(value: "query")!) { _ in } - - let acceptedTypes: [SearchQueryType] = [.country, .region, .postcode, .district, .place, .locality, .neighborhood, .address, .street, .poi] - - XCTAssertEqual(searchEngine.searchOptions?.types, acceptedTypes.map { NSNumber(value: $0.coreValue.rawValue) }) + + XCTAssertNil(searchEngine.searchOptions!.types) } func testThatDefaultOptionsArePassedForSuggestionsByQuery() { @@ -63,9 +61,7 @@ final class AddressAutofillTests: XCTestCase { func testThatCorrectAcceptedTypesAreUsedForSuggestionsByCoordinate() { addressAutofill.suggestions(for: kCLLocationCoordinate2DInvalid) { _ in } - let acceptedTypes: [SearchQueryType] = [.country, .region, .postcode, .district, .place, .locality, .neighborhood, .address, .street, .poi] - - XCTAssertEqual(searchEngine.reverseGeocodingOptions?.types, acceptedTypes.map { NSNumber(value: $0.coreValue.rawValue) }) + XCTAssertNil(searchEngine.reverseGeocodingOptions!.types) } func testThatDefaultOptionsArePassedForSuggestionsByCoordinate() { From 0c7e6f205de858fac8db094cd80917168f6ff45e Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Fri, 16 Jun 2023 15:35:59 +0300 Subject: [PATCH 02/31] Added default types parameter for the `PlaceAutocomplete` options to be `POI`. --- .../Place Autocomplete/Models/PlaceAutocomplete+Options.swift | 2 +- .../Place Autocomplete/PlaceAutocomplete.Options+Tests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Options.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Options.swift index fa0748fe2..bed52a8b0 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Options.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Options.swift @@ -25,7 +25,7 @@ public extension PlaceAutocomplete { public init( countries: [Country] = [], language: Language? = nil, - types: [PlaceType] = [], + types: [PlaceType] = [.POI], navigationProfile: SearchNavigationProfile? = nil ) { self.countries = countries diff --git a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Options+Tests.swift b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Options+Tests.swift index 17cb95aa4..175257697 100644 --- a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Options+Tests.swift +++ b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Options+Tests.swift @@ -9,7 +9,7 @@ final class PlaceAutocompleteOptionsTests: XCTestCase { XCTAssertTrue(options.countries.isEmpty) XCTAssertEqual(options.language, .default) - XCTAssertTrue(options.types.isEmpty) + XCTAssertEqual(options.types, [.POI]) } func testThatOptionsInitializedWithCountries() { From df8c89ab7e18e8dda3d6009f32f44b751be1b879 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Fri, 16 Jun 2023 15:39:06 +0300 Subject: [PATCH 03/31] Updated Changelog --- CHANGELOG.md | 6 ++++++ .../AdministrativeUnits.swift | 4 ++++ .../Models/PlaceAutocomplete+Options.swift | 2 +- .../Models/PlaceAutocomplete+PlaceType.swift | 4 ++++ .../Place Autocomplete/PlaceAutocomplete.swift | 17 +++++++++++++++-- .../OfflineIntegrationTests.swift | 1 - .../PlaceAutocomplete.Options+Tests.swift | 3 ++- .../PlaceAutocompleteTests.swift | 18 ++++++++++++++++-- 8 files changed, 48 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a295a2258..93f988a90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ Guide: https://keepachangelog.com/en/1.0.0/ --> +## Unreleased + +### Fixed +- [Place Autocomplete]: request all possible `PlaceType` values in case if types were not specified in a search query options. +- [Address Autofill]: fixed reverse geocoding query, removed unsupported types from query. + ## 1.0.0-rc.4 - 2023-05-19 ### Added diff --git a/Sources/MapboxSearch/PublicAPI/Common/Models/Administrative Unit/AdministrativeUnits.swift b/Sources/MapboxSearch/PublicAPI/Common/Models/Administrative Unit/AdministrativeUnits.swift index a0dcda2e5..a87138948 100644 --- a/Sources/MapboxSearch/PublicAPI/Common/Models/Administrative Unit/AdministrativeUnits.swift +++ b/Sources/MapboxSearch/PublicAPI/Common/Models/Administrative Unit/AdministrativeUnits.swift @@ -51,4 +51,8 @@ public struct AdministrativeUnit: Equatable { /// Japanese administrative unit analogous to `neighborhood`. /// - Note: Not available for reverse geocoding requests. public static let chome: AdministrativeUnit = .init(rawValue: .neighborhood) + + public static var all: [AdministrativeUnit] { + [.country, .region, .postcode, .district, .place, .locality, .neighborhood, .street, .address, .city, prefecture, .oaza, chome] + } } diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Options.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Options.swift index bed52a8b0..fa0748fe2 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Options.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Options.swift @@ -25,7 +25,7 @@ public extension PlaceAutocomplete { public init( countries: [Country] = [], language: Language? = nil, - types: [PlaceType] = [.POI], + types: [PlaceType] = [], navigationProfile: SearchNavigationProfile? = nil ) { self.countries = countries diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+PlaceType.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+PlaceType.swift index f9e496cc1..517b8ccf5 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+PlaceType.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+PlaceType.swift @@ -9,6 +9,10 @@ public extension PlaceAutocomplete { case POI case administrativeUnit(AdministrativeUnit) + public static var allTypes: [PlaceType] { + [.POI] + AdministrativeUnit.all.map(PlaceType.administrativeUnit) + } + var coreType: SearchQueryType { switch self { case .POI: return .poi diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift index 2c7527518..dda241800 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift @@ -75,6 +75,13 @@ public extension PlaceAutocomplete { if let navigationProfiler = options.navigationProfile { navigationOptions = .init(profile: navigationProfiler, etaType: .navigation) } + + // We should not leave core types list empty or null in order to avoid unsupported types being requested + var filterTypes = options.types + if filterTypes.isEmpty { + filterTypes = PlaceType.allTypes + } + let searchOptions = SearchOptions( countries: options.countries.map { $0.countryCode }, languages: [options.language.languageCode], @@ -83,7 +90,7 @@ public extension PlaceAutocomplete { boundingBox: region, origin: proximity, navigationOptions: navigationOptions, - filterTypes: options.types.isEmpty ? nil : options.types.map { $0.coreType }, + filterTypes: filterTypes.map { $0.coreType }, ignoreIndexableRecords: true ).toCore(apiType: Self.apiType) @@ -102,9 +109,15 @@ public extension PlaceAutocomplete { ) { userActivityReporter.reportActivity(forComponent: "place-autocomplete-reverse-geocoding") + // We should not leave core types list empty or null in order to avoid unsupported types being requested + var filterTypes = options.types + if filterTypes.isEmpty { + filterTypes = PlaceType.allTypes + } + let searchOptions = ReverseGeocodingOptions( point: query, - types: options.types.map { $0.coreType }, + types: filterTypes.map { $0.coreType }, countries: options.countries.map { $0.countryCode }, languages: [options.language.languageCode] ).toCore() diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 73c9d36a2..d03a98a8b 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -85,7 +85,6 @@ class OfflineIntegrationTests: MockServerTestCase { wait(for: [errorExpectation], timeout: 10) XCTAssertTrue(searchEngine.suggestions.isEmpty) - } func testCancelDownload() { diff --git a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Options+Tests.swift b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Options+Tests.swift index 175257697..6afa0ba82 100644 --- a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Options+Tests.swift +++ b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Options+Tests.swift @@ -8,8 +8,9 @@ final class PlaceAutocompleteOptionsTests: XCTestCase { let options = PlaceAutocomplete.Options() XCTAssertTrue(options.countries.isEmpty) + XCTAssertTrue(options.types.isEmpty) + XCTAssertEqual(options.language, .default) - XCTAssertEqual(options.types, [.POI]) } func testThatOptionsInitializedWithCountries() { diff --git a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift index 19686878a..cbb21cc7d 100644 --- a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift +++ b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift @@ -44,6 +44,20 @@ final class PlaceAutocompleteTests: XCTestCase { XCTAssertNil(searchEngine.searchOptions?.navProfile) XCTAssertNil(searchEngine.searchOptions?.etaType) } + + func testReverseGeocodingRequestUsesAllPlaceTypesIfTheyWereNotSpecifiedInOptions() { + placeAutocomplete.suggestions(for: .sample1) { _ in } + + XCTAssertFalse(searchEngine.reverseGeocodingOptions!.types!.isEmpty) + XCTAssertEqual(searchEngine.reverseGeocodingOptions!.types!.count, PlaceAutocomplete.PlaceType.allTypes.count) + } + + func testSuggestionsRequestUsesAllPlaceTypesIfTheyWereNotSpecifiedInOptions() { + placeAutocomplete.suggestions(for: "query") { _ in } + + XCTAssertFalse(searchEngine.searchOptions!.types!.isEmpty) + XCTAssertEqual(searchEngine.searchOptions!.types!.count, PlaceAutocomplete.PlaceType.allTypes.count) + } func testSuggestionsFilteredBy() { let types: [PlaceAutocomplete.PlaceType] = [.POI, .administrativeUnit(.city)] @@ -127,7 +141,7 @@ final class PlaceAutocompleteTests: XCTestCase { XCTAssertFalse(searchEngine.nextSearchCalled) } - func testSelectSuggestionIfNeedToRetrive() { + func testSelectSuggestionIfNeedToRetrieve() { let coreSuggestion = CoreSearchResultStub.makeSuggestion() coreSuggestion.resultTypes = [.poi] coreSuggestion.center = CLLocation(latitude: 10.0, longitude: 20.0) @@ -146,7 +160,7 @@ final class PlaceAutocompleteTests: XCTestCase { wait(for: [expectation], timeout: 1.0) } - func testSelectSuggestionIfDoNotNeedToRetrive() { + func testSelectSuggestionIfDoNotNeedToRetrieve() { let suggestion = PlaceAutocomplete.Suggestion.makeMock() let expectation = XCTestExpectation(description: "Call callback") From 139e89be8077c2b1e0cb0cd21022ffe4db3ff5bc Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Wed, 21 Jun 2023 21:13:53 +0300 Subject: [PATCH 04/31] Fix place autocomplete suggestions resolving for reverse geocoding requests --- CHANGELOG.md | 1 + .../Models/PlaceAutocomplete+Suggestion.swift | 1 + .../PlaceAutocomplete.swift | 19 +++++++------ .../PlaceAutocompleteTests.swift | 28 +++++++++++++++++++ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93f988a90..f381619bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Guide: https://keepachangelog.com/en/1.0.0/ ### Fixed - [Place Autocomplete]: request all possible `PlaceType` values in case if types were not specified in a search query options. +- [Place Autocomplete]: fixed an issue when reverevse geocoding suggestion returns error on `select` request. - [Address Autofill]: fixed reverse geocoding query, removed unsupported types from query. ## 1.0.0-rc.4 - 2023-05-19 diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift index 3418c970c..d5db5d9b6 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift @@ -126,6 +126,7 @@ extension PlaceAutocomplete.Suggestion { guard let type = SearchResultType(coreResultTypes: searchSuggestion.resultTypes) else { throw Error.invalidResultType } + guard let coordinate = searchSuggestion.center?.coordinate, CLLocationCoordinate2DIsValid(coordinate) else { throw Error.invalidCoordinates diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift index dda241800..06f820a3d 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift @@ -157,19 +157,22 @@ public extension PlaceAutocomplete { // MARK: - Reverse geocoding query private extension PlaceAutocomplete { func fetchSuggestions(using options: CoreReverseGeoOptions, completion: @escaping (Swift.Result<[Suggestion], Error>) -> Void) { - searchEngine.reverseGeocoding(for: options) { [weak self] response in + searchEngine.reverseGeocoding(for: options) { response in guard let response = Self.preprocessResponse(response) else { return } - switch response.coreResponse.result { - case .success(let results): - self?.resolve(suggestions: results, with: response.coreResponse.request, completion: completion) + switch response.process() { + case .success(let processedResponse): + do { + let suggestions = try processedResponse.results.map { try Suggestion.from($0) } + completion(.success(suggestions)) + } catch { + completion(.failure(error)) + } - case .failure(let responseError): - completion( - .failure(responseError) - ) + case .failure(let error): + completion(.failure(error)) } } } diff --git a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift index cbb21cc7d..e4a5a42c4 100644 --- a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift +++ b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift @@ -172,4 +172,32 @@ final class PlaceAutocompleteTests: XCTestCase { XCTAssertFalse(searchEngine.nextSearchCalled) wait(for: [expectation], timeout: 1.0) } + + func testReverseGeocodingReturnsAutocompleteSuggestionsAsResults() { + let results = [ + CoreSearchResultStub.makePlace(), + CoreSearchResultStub.makeAddress() + ].map { $0.asCoreSearchResult } + + searchEngine.searchResponse = CoreSearchResponseStub.successSample(results: results) + + let suggestionsExpectation = XCTestExpectation(description: "Suggestions resolved") + + placeAutocomplete.suggestions( + for: CLLocationCoordinate2D(latitude: .zero, longitude: .zero) + ) { result in + suggestionsExpectation.fulfill() + + let suggestions = try! result.get() + XCTAssertEqual(suggestions.count, 2) + + suggestions.forEach { + if case .suggestion = $0.underlying { + XCTFail("Geocoding suggestions should be resolved as results") + } + } + } + + wait(for: [suggestionsExpectation], timeout: 1.0) + } } From 6b8ec8c86429b5d6a2dfe669033735817ce59e9b Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Mon, 26 Jun 2023 12:48:50 +0300 Subject: [PATCH 05/31] Updated Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f381619bd..a7b845c5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ Guide: https://keepachangelog.com/en/1.0.0/ ## Unreleased +## 1.0.0-rc.5 - 2023-06-26 + ### Fixed - [Place Autocomplete]: request all possible `PlaceType` values in case if types were not specified in a search query options. - [Place Autocomplete]: fixed an issue when reverevse geocoding suggestion returns error on `select` request. From 675e5cd14c12c5c0b1b82ed69bf0e790592664db Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Mon, 26 Jun 2023 12:49:20 +0300 Subject: [PATCH 06/31] Updated Podspecs --- MapboxSearch.podspec | 2 +- MapboxSearchUI.podspec | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MapboxSearch.podspec b/MapboxSearch.podspec index 4eff838cd..26a97bd63 100644 --- a/MapboxSearch.podspec +++ b/MapboxSearch.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MapboxSearch' - s.version = '1.0.0-rc.4' + s.version = '1.0.0-rc.5' s.summary = 'Search SDK for Mapbox Search API ' # This description is used to generate tags and improve search results. diff --git a/MapboxSearchUI.podspec b/MapboxSearchUI.podspec index 5de5da22c..ea5b319de 100644 --- a/MapboxSearchUI.podspec +++ b/MapboxSearchUI.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MapboxSearchUI' - s.version = '1.0.0-rc.4' + s.version = '1.0.0-rc.5' s.summary = 'Search UI for Mapbox Search API' # This description is used to generate tags and improve search results. @@ -23,5 +23,5 @@ Card style custom UI with full search functionality powered by Mapbox Search API s.vendored_frameworks = "**/#{s.name}.xcframework" - s.dependency 'MapboxSearch', "1.0.0-rc.4" + s.dependency 'MapboxSearch', "1.0.0-rc.5" end From 152938dc0ddeb52d493a5d708514f1fc8b0bc1b9 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Mon, 26 Jun 2023 12:50:30 +0300 Subject: [PATCH 07/31] Bump SDK version --- Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift b/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift index 6eb8fa584..9f24d589b 100644 --- a/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift +++ b/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift @@ -1,2 +1,2 @@ /// Mapbox Search SDK version variable -public let mapboxSearchSDKVersion = "1.0.0-rc.4" +public let mapboxSearchSDKVersion = "1.0.0-rc.5" From ed03aab26cfc715048040b32c9a491a8b5183518 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 29 Jun 2023 14:31:10 +0300 Subject: [PATCH 08/31] Removed assertion for an unsupported search result type. --- CHANGELOG.md | 3 +++ Sources/MapboxSearch/InternalAPI/SearchResponse.swift | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7b845c5f..4047e0312 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Guide: https://keepachangelog.com/en/1.0.0/ ## Unreleased +### Fixed +- [Core]: removed assertion for unsupported search result types. + ## 1.0.0-rc.5 - 2023-06-26 ### Fixed diff --git a/Sources/MapboxSearch/InternalAPI/SearchResponse.swift b/Sources/MapboxSearch/InternalAPI/SearchResponse.swift index 8c42635a2..756d99011 100644 --- a/Sources/MapboxSearch/InternalAPI/SearchResponse.swift +++ b/Sources/MapboxSearch/InternalAPI/SearchResponse.swift @@ -39,7 +39,6 @@ private extension SearchResponse { suggestion = ExternalRecordPlaceholder(coreResult: coreResult, response: coreResponse) case _ where coreResult.resultTypes.contains(.unknown): - assertionFailure("Unsupported configuration") suggestion = nil default: @@ -53,7 +52,7 @@ private extension SearchResponse { suggestion = SearchResultSuggestionImpl(coreResult: coreResult, response: coreResponse) } } - assert(suggestion != nil, "Nil searchResult means missing business logic. Please, review current implementation") + return suggestion } From fadb72b069f94ee48ada720897ee65fe7b53d6f5 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 29 Jun 2023 14:49:28 +0300 Subject: [PATCH 09/31] Removed test case for checking unsupported assertion --- .../Legacy/SearchResponseTests.swift | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Tests/MapboxSearchTests/Legacy/SearchResponseTests.swift b/Tests/MapboxSearchTests/Legacy/SearchResponseTests.swift index 7d7352f26..ca1d74c94 100644 --- a/Tests/MapboxSearchTests/Legacy/SearchResponseTests.swift +++ b/Tests/MapboxSearchTests/Legacy/SearchResponseTests.swift @@ -98,20 +98,4 @@ class SearchResponseTests: XCTestCase { let processedResponse = try response.process().get() XCTAssertEqual(processedResponse.suggestions.map({ $0.id }), expectedResults.map({ $0.id })) } - - func testSuccessResponseWithUnsupportedType_UserRecord() throws { - #if !arch(x86_64) - throw XCTSkip("Unsupported architecture") - #else - - let result = CoreSearchResultStub(id: "random-userRecord-type", type: .userRecord) - let coreResponse = CoreSearchResponseStub(id: 377, options: .sample1, result: .success([result].map { $0.asCoreSearchResult })) - let response = SearchResponse(coreResponse: coreResponse) - let assertionError = catchBadInstruction { - let processedResponse = try? response.process().get() - XCTAssert(processedResponse?.suggestions.isEmpty == true) - } - XCTAssertNotNil(assertionError) - #endif - } } From 0aec8f5770a72f1e417a846fbe6ae1d24db63121 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 29 Jun 2023 15:18:14 +0300 Subject: [PATCH 10/31] Updated Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4047e0312..3bc8012b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ Guide: https://keepachangelog.com/en/1.0.0/ ## Unreleased +## 1.0.0-rc.5 - 2023-06-29 + ### Fixed - [Core]: removed assertion for unsupported search result types. From a8eb7f8f36c6e8f11faae62b98e7084fd1c4e70d Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 29 Jun 2023 15:18:43 +0300 Subject: [PATCH 11/31] Updated Podspecs --- MapboxSearch.podspec | 2 +- MapboxSearchUI.podspec | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MapboxSearch.podspec b/MapboxSearch.podspec index 26a97bd63..2153413bc 100644 --- a/MapboxSearch.podspec +++ b/MapboxSearch.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MapboxSearch' - s.version = '1.0.0-rc.5' + s.version = '1.0.0-rc.6' s.summary = 'Search SDK for Mapbox Search API ' # This description is used to generate tags and improve search results. diff --git a/MapboxSearchUI.podspec b/MapboxSearchUI.podspec index ea5b319de..385874aa5 100644 --- a/MapboxSearchUI.podspec +++ b/MapboxSearchUI.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MapboxSearchUI' - s.version = '1.0.0-rc.5' + s.version = '1.0.0-rc.6' s.summary = 'Search UI for Mapbox Search API' # This description is used to generate tags and improve search results. @@ -23,5 +23,5 @@ Card style custom UI with full search functionality powered by Mapbox Search API s.vendored_frameworks = "**/#{s.name}.xcframework" - s.dependency 'MapboxSearch', "1.0.0-rc.5" + s.dependency 'MapboxSearch', "1.0.0-rc.6" end From 08191cf101ebd7ef9478d3835b927de07d87ad73 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 29 Jun 2023 15:20:16 +0300 Subject: [PATCH 12/31] Bump SDK version. --- Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift b/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift index 9f24d589b..3d8424153 100644 --- a/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift +++ b/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift @@ -1,2 +1,2 @@ /// Mapbox Search SDK version variable -public let mapboxSearchSDKVersion = "1.0.0-rc.5" +public let mapboxSearchSDKVersion = "1.0.0-rc.6" From b9f3da29b4e071a8ff639007a862dd2241fd6b11 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 29 Jun 2023 15:37:13 +0300 Subject: [PATCH 13/31] Removed Travis CI configuration file --- .travis.yml | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d7501c33e..000000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -language: objective-c -os: osx -osx_image: xcode12 -before_install: - - echo -e "machine api.mapbox.com\n login $SDK_REGISTRY_USER\n password $SDK_REGISTRY_PASSWORD\n\n" > ~/.netrc - - echo -e "machine mapbox.bintray.com\n login $BINTRAY_USER\n password $BINTRAY_PASSWORD" >> ~/.netrc -before_script: - - echo $MAPBOX_API_KEY > .mapbox - - make dependencies -script: - - xcodebuild -scheme Demo -destination platform\=iOS\ Simulator,name\=iPhone\ 11,OS\=latest clean test | xcpretty -after_script: - - scripts/trigger_metrics.sh -branches: - only: - - develop - - master - - /^release/.*$/ - -before_deploy: xcodebuild -scheme "MapboxSearchUI" -destination platform=iOS\ Simulator,name=iPhone\ 11 clean test -deploy: - provider: script - script: bundle exec fastlane beta - skip_cleanup: true - on: - all_branches: true - condition: $TRAVIS_EVENT_TYPE = "cron" || $TRAVIS_EVENT_TYPE = "api" -notifications: - slack: - rooms: - - mapbox:rvYzCIzlDAan4aIsehoUxok6 - - mapbox:t5lJ1LCG6NeaVn35X7XcYOJl - on_success: change - on_failure: always From 30707aaaf63989a0e4d798d05420258b470f82df Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 13 Jul 2023 12:20:08 +0300 Subject: [PATCH 14/31] [PlaceAutocomplete]: replace `Address` type with `AddressComponents` type. --- MapboxSearch.xcodeproj/project.pbxproj | 4 ++ .../Common/Models/Address/Address.swift | 2 +- .../AddressComponents.swift | 67 +++++++++++++++++++ .../Models/PlaceAutocomplete+Result.swift | 4 +- .../Models/PlaceAutocomplete+Suggestion.swift | 2 +- .../CoreSearchResultStub+Samples.swift | 5 +- .../SearchResultMetadata+Samples.swift | 18 +++++ .../PlaceAutocomplet.Result+Tests.swift | 27 ++++++++ 8 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplet.Result+Tests.swift diff --git a/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index e153e6c32..606f6fe99 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -45,6 +45,7 @@ 149948ED290A8DCA00E7E619 /* Swifter in Frameworks */ = {isa = PBXBuildFile; productRef = 149948EC290A8DCA00E7E619 /* Swifter */; }; 149948EF290A8DD500E7E619 /* Swifter in Frameworks */ = {isa = PBXBuildFile; productRef = 149948EE290A8DD500E7E619 /* Swifter */; }; 149948F1290A8DF900E7E619 /* Swifter in Frameworks */ = {isa = PBXBuildFile; productRef = 149948F0290A8DF900E7E619 /* Swifter */; }; + 14A0B83D2A5FF20B00D281F1 /* PlaceAutocomplet.Result+Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14A0B83B2A5FF1B300D281F1 /* PlaceAutocomplet.Result+Tests.swift */; }; 14B92D5E298BFD19006003C1 /* DiscoverViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14B92D5D298BFD19006003C1 /* DiscoverViewController.swift */; }; 14F71865299FD4BD00D5BC2E /* PlaceAutocomplete+PlaceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14F71864299FD4BD00D5BC2E /* PlaceAutocomplete+PlaceType.swift */; }; 14F7186B29A1361700D5BC2E /* PlaceAutocompleteMainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14F7186929A1341A00D5BC2E /* PlaceAutocompleteMainViewController.swift */; }; @@ -506,6 +507,7 @@ 148DE66B285757AA0085684D /* AddressAutofill+Result.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AddressAutofill+Result.swift"; sourceTree = ""; }; 148DE670285777180085684D /* NSLocking+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSLocking+Extensions.swift"; sourceTree = ""; }; 148DE68A285A18900085684D /* AddressAutofill+AddressComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AddressAutofill+AddressComponent.swift"; sourceTree = ""; }; + 14A0B83B2A5FF1B300D281F1 /* PlaceAutocomplet.Result+Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PlaceAutocomplet.Result+Tests.swift"; sourceTree = ""; }; 14B92D5D298BFD19006003C1 /* DiscoverViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverViewController.swift; sourceTree = ""; }; 14F71864299FD4BD00D5BC2E /* PlaceAutocomplete+PlaceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PlaceAutocomplete+PlaceType.swift"; sourceTree = ""; }; 14F7186929A1341A00D5BC2E /* PlaceAutocompleteMainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaceAutocompleteMainViewController.swift; sourceTree = ""; }; @@ -1224,6 +1226,7 @@ children = ( 14FA65832953618800056E5B /* PlaceAutocomplete.Options+Tests.swift */, 2CA1E22029F09CD200A533CF /* PlaceAutocomplete.Suggestion+Tests.swift */, + 14A0B83B2A5FF1B300D281F1 /* PlaceAutocomplet.Result+Tests.swift */, 2CA1E22229F0A47600A533CF /* PlaceAutocompleteTests.swift */, ); path = "Place Autocomplete"; @@ -2467,6 +2470,7 @@ FE7C73B3256687310047CA20 /* IndexableRecordStub.swift in Sources */, FEEDD3A42508E24900DC0A98 /* SearchErrorTests.swift in Sources */, FE8F821C256D509600A100D4 /* RoutablePointTests.swift in Sources */, + 14A0B83D2A5FF20B00D281F1 /* PlaceAutocomplet.Result+Tests.swift in Sources */, 14FA658229535ABC00056E5B /* AdministrativeUnits+Tests.swift in Sources */, FEB0AA8325CAC3EF002F0D1F /* CoreResultTypeTests.swift in Sources */, FE4655A12566B619007ECC6A /* SearchResultSuggestionImplTests.swift in Sources */, diff --git a/Sources/MapboxSearch/PublicAPI/Common/Models/Address/Address.swift b/Sources/MapboxSearch/PublicAPI/Common/Models/Address/Address.swift index a4ad76de0..c060c38b0 100644 --- a/Sources/MapboxSearch/PublicAPI/Common/Models/Address/Address.swift +++ b/Sources/MapboxSearch/PublicAPI/Common/Models/Address/Address.swift @@ -50,7 +50,7 @@ public struct Address: Codable, Hashable { address.country = country ?? "" address.state = region ?? "" address.city = place ?? "" - + return address } diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Components/AddressComponents.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Components/AddressComponents.swift index e0607dfa8..388115af8 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Components/AddressComponents.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Components/AddressComponents.swift @@ -92,3 +92,70 @@ public extension AddressComponents { return address } } + +// MARK: - Formatted Address +public extension AddressComponents { + /// Address format style manage address string representation + enum FormatStyle { + /// House number and street name + case short + + /// House number, street name and place name (city). For region-based contries (like USA), the State name will be appended + case medium + + /// All address components (if available) without postcode + case long + + /// All available address components + case full + + /// Provide `Address` keypaths to build your own format. No additional country-based logic would be applied + case custom(components: [KeyPath]) + } + + /// Build address string in requested style. All empty components will be skipped. + /// Separator ", " would be used to join all the components. House number will separated with " " separator + /// For example, for `.short` style: "50 Beale St, 9th Floor" and for `.medium` – "50 Beale St, 9th Floor, San Francisco, California" + /// - Parameter style: address style to be used + /// - Returns: Address string + func formattedAddress(style: FormatStyle) -> String? { + // All styles will include \.houseNumber if it exist + let componentPaths: [KeyPath] + switch style { + case .short: + componentPaths = [\.houseNumber, \.street] + case .medium: + if let country = country, regionBasedCountry(country) { + componentPaths = [\.houseNumber, \.street, \.place, \.region] + } else { + componentPaths = [\.houseNumber, \.street, \.place] + } + case .long: + componentPaths = [\.houseNumber, \.street, \.neighborhood, \.locality, \.place, \.district, \.region, \.country] + case .full: + componentPaths = [\.houseNumber, \.street, \.neighborhood, \.locality, \.place, \.district, \.region, \.country, \.postcode] + case .custom(let components): + componentPaths = components + } + + // Take actual non-nil components + let components = componentPaths.map({ self[keyPath: $0] }).compactMap({ $0 }).filter({ !$0.isEmpty }) + guard !components.isEmpty else { return nil } + + let separator = ", " + + if componentPaths.first == \.houseNumber, let houseNumber = houseNumber { + if components.count == 1 { + return houseNumber + } else { + return houseNumber + " " + components.dropFirst().joined(separator: separator) + } + } else { + return components.joined(separator: separator) + } + } + + private func regionBasedCountry(_ country: String) -> Bool { + ["united states of america", "usa"].contains(country.lowercased()) + } +} diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Result.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Result.swift index 2bfb0561e..979559ada 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Result.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Result.swift @@ -31,8 +31,8 @@ public extension PlaceAutocomplete { /// Poi categories. Always empty for non-POI suggestions. public let categories: [String] - /// Textual representation of the address. - public let address: Address? + /// Type representing address components. + public let address: AddressComponents? /// Business phone number public let phone: String? diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift index d5db5d9b6..21260c862 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift @@ -77,7 +77,7 @@ extension PlaceAutocomplete.Suggestion { estimatedTime: estimatedTime, routablePoints: underlyingResult.routablePoints ?? [], categories: underlyingResult.categories ?? [], - address: underlyingResult.address, + address: AddressComponents(searchResult: underlyingResult), phone: underlyingResult.metadata?.phone, website: underlyingResult.metadata?.website, reviewCount: underlyingResult.metadata?.reviewCount, diff --git a/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchResultStub+Samples.swift b/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchResultStub+Samples.swift index b4bcb9b14..c740a8b5e 100644 --- a/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchResultStub+Samples.swift +++ b/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchResultStub+Samples.swift @@ -29,7 +29,7 @@ extension CoreSearchResultStub { return results } - static func makeSuggestion() -> CoreSearchResultStub { + static func makeSuggestion(metadata: CoreResultMetadata? = nil) -> CoreSearchResultStub { let result = CoreSearchResultStub( id: UUID().uuidString, type: .place, @@ -37,7 +37,8 @@ extension CoreSearchResultStub { languages: ["en"], center: nil, categories: ["cafe"], - icon: Maki.alcoholShop.name + icon: Maki.alcoholShop.name, + metadata: metadata ) return result } diff --git a/Tests/MapboxSearchTests/Common/Data Samples/SearchResultMetadata+Samples.swift b/Tests/MapboxSearchTests/Common/Data Samples/SearchResultMetadata+Samples.swift index d66fdece2..8a08d5e9b 100644 --- a/Tests/MapboxSearchTests/Common/Data Samples/SearchResultMetadata+Samples.swift +++ b/Tests/MapboxSearchTests/Common/Data Samples/SearchResultMetadata+Samples.swift @@ -21,3 +21,21 @@ extension SearchResultMetadata { website: "https://www.pizzahut.com") ) } + +extension CoreResultMetadata { + static func make(data: [String: String] = [:]) -> CoreResultMetadata { + .init( + reviewCount: nil, + phone: nil, + website: nil, + avRating: nil, + description: nil, + openHours: nil, + primaryPhoto: nil, + otherPhoto: nil, + cpsJson: nil, + parking: nil, + data: data + ) + } +} diff --git a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplet.Result+Tests.swift b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplet.Result+Tests.swift new file mode 100644 index 000000000..2b4bc136c --- /dev/null +++ b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplet.Result+Tests.swift @@ -0,0 +1,27 @@ +// Copyright © 2023 Mapbox. All rights reserved. + +import XCTest +@testable import MapboxSearch + +final class PlaceAutocompleteResultTests: XCTestCase { + func testResultContainsISOCountryCodes() { + let coreResult = CoreSearchResultStub( + id: UUID().uuidString, + type: .address + ) + coreResult.metadata = .make(data: [ + "iso_3166_1": "US", + "iso_3166_2": "US-NY" + ]) + + let searchResult = ServerSearchResult( + coreResult: coreResult, + response: CoreSearchResponseStub.successSample(results: [coreResult]) + )! + + let result = try! PlaceAutocomplete.Suggestion.from(searchResult).result(for: searchResult) + + XCTAssertEqual(result.address?.countryISO1, "US") + XCTAssertEqual(result.address?.countryISO2, "US-NY") + } +} From 704d9cfcad4cee544ec4eb054eeb3f4190947d1a Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 13 Jul 2023 12:29:41 +0300 Subject: [PATCH 15/31] Updated Changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bc8012b4..42d1772e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ Guide: https://keepachangelog.com/en/1.0.0/ ## 1.0.0-rc.5 - 2023-06-29 +### Added +- [PlaceAutocomplete]: added `formattedAddress` function to perform default address formatting. +- [PlaceAutocomplete]: added `countryISO1` and `countryISO2` properties in the resul's address. + +### Breaking changes +- [PlaceAutocomplete]: replaced `Address` type of the `Result` to the `AddressComponents`. + ### Fixed - [Core]: removed assertion for unsupported search result types. From 66fb7b430f2ac1f67db8c37fdde740e07fe5d8f4 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 13 Jul 2023 13:10:32 +0300 Subject: [PATCH 16/31] Updated dependencies and Changelog --- CHANGELOG.md | 7 +++++-- Cartfile | 4 ++-- Cartfile.resolved | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42d1772e7..80c75c183 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,15 +6,18 @@ Guide: https://keepachangelog.com/en/1.0.0/ ## Unreleased -## 1.0.0-rc.5 - 2023-06-29 - ### Added - [PlaceAutocomplete]: added `formattedAddress` function to perform default address formatting. - [PlaceAutocomplete]: added `countryISO1` and `countryISO2` properties in the resul's address. +### Fixed +- [Core]: Fixed street name capitalization for names with numbers. + ### Breaking changes - [PlaceAutocomplete]: replaced `Address` type of the `Result` to the `AddressComponents`. +## 1.0.0-rc.5 - 2023-06-29 + ### Fixed - [Core]: removed assertion for unsupported search result types. diff --git a/Cartfile b/Cartfile index 631b1cef9..2b68808ad 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" == 0.68.0 -binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" == 23.3.1 +binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" == 0.71.0 +binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" == 23.6.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index 6c50bc82b..83adff36f 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" "23.3.1" -binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" "0.68.0" +binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" "23.6.0" +binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" "0.71.0" From 28bfe7b8e87ca273380d32f9c0dcb67aa6a70774 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 13 Jul 2023 16:18:12 +0300 Subject: [PATCH 17/31] Updated Changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80c75c183..d8a92fb22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ Guide: https://keepachangelog.com/en/1.0.0/ ## Unreleased +## 1.0.0-rc.7 - 2023-07-13 + ### Added - [PlaceAutocomplete]: added `formattedAddress` function to perform default address formatting. - [PlaceAutocomplete]: added `countryISO1` and `countryISO2` properties in the resul's address. @@ -16,7 +18,7 @@ Guide: https://keepachangelog.com/en/1.0.0/ ### Breaking changes - [PlaceAutocomplete]: replaced `Address` type of the `Result` to the `AddressComponents`. -## 1.0.0-rc.5 - 2023-06-29 +## 1.0.0-rc.6 - 2023-06-29 ### Fixed - [Core]: removed assertion for unsupported search result types. From db2018515f9fc2fff50baaefa53b46321d61c347 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 13 Jul 2023 16:18:51 +0300 Subject: [PATCH 18/31] Updated podspecs --- MapboxSearch.podspec | 4 ++-- MapboxSearchUI.podspec | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MapboxSearch.podspec b/MapboxSearch.podspec index 2153413bc..bb8f1e491 100644 --- a/MapboxSearch.podspec +++ b/MapboxSearch.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MapboxSearch' - s.version = '1.0.0-rc.6' + s.version = '1.0.0-rc.7' s.summary = 'Search SDK for Mapbox Search API ' # This description is used to generate tags and improve search results. @@ -24,5 +24,5 @@ Some iOS platform specifics applies. s.vendored_frameworks = "**/#{s.name}.xcframework" - s.dependency "MapboxCommon", '~> 23.3' + s.dependency "MapboxCommon", '~> 23.6' end diff --git a/MapboxSearchUI.podspec b/MapboxSearchUI.podspec index 385874aa5..a07345e6b 100644 --- a/MapboxSearchUI.podspec +++ b/MapboxSearchUI.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MapboxSearchUI' - s.version = '1.0.0-rc.6' + s.version = '1.0.0-rc.7' s.summary = 'Search UI for Mapbox Search API' # This description is used to generate tags and improve search results. @@ -23,5 +23,5 @@ Card style custom UI with full search functionality powered by Mapbox Search API s.vendored_frameworks = "**/#{s.name}.xcframework" - s.dependency 'MapboxSearch', "1.0.0-rc.6" + s.dependency 'MapboxSearch', "1.0.0-rc.7" end From e1f83d8819c09c68ba77a6947398652b5c4b0fae Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 13 Jul 2023 16:21:34 +0300 Subject: [PATCH 19/31] Updated SPM manifest file --- Package.resolved | 4 ++-- Package.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Package.resolved b/Package.resolved index 406e3cbee..5d8dc98c3 100644 --- a/Package.resolved +++ b/Package.resolved @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/mapbox/mapbox-common-ios.git", "state": { "branch": null, - "revision": "012a2082e005e7fb375ca2743f6f921109f37d32", - "version": "23.3.2" + "revision": "584006ae5dcd08ba5ce206c3363bd679600ed39c", + "version": "23.6.0" } } ] diff --git a/Package.swift b/Package.swift index 5ed1ce4cd..6077b1651 100644 --- a/Package.swift +++ b/Package.swift @@ -4,9 +4,9 @@ import PackageDescription import Foundation -let (coreSearchVersion, coreSearchVersionHash) = ("0.68.0", "da06b5ef808eb94a1c4f16f3e9be0172cf0fd4c167575ab89553deeaffac8563") +let (coreSearchVersion, coreSearchVersionHash) = ("0.71.0", "252327e268abc28b9e5546a381d969c5cd1a3a8ccbd4b3ae2a31cef448a61fbc") -let commonMinVersion = Version("23.3.1") +let commonMinVersion = Version("23.6.0") let commonMaxVersion = Version("24.0.0") let package = Package( From 6eae2d29b140765eb11081020052be7b8330dc82 Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Thu, 13 Jul 2023 16:22:00 +0300 Subject: [PATCH 20/31] Updated SDK version --- Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift b/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift index 3d8424153..31d8bbb86 100644 --- a/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift +++ b/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift @@ -1,2 +1,2 @@ /// Mapbox Search SDK version variable -public let mapboxSearchSDKVersion = "1.0.0-rc.6" +public let mapboxSearchSDKVersion = "1.0.0-rc.7" From 9de8247f98c0bcf7be82b7f5436d9a1436c6f32b Mon Sep 17 00:00:00 2001 From: Oleg Sorochich Date: Fri, 14 Jul 2023 09:14:41 +0300 Subject: [PATCH 21/31] Handle new native API and result types. --- .../MapboxSearch/InternalAPI/CoreResultType+Extensions.swift | 1 + .../InternalAPI/DefaultStringInterpolation+Extensions.swift | 3 +++ .../Common/Models/Result Types/SearchAddressType.swift | 2 +- Sources/MapboxSearch/PublicAPI/SearchOptions.swift | 3 +++ Sources/MapboxSearch/PublicAPI/SearchQueryType.swift | 5 +++++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/MapboxSearch/InternalAPI/CoreResultType+Extensions.swift b/Sources/MapboxSearch/InternalAPI/CoreResultType+Extensions.swift index 024fd6b8f..009719e42 100644 --- a/Sources/MapboxSearch/InternalAPI/CoreResultType+Extensions.swift +++ b/Sources/MapboxSearch/InternalAPI/CoreResultType+Extensions.swift @@ -17,6 +17,7 @@ extension CoreResultType { case .userRecord: return "userRecord" case .neighborhood: return "neighborhood" case .block: return "block" + case .brand: return "brand" case .unknown: fallthrough @unknown default: return "unknown" diff --git a/Sources/MapboxSearch/InternalAPI/DefaultStringInterpolation+Extensions.swift b/Sources/MapboxSearch/InternalAPI/DefaultStringInterpolation+Extensions.swift index bcf472a0f..a5a1dd402 100644 --- a/Sources/MapboxSearch/InternalAPI/DefaultStringInterpolation+Extensions.swift +++ b/Sources/MapboxSearch/InternalAPI/DefaultStringInterpolation+Extensions.swift @@ -8,6 +8,9 @@ extension DefaultStringInterpolation { case .SBS: versionName = "SBS" + case .searchBox: + versionName = "searchBox" + case .autofill: versionName = "autofill" diff --git a/Sources/MapboxSearch/PublicAPI/Common/Models/Result Types/SearchAddressType.swift b/Sources/MapboxSearch/PublicAPI/Common/Models/Result Types/SearchAddressType.swift index 6dbd68344..d2040e00c 100644 --- a/Sources/MapboxSearch/PublicAPI/Common/Models/Result Types/SearchAddressType.swift +++ b/Sources/MapboxSearch/PublicAPI/Common/Models/Result Types/SearchAddressType.swift @@ -72,7 +72,7 @@ public enum SearchAddressType: String, Hashable, Codable { case .block: self = .block - case .unknown, .category, .userRecord, .query, .poi: + case .unknown, .category, .userRecord, .query, .poi, .brand: fallthrough @unknown default: diff --git a/Sources/MapboxSearch/PublicAPI/SearchOptions.swift b/Sources/MapboxSearch/PublicAPI/SearchOptions.swift index 670e60a27..db1ebb795 100644 --- a/Sources/MapboxSearch/PublicAPI/SearchOptions.swift +++ b/Sources/MapboxSearch/PublicAPI/SearchOptions.swift @@ -273,6 +273,9 @@ public struct SearchOptions { info("Autofill API doesn't support following filter types: \(unsupportedFilterTypes)") } + case .searchBox: + _Logger.searchSDK.warning("SearchBox API is not supported yet.") + @unknown default: _Logger.searchSDK.warning("Unexpected engine API Type: \(apiType)") } diff --git a/Sources/MapboxSearch/PublicAPI/SearchQueryType.swift b/Sources/MapboxSearch/PublicAPI/SearchQueryType.swift index 132ea5c6a..a150e1405 100644 --- a/Sources/MapboxSearch/PublicAPI/SearchQueryType.swift +++ b/Sources/MapboxSearch/PublicAPI/SearchQueryType.swift @@ -95,6 +95,11 @@ public enum SearchQueryType { return .street case .category: return category + case .brand: + /* + Brand type query is not supported. + */ + return .poi @unknown default: return nil } From 4daf2d06e56b9086dde1702797344cae809f9c98 Mon Sep 17 00:00:00 2001 From: Alex Azarov Date: Mon, 9 Oct 2023 14:56:12 +0200 Subject: [PATCH 22/31] Remove unnecessary log statement --- MapboxSearch.xcodeproj/project.pbxproj | 4 ++++ .../InternalAPI/Common/Extensions/Any+dumpAsString.swift | 8 ++++++++ Sources/MapboxSearch/PublicAPI/LocalDataProviders.swift | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 Sources/MapboxSearch/InternalAPI/Common/Extensions/Any+dumpAsString.swift diff --git a/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index 606f6fe99..3827c3dee 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -87,6 +87,7 @@ 2CE1B9FD2A13D41A005B043F /* address-suggestions-san-francisco.json in Resources */ = {isa = PBXBuildFile; fileRef = 2CE1B9F92A13D412005B043F /* address-suggestions-san-francisco.json */; }; 2CE1B9FE2A13D41A005B043F /* address-retrieve-san-francisco.json in Resources */ = {isa = PBXBuildFile; fileRef = 2CE1B9FA2A13D412005B043F /* address-retrieve-san-francisco.json */; }; 3A0D7E56233522D5006D81BB /* MapboxSearch.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A0D7E4C233522D4006D81BB /* MapboxSearch.framework */; }; + DFBC8A6D2AD42F5F00D394EF /* Any+dumpAsString.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC8A6C2AD42F5F00D394EF /* Any+dumpAsString.swift */; }; E648C0B626428D2B0044315F /* MapboxCoreSearch.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = E648C0B526428D2B0044315F /* MapboxCoreSearch.xcframework */; }; E648C0BA26428D3D0044315F /* MapboxCommon.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = E648C0B926428D3D0044315F /* MapboxCommon.xcframework */; }; E648C0BD26428D530044315F /* MapboxCommon.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = E648C0B926428D3D0044315F /* MapboxCommon.xcframework */; }; @@ -537,6 +538,7 @@ 2CE1B9FA2A13D412005B043F /* address-retrieve-san-francisco.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "address-retrieve-san-francisco.json"; sourceTree = ""; }; 3A0D7E4C233522D4006D81BB /* MapboxSearch.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MapboxSearch.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3A0D7E55233522D5006D81BB /* MapboxSearchTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MapboxSearchTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + DFBC8A6C2AD42F5F00D394EF /* Any+dumpAsString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Any+dumpAsString.swift"; sourceTree = ""; }; E648C0B526428D2B0044315F /* MapboxCoreSearch.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MapboxCoreSearch.xcframework; path = Carthage/Build/MapboxCoreSearch.xcframework; sourceTree = ""; }; E648C0B926428D3D0044315F /* MapboxCommon.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MapboxCommon.xcframework; path = Carthage/Build/MapboxCommon.xcframework; sourceTree = ""; }; E648C0C8264297730044315F /* libc++.1.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.1.tbd"; path = "usr/lib/libc++.1.tbd"; sourceTree = SDKROOT; }; @@ -1173,6 +1175,7 @@ isa = PBXGroup; children = ( 148DE670285777180085684D /* NSLocking+Extensions.swift */, + DFBC8A6C2AD42F5F00D394EF /* Any+dumpAsString.swift */, ); path = Extensions; sourceTree = ""; @@ -2351,6 +2354,7 @@ FEEDD3052508DFE400DC0A98 /* BoundingBox.swift in Sources */, FEEDD2FE2508DFE400DC0A98 /* CoreSearchResultProtocol.swift in Sources */, 140E47A5298BC94D00677E30 /* Discover+Options.swift in Sources */, + DFBC8A6D2AD42F5F00D394EF /* Any+dumpAsString.swift in Sources */, F914EE642743E4F400D4F173 /* CoreAliases.swift in Sources */, F998AED825D17DFF00230F34 /* SearchResponseInfo.swift in Sources */, FEEDD3082508DFE400DC0A98 /* HistoryRecord.swift in Sources */, diff --git a/Sources/MapboxSearch/InternalAPI/Common/Extensions/Any+dumpAsString.swift b/Sources/MapboxSearch/InternalAPI/Common/Extensions/Any+dumpAsString.swift new file mode 100644 index 000000000..1a8075d49 --- /dev/null +++ b/Sources/MapboxSearch/InternalAPI/Common/Extensions/Any+dumpAsString.swift @@ -0,0 +1,8 @@ +import Foundation + +/// An internal helper function that dumps the given object's contents using its mirror to a string +func dumpAsString(_ value: T) -> String { + var result = String() + dump(value, to: &result) + return result +} diff --git a/Sources/MapboxSearch/PublicAPI/LocalDataProviders.swift b/Sources/MapboxSearch/PublicAPI/LocalDataProviders.swift index b13f8b01d..350d0a44f 100644 --- a/Sources/MapboxSearch/PublicAPI/LocalDataProviders.swift +++ b/Sources/MapboxSearch/PublicAPI/LocalDataProviders.swift @@ -80,7 +80,7 @@ public class LocalDataProvider /// - Parameter record: entity to add public func add(record: Record) { recordsMap[record.id] = record - _Logger.searchSDK.debug("New record [id='\(record.id)'] in \(self). Whole record: \(dump(record))", + _Logger.searchSDK.debug("New record [id='\(record.id)'] in \(self). Whole record: \(dumpAsString(record))", category: .userRecords) for interactor in providerInteractors { From 0242413805cf28fd93fe925bd9ba93e6862eac36 Mon Sep 17 00:00:00 2001 From: Alex Azarov Date: Mon, 9 Oct 2023 15:16:42 +0200 Subject: [PATCH 23/31] Bump Xcode version --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a187d5753..213db06d7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -235,7 +235,7 @@ jobs: spm-build: macos: - xcode: 13.4.0 + xcode: 14.3.1 steps: - checkout - setup-authentication From 34fd274b6ec61c10aa2058fc878302d4bdadb58e Mon Sep 17 00:00:00 2001 From: Alex Azarov Date: Mon, 9 Oct 2023 16:20:53 +0200 Subject: [PATCH 24/31] Update changelog for rc.8 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8a92fb22..dc66c2b91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ Guide: https://keepachangelog.com/en/1.0.0/ ## Unreleased +## 1.0.0-rc.8 - 2023-10-09 + +### Fixed +- [Core]: removed unnecessary log statement that didn't respect the `LoggerLevel` setting. + ## 1.0.0-rc.7 - 2023-07-13 ### Added From 4046212137db5d24dfba708f42ca6155f32d7548 Mon Sep 17 00:00:00 2001 From: Jack Alto <384288+aokj4ck@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:34:56 -0500 Subject: [PATCH 25/31] Complete version bump to 1.0.0-rc.8 - SSDK-517 (#142) - Update documentation, podspecs, README, and notes to catch up to most recent existing release --- MapboxSearch.podspec | 2 +- MapboxSearchUI.podspec | 4 ++-- README.md | 4 ++-- Search Documentation.docc/Installation.md | 4 ++-- Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/MapboxSearch.podspec b/MapboxSearch.podspec index bb8f1e491..cd5c80dea 100644 --- a/MapboxSearch.podspec +++ b/MapboxSearch.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MapboxSearch' - s.version = '1.0.0-rc.7' + s.version = '1.0.0-rc.8' s.summary = 'Search SDK for Mapbox Search API ' # This description is used to generate tags and improve search results. diff --git a/MapboxSearchUI.podspec b/MapboxSearchUI.podspec index a07345e6b..775420ff9 100644 --- a/MapboxSearchUI.podspec +++ b/MapboxSearchUI.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MapboxSearchUI' - s.version = '1.0.0-rc.7' + s.version = '1.0.0-rc.8' s.summary = 'Search UI for Mapbox Search API' # This description is used to generate tags and improve search results. @@ -23,5 +23,5 @@ Card style custom UI with full search functionality powered by Mapbox Search API s.vendored_frameworks = "**/#{s.name}.xcframework" - s.dependency 'MapboxSearch', "1.0.0-rc.7" + s.dependency 'MapboxSearch', "1.0.0-rc.8" end diff --git a/README.md b/README.md index 87e1ab887..df509ec31 100644 --- a/README.md +++ b/README.md @@ -105,13 +105,13 @@ MapboxSearchDemoApplication provides a Demo app wih MapboxSearchUI.framework pre ##### MapboxSearch To integrate latest preview version of `MapboxSearch` into your Xcode project using CocoaPods, specify it in your `Podfile`: ``` -pod 'MapboxSearch', ">= 1.0.0-beta", "< 2.0" +pod 'MapboxSearch', ">= 1.0.0-rc.8", "< 2.0" ``` ##### MapboxSearchUI To integrate latest preview version of `MapboxSearchUI` into your Xcode project using CocoaPods, specify it in your `Podfile`: ``` -pod 'MapboxSearchUI', ">= 1.0.0-beta", "< 2.0" +pod 'MapboxSearchUI', ">= 1.0.0-rc.8", "< 2.0" ``` ### Swift Package Manager diff --git a/Search Documentation.docc/Installation.md b/Search Documentation.docc/Installation.md index 703c2e543..3dd3892aa 100644 --- a/Search Documentation.docc/Installation.md +++ b/Search Documentation.docc/Installation.md @@ -59,7 +59,7 @@ To add the Mapbox Search SDK dependency with CocoaPods, you will need to configu ```ruby use_frameworks! target "TargetNameForYourApp" do - pod 'MapboxSearchUI', ">= 1.0.0-beta", "< 2.0" + pod 'MapboxSearchUI', ">= 1.0.0-rc.8", "< 2.0" end ``` @@ -68,7 +68,7 @@ To add the Mapbox Search SDK dependency with CocoaPods, you will need to configu ```ruby use_frameworks! target "TargetNameForYourApp" do - pod 'MapboxSearch', ">= 1.0.0-beta", "< 2.0" + pod 'MapboxSearch', ">= 1.0.0-rc.8", "< 2.0" end ``` diff --git a/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift b/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift index 31d8bbb86..8ccf4a2c8 100644 --- a/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift +++ b/Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift @@ -1,2 +1,2 @@ /// Mapbox Search SDK version variable -public let mapboxSearchSDKVersion = "1.0.0-rc.7" +public let mapboxSearchSDKVersion = "1.0.0-rc.8" From f294ee59924fc1f971cb79348a77f9d2ec7144a8 Mon Sep 17 00:00:00 2001 From: Jack Alto <384288+aokj4ck@users.noreply.github.com> Date: Mon, 8 Jan 2024 10:54:35 -0500 Subject: [PATCH 26/31] [SSDK-499] Update to Xcode 14.1 (#143) - Update iOS deployment target in Package.swift to iOS 12 - Xcode 14.1 is the minimum required version for App Store submissions - https://developer.apple.com/news/?id=jd9wcyov - Update .swift-version to 5.7.1 - Update documentation - See also https://xcodereleases.com/ --- .circleci/config.yml | 16 ++++++++-------- .swift-version | 2 +- CHANGELOG.md | 3 +++ Package.swift | 2 +- README.md | 12 ++++++------ scripts/build_spm_sample.sh | 4 ++-- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 213db06d7..cb1d42d08 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -73,7 +73,7 @@ workflows: jobs: pre-check: macos: - xcode: 13.4.0 + xcode: 14.1 steps: - checkout - ios-install-carthage-dependencies @@ -81,7 +81,7 @@ jobs: release-pre-check: macos: - xcode: 13.4.0 + xcode: 14.1 steps: - parse-release-version - run: @@ -90,7 +90,7 @@ jobs: build: macos: - xcode: 13.4.0 # Specify the Xcode version to use + xcode: 14.1 # Specify the Xcode version to use environment: FL_OUTPUT_DIR: ../output steps: @@ -128,7 +128,7 @@ jobs: release-documentation: macos: - xcode: 13.4.0 + xcode: 14.1 steps: - checkout - parse-release-version @@ -151,7 +151,7 @@ jobs: documentation-pr: macos: - xcode: 13.4.0 + xcode: 14.1 steps: - checkout - parse-release-version @@ -174,7 +174,7 @@ jobs: build-for-release: macos: - xcode: 13.4.0 + xcode: 14.1 steps: - checkout - setup-authentication @@ -193,7 +193,7 @@ jobs: release-ios: macos: - xcode: 13.4.0 + xcode: 14.1 steps: - checkout - setup-authentication @@ -218,7 +218,7 @@ jobs: post-SDK_Registry-release: macos: - xcode: 13.4.0 + xcode: 14.1 steps: - checkout - parse-release-version diff --git a/.swift-version b/.swift-version index ef425ca98..262122f67 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -5.2 +5.7.1 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index dc66c2b91..6c32ee382 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Guide: https://keepachangelog.com/en/1.0.0/ ## Unreleased +- [Core] Updated to Xcode 14.1 minimum version +- [Core] Updated deployment target to iOS 12 + ## 1.0.0-rc.8 - 2023-10-09 ### Fixed diff --git a/Package.swift b/Package.swift index 6077b1651..85d6e5760 100644 --- a/Package.swift +++ b/Package.swift @@ -12,7 +12,7 @@ let commonMaxVersion = Version("24.0.0") let package = Package( name: "MapboxSearch", defaultLocalization: "en", - platforms: [.iOS(.v11), .macOS(.v10_15)], + platforms: [.iOS(.v12), .macOS(.v10_15)], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( diff --git a/README.md b/README.md index df509ec31..68c9b10cc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![CircleCI](https://dl.circleci.com/status-badge/img/gh/mapbox/mapbox-search-ios/tree/main.svg?style=shield)](https://dl.circleci.com/status-badge/redirect/gh/mapbox/mapbox-search-ios/tree/main) -[![Swift version](https://img.shields.io/badge/swift-4.2+-orange.svg?style=flat&logo=swift)](https://developer.apple.com/swift) -[![iOS version](https://img.shields.io/badge/iOS-11.0+-green.svg?style=flat&logo=apple)](https://developer.apple.com/ios/) -[![Xcode version](https://img.shields.io/badge/Xcode-11.3+-DeepSkyBlue.svg?style=flat&logo=xcode&logoColor=lightGray)](https://developer.apple.com/xcode/) +[![Swift version](https://img.shields.io/badge/swift-5.7.1+-orange.svg?style=flat&logo=swift)](https://developer.apple.com/swift) +[![iOS version](https://img.shields.io/badge/iOS-12.0+-green.svg?style=flat&logo=apple)](https://developer.apple.com/ios/) +[![Xcode version](https://img.shields.io/badge/Xcode-14.1+-DeepSkyBlue.svg?style=flat&logo=xcode&logoColor=lightGray)](https://developer.apple.com/xcode/) [![codecov](https://codecov.io/gh/mapbox/mapbox-search-ios/branch/develop/graph/badge.svg?token=js3DSKdda4)](https://codecov.io/gh/mapbox/mapbox-search-ios) [![swift-doc](https://img.shields.io/badge/swift--doc-64.94%25-orange?logo=read-the-docs)](https://github.com/SwiftDocOrg/swift-doc) # Mapbox Search SDK for iOS @@ -34,9 +34,9 @@ The Search SDK is pre-configured for autocomplete, local search biasing, and inc ## Requirements -- iOS 11.0 and newer -- Xcode 11.3 and newer -- Swift 4.2 and newer +- iOS 12.0 and newer +- Xcode 14 and newer +- Swift 5.7.1 and newer - Objective-C is not supported - macOS/tvOS/watchOS platforms currently are not supported diff --git a/scripts/build_spm_sample.sh b/scripts/build_spm_sample.sh index f2e6beac0..83e20dbb7 100755 --- a/scripts/build_spm_sample.sh +++ b/scripts/build_spm_sample.sh @@ -23,7 +23,7 @@ targets: CircleCIApp: type: application platform: iOS - deploymentTarget: 11.0 + deploymentTarget: 12.0 info: path: App.plist dependencies: @@ -38,7 +38,7 @@ EOF BASEDIR="${BASEDIR}" xcodegen xcodebuild -resolvePackageDependencies -derivedDataPath derivedData -scheme CircleCIApp -xcodebuild -scheme "CircleCIApp" -destination 'platform=iOS Simulator,name=iPhone 12' -derivedDataPath derivedData/ -project CircleCIApp.xcodeproj CODE_SIGNING_ALLOWED=NO +xcodebuild -scheme "CircleCIApp" -destination 'platform=iOS Simulator,name=iPhone 13,OS=15.0' -derivedDataPath derivedData/ -project CircleCIApp.xcodeproj CODE_SIGNING_ALLOWED=NO popd From 2deabea23bd33eadf91feda9e6b235c768c1acaa Mon Sep 17 00:00:00 2001 From: Jack Alto <384288+aokj4ck@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:57:58 -0500 Subject: [PATCH 27/31] [SSDK-487] Improve AddressAutofill, PlaceAutocomplete efficiency by skipping prefetching (#139) ### Description Fixes [SSDK-487](https://mapbox.atlassian.net/browse/SSDK-487) - Update AddressAutofill.resolve(suggestions:) to _only_ perform `autofill/v1/suggest` requests and to abstain from fetching the `retrieve` endpoint - Update PlaceAutocomplete.select(suggestions:) to _only_ perform `search/v1/suggest` requests and to abstain from fetching the `retrieve` endpoint - Requesting only `suggest` removes the suggestion coordinates and estimated times. Perform a call to `retrieve` in order to fetch those values. - Disable SwiftLint rules for the time being - Add helper function to convert CoreAddress to AddressAutofill.AddressComponents - Change AddressAutofill.Suggestion.coordinate to optional - Change PlaceAutocomplete.Suggestion.coordinate and PlaceAutocomplete.Result.coordinate to optional - Add Suggestion.Underlying field and enum to capture original Core API response for future API requests or validation ### Checklist - [x] Update `CHANGELOG` ### Screenshots | Before | After | | -- | -- | | ![Simulator Screen Shot - iPhone 14 Pro - 2024-01-09 at 12 31 30](https://github.com/mapbox/mapbox-search-ios/assets/384288/926ef543-888c-4f98-ba8a-7184779cce12) | ![Simulator Screenshot - iPhone 15 - 2023-12-20 at 13 57 19](https://github.com/mapbox/mapbox-search-ios/assets/384288/27012254-f0d7-42e4-868e-ba306851eb53) | | ![Simulator Screenshot - iPhone 15 - 2023-12-20 at 13 55 20](https://github.com/mapbox/mapbox-search-ios/assets/384288/d4371862-0cca-4d59-8c84-818f06da38fa) | ![Simulator Screen Shot - iPhone 14 Pro - 2024-01-09 at 12 15 32](https://github.com/mapbox/mapbox-search-ios/assets/384288/44a1e761-7b7e-46a9-bcc3-5d6546f181df) | [SSDK-487]: https://mapbox.atlassian.net/browse/SSDK-487?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --- .gitignore | 1 - CHANGELOG.md | 6 + MapboxSearch.xcodeproj/project.pbxproj | 4 + .../xcshareddata/swiftpm/Package.resolved | 13 +- ...aceAutocompleteDetailsViewController.swift | 10 +- .../PlaceAutocompleteMainViewController.swift | 6 +- .../Address Autofill/AddressAutofill.swift | 124 ++++++++++-------- .../AddressAutofill+Suggestion.swift | 24 +++- ...ressAutofill.Suggestion+SearchResult.swift | 3 +- .../CoreAddress+AddressComponents.swift | 33 +++++ .../Models/PlaceAutocomplete+Result.swift | 2 +- .../Models/PlaceAutocomplete+Suggestion.swift | 8 +- .../PlaceAutocomplete.swift | 64 +++------ .../AddressAutofillIntegrationTests.swift | 57 +++++++- .../PlaceAutocompleteIntegrationTests.swift | 10 +- .../PlaceAutocompleteTests.swift | 5 +- ...tegorySuggestionsIntegrationTestCase.swift | 4 +- .../VisibilityTestCase.swift | 2 +- 18 files changed, 234 insertions(+), 142 deletions(-) create mode 100644 Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/CoreAddress+AddressComponents.swift diff --git a/.gitignore b/.gitignore index 98bf207ea..c5f71c457 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ - # Created by https://www.gitignore.io/api/swift # Edit at https://www.gitignore.io/?templates=swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c32ee382..0ebc72c81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ Guide: https://keepachangelog.com/en/1.0.0/ - [Core] Updated to Xcode 14.1 minimum version - [Core] Updated deployment target to iOS 12 +- [Address Autofill] Suggestions no longer perform a `retrieve` call. +- [Address Autofill] `Suggestion.coordinate` is now an optional. `init` requires an Underlying enum parameter. +- [Address Autofill] Added new AddressAutofill.Suggestion.Underlying enum parameter with cases for suggestion and result inputs. +- [Place Autocomplete] Suggestions no longer perform a `retrieve` call. +- [Place Autocomplete] `Suggestion.coordinate` is now an optional. +- [Place Autocomplete] `Result.coordinate` is now an optional. ## 1.0.0-rc.8 - 2023-10-09 diff --git a/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index 3827c3dee..343fbc87d 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 043A3D4D2B30F38300DB681B /* CoreAddress+AddressComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043A3D4C2B30F38300DB681B /* CoreAddress+AddressComponents.swift */; }; 140D1BDC286DB479001A51C2 /* SearchResultAccuracy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 140D1BDB286DB479001A51C2 /* SearchResultAccuracy.swift */; }; 140E47A2298BC90E00677E30 /* Discover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 140E47A1298BC90E00677E30 /* Discover.swift */; }; 140E47A5298BC94D00677E30 /* Discover+Options.swift in Sources */ = {isa = PBXBuildFile; fileRef = 140E47A4298BC94D00677E30 /* Discover+Options.swift */; }; @@ -475,6 +476,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 043A3D4C2B30F38300DB681B /* CoreAddress+AddressComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreAddress+AddressComponents.swift"; sourceTree = ""; }; 140D1BDB286DB479001A51C2 /* SearchResultAccuracy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultAccuracy.swift; sourceTree = ""; }; 140E47A1298BC90E00677E30 /* Discover.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Discover.swift; sourceTree = ""; }; 140E47A4298BC94D00677E30 /* Discover+Options.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Discover+Options.swift"; sourceTree = ""; }; @@ -947,6 +949,7 @@ isa = PBXGroup; children = ( 148DE667285755500085684D /* AddressAutofill+Suggestion.swift */, + 043A3D4C2B30F38300DB681B /* CoreAddress+AddressComponents.swift */, 141789E6287C05060000AE79 /* AddressAutofill.Suggestion+SearchResult.swift */, ); path = Suggestion; @@ -2348,6 +2351,7 @@ FEEDD31B2508DFE400DC0A98 /* LocalDataProviders.swift in Sources */, FEEDD2F42508DFE400DC0A98 /* CoreResponseProvider.swift in Sources */, FEEDD30C2508DFE400DC0A98 /* IndexableRecord.swift in Sources */, + 043A3D4D2B30F38300DB681B /* CoreAddress+AddressComponents.swift in Sources */, FE097B7B264EAA1A001EAC2F /* AddOfflineRegionError.swift in Sources */, FEEDD30D2508DFE400DC0A98 /* ServiceProvider.swift in Sources */, FEEDD2FA2508DFE400DC0A98 /* CoreSearchEngineProtocol.swift in Sources */, diff --git a/Sources/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Sources/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index e7b67679c..bafb5f04f 100644 --- a/Sources/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Sources/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -51,17 +51,8 @@ "repositoryURL": "https://github.com/mapbox/mapbox-common-ios.git", "state": { "branch": null, - "revision": "98893cfe86f3aeed89d852f406d74a1756f71dad", - "version": "19.0.0" - } - }, - { - "package": "MapboxMobileEvents", - "repositoryURL": "https://github.com/mapbox/mapbox-events-ios.git", - "state": { - "branch": null, - "revision": "1df12e2514513acdf87841cde1f98fd8e414461e", - "version": "1.0.4" + "revision": "065cb97a83b8bf8d8584ab56cb6ebed898cc0c97", + "version": "23.8.6" } } ] diff --git a/Sources/Demo/PlaceAutocompleteDetailsViewController.swift b/Sources/Demo/PlaceAutocompleteDetailsViewController.swift index f6b8f1ffc..2feae215a 100644 --- a/Sources/Demo/PlaceAutocompleteDetailsViewController.swift +++ b/Sources/Demo/PlaceAutocompleteDetailsViewController.swift @@ -80,18 +80,20 @@ private extension PlaceAutocompleteResultViewController { } func showAnnotation() { + guard let coordinate = result.coordinate else { return } + let annotation = MKPointAnnotation() - annotation.coordinate = result.coordinate + annotation.coordinate = coordinate annotation.title = result.name mapView.addAnnotation(annotation) } func showSuggestionRegion() { - guard result != nil else { return } - + guard let coordinate = result.coordinate else { return } + let region = MKCoordinateRegion( - center: result.coordinate, + center: coordinate, span: .init(latitudeDelta: 0.001, longitudeDelta: 0.001) ) mapView.setRegion(region, animated: true) diff --git a/Sources/Demo/PlaceAutocompleteMainViewController.swift b/Sources/Demo/PlaceAutocompleteMainViewController.swift index c14ded462..d18360ad7 100644 --- a/Sources/Demo/PlaceAutocompleteMainViewController.swift +++ b/Sources/Demo/PlaceAutocompleteMainViewController.swift @@ -84,7 +84,7 @@ extension PlaceAutocompleteMainViewController: UITableViewDataSource, UITableVie tableViewCell.detailTextLabel?.text = description tableViewCell.detailTextLabel?.textColor = UIColor.darkGray - tableViewCell.detailTextLabel?.numberOfLines = 4 + tableViewCell.detailTextLabel?.numberOfLines = 3 return tableViewCell } @@ -103,10 +103,6 @@ extension PlaceAutocompleteMainViewController: UITableViewDataSource, UITableVie } } } - - func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - 100 - } } // MARK: - Private diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift index 19e94df4e..b4fb5a35e 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift @@ -105,13 +105,26 @@ public extension AddressAutofill { ) { userActivityReporter.reportActivity(forComponent: "address-autofill-suggestion-select") - let result = AddressAutofill.Result( - name: suggestion.name, - formattedAddress: suggestion.formattedAddress, - coordinate: suggestion.coordinate, - addressComponents: suggestion.addressComponents - ) - completion(.success(result)) + switch suggestion.underlying { + case let .suggestion(coreSearch, coreOptions): + searchEngine.nextSearch(for: coreSearch, with: coreOptions) { [weak self] coreResponse in + guard let self = self else { return } + + self.manage(response: coreResponse, completion: completion) + } + case .result: + guard let coordinate = suggestion.coordinate else { + completion(.failure(SearchError.responseProcessingFailed)) + return + } + let result = AddressAutofill.Result( + name: suggestion.name, + formattedAddress: suggestion.formattedAddress, + coordinate: coordinate, + addressComponents: suggestion.addressComponents + ) + completion(.success(result)) + } } } @@ -147,7 +160,7 @@ private extension AddressAutofill { } } -// MARK: - Text query +// MARK: - Suggestion Text query private extension AddressAutofill { func fetchSuggestions(for query: String, with options: CoreSearchOptions, completion: @escaping (Swift.Result<[Suggestion], Error>) -> Void) { searchEngine.search( @@ -197,56 +210,59 @@ private extension AddressAutofill { with options: CoreRequestOptions, completion: @escaping (Swift.Result<[Suggestion], Error>) -> Void ) { - guard !suggestions.isEmpty else { - return completion(.success([])) + let resolvedSuggestions = suggestions.compactMap { result -> Suggestion? in + guard let name = result.names.first, + let address = result.addresses?.first, + let resultAddress = try? address.toAutofillComponents() else { + return nil + } + + let fullAddress = result.fullAddress ?? "" + let underlying: Suggestion.Underlying = .suggestion(result, options) + + return Suggestion(name: name, + formattedAddress: fullAddress, + coordinate: result.center?.coordinate, + addressComponents: resultAddress, + underlying: underlying) } - - let dispatchGroup = DispatchGroup() - - var resolvedResultsUnsafe: [SearchResult?] = Array(repeating: nil, count: suggestions.count) - let lock = NSLock() - suggestions.enumerated().forEach { iterator in - dispatchGroup.enter() - - searchEngine.nextSearch(for: iterator.element, with: options) { response in - defer { dispatchGroup.leave() } - - guard let coreResponse = response else { - assertionFailure("Response should never be nil") - return - } - - guard let response = Self.preprocessResponse(coreResponse) else { - return - } - - switch response.process() { - case .success(let processedResponse): - guard let result = processedResponse.results.first else { - return - } - - lock.sync { - resolvedResultsUnsafe[iterator.offset] = result - } - - case .failure(let error): - completion(.failure(error)) - } - } + completion(.success(resolvedSuggestions)) + } +} + +// MARK: - Suggestion Retrieval Query +private extension AddressAutofill { + /// Manage responses from retrieve invocations. + /// - Parameters: + /// - coreResponse: Response from retrieve endpoint for a given suggestion. + /// - completion: Completion to execute when done processing response. + func manage( + response coreResponse: CoreSearchResponseProtocol?, + completion: @escaping (Swift.Result) -> Void + ) { + guard let response = Self.preprocessResponse(coreResponse) else { + completion(.failure(SearchError.responseProcessingFailed)) + return } - - dispatchGroup.notify(queue: .main) { - let resolvedSuggestions: [Suggestion] = resolvedResultsUnsafe.compactMap { - do { - return try $0.map(Suggestion.from(_:)) - } catch { - return nil - } + + switch response.process() { + case .success(let success): + guard let result = success.results.first, + let formattedAddress = result.address?.formattedAddress(style: .full), + let addressComponents = try? result.address?.toAutofillComponents() else { + completion(.failure(SearchError.responseProcessingFailed)) + return } - - completion(.success(resolvedSuggestions)) + + let autofillResult = AddressAutofill.Result(name: result.name, + formattedAddress: formattedAddress, + coordinate: result.coordinate, + addressComponents: addressComponents) + + completion(.success(autofillResult)) + case .failure(let failure): + completion(.failure(failure)) } } } diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/AddressAutofill+Suggestion.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/AddressAutofill+Suggestion.swift index ae7560ba0..6e3634867 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/AddressAutofill+Suggestion.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/AddressAutofill+Suggestion.swift @@ -11,21 +11,35 @@ public extension AddressAutofill { /// Textual representation of the address. public let formattedAddress: String - /// Address geographic point. - public let coordinate: CLLocationCoordinate2D + /// Address geographic point. May be nil. + public let coordinate: CLLocationCoordinate2D? + /// The individual address components. internal let addressComponents: NonEmptyArray - + + /// Underlying data provided by core SDK and API used to construct this Suggestion instance. + /// Useful for any follow-up API calls or unit test validation. + internal let underlying: Underlying + init( name: String, formattedAddress: String, - coordinate: CLLocationCoordinate2D, - addressComponents: NonEmptyArray + coordinate: CLLocationCoordinate2D?, + addressComponents: NonEmptyArray, + underlying: Underlying ) { self.name = name self.formattedAddress = formattedAddress self.coordinate = coordinate self.addressComponents = addressComponents + self.underlying = underlying } } } + +extension AddressAutofill.Suggestion { + enum Underlying { + case suggestion(CoreSearchResultProtocol, CoreRequestOptions) + case result(SearchResult) + } +} diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/AddressAutofill.Suggestion+SearchResult.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/AddressAutofill.Suggestion+SearchResult.swift index f388e632f..078c868c2 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/AddressAutofill.Suggestion+SearchResult.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/AddressAutofill.Suggestion+SearchResult.swift @@ -27,7 +27,8 @@ extension AddressAutofill.Suggestion { name: searchResult.name, formattedAddress: formattedAddress, coordinate: searchResult.coordinate, - addressComponents: try address.toAutofillComponents() + addressComponents: try address.toAutofillComponents(), + underlying: .result(searchResult) ) } } diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/CoreAddress+AddressComponents.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/CoreAddress+AddressComponents.swift new file mode 100644 index 000000000..724a2357b --- /dev/null +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/CoreAddress+AddressComponents.swift @@ -0,0 +1,33 @@ +// Copyright © 2023 Mapbox. All rights reserved. + +import Foundation + +extension CoreAddress { + enum AutofillParsingError: Error { + case emptyAddressComponents + } + + func toAutofillComponents() throws -> NonEmptyArray { + var components: [AddressAutofill.AddressComponent] = [] + + houseNumber.map { components.append(.init(kind: .houseNumber, value: $0)) } + street.map { components.append(.init(kind: .street, value: $0)) } + neighborhood.map { components.append(.init(kind: .neighborhood, value: $0)) } + locality.map { components.append(.init(kind: .locality, value: $0)) } + postcode.map { components.append(.init(kind: .postcode, value: $0)) } + place.map { components.append(.init(kind: .place, value: $0)) } + district.map { components.append(.init(kind: .district, value: $0)) } + region.map { components.append(.init(kind: .region, value: $0)) } + country.map { components.append(.init(kind: .country, value: $0)) } + + guard let first = components.first else { + throw AutofillParsingError.emptyAddressComponents + } + + return .init( + first: first, + others: Array(components.dropFirst()) + ) + } + +} diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Result.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Result.swift index 979559ada..66ab1ebba 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Result.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Result.swift @@ -14,7 +14,7 @@ public extension PlaceAutocomplete { public let type: SearchResultType /// result geographic point. - public let coordinate: CLLocationCoordinate2D + public let coordinate: CLLocationCoordinate2D? /// Icon name according to [Mapbox Maki icon set](https://github.com/mapbox/maki/) public let iconName: String? diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift index 21260c862..5b802d8a3 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift @@ -12,8 +12,8 @@ public extension PlaceAutocomplete { public let description: String? /// Geographic point. - public let coordinate: CLLocationCoordinate2D - + public let coordinate: CLLocationCoordinate2D? + /// Icon name according to [Mapbox Maki icon set](https://github.com/mapbox/maki/) public let iconName: String? @@ -32,12 +32,14 @@ public extension PlaceAutocomplete { /// List of points near `coordinate`, that represents entries to associated building. public let routablePoints: [RoutablePoint] + /// Underlying data provided by core SDK and API used to construct this Suggestion instance. + /// Useful for any follow-up API calls or unit test validation. let underlying: Underlying init( name: String, description: String?, - coordinate: CLLocationCoordinate2D, + coordinate: CLLocationCoordinate2D?, iconName: String?, distance: CLLocationDistance?, estimatedTime: Measurement?, diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift index 06f820a3d..058c0fbbd 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift @@ -291,52 +291,28 @@ private extension PlaceAutocomplete { let filteredSuggestions = suggestions.filter { !$0.resultTypes.contains(.category) && !$0.resultTypes.contains(.query) } - guard !filteredSuggestions.isEmpty else { - return completion(.success([])) - } - - let dispatchGroup = DispatchGroup() - var resolvingError: Error? - - var resolvedSuggestions: [Suggestion?] = Array(repeating: nil, count: filteredSuggestions.count) - let lock = NSLock() - - filteredSuggestions.enumerated().forEach { iterator in - dispatchGroup.enter() - if iterator.element.center != nil { - do { - let resolvedSuggestion = try Suggestion.from(searchSuggestion: iterator.element, options: options) - lock.sync { - resolvedSuggestions[iterator.offset] = resolvedSuggestion - } - } catch { - resolvingError = error - } - dispatchGroup.leave() - } else { - retrieve(suggestion: iterator.element, with: options) { result in - defer { dispatchGroup.leave() } + let resolvedSuggestions = filteredSuggestions.compactMap { result -> Suggestion? in + let name = result.names.first ?? "" + let distance = result.distance.flatMap { CLLocationDistance(integerLiteral: $0.int64Value) } + let coreResultTypes = result.types.compactMap { CoreResultType(rawValue: $0.intValue) } + let placeTypes = SearchResultType(coreResultTypes: coreResultTypes) + let categories = result.categories ?? [] + let routablePoints = result.routablePoints?.compactMap { RoutablePoint(routablePoint: $0) } ?? [] + let underlying: Suggestion.Underlying = .suggestion(result, options) - switch result { - case .success(let suggestion): - lock.sync { - resolvedSuggestions[iterator.offset] = suggestion - } - case .failure(let error): - resolvingError = error - } - } - } - } - - dispatchGroup.notify(queue: .main) { - let results = resolvedSuggestions.compactMap({ $0 }) - if results.isEmpty { - completion(.failure(resolvingError ?? SearchError.responseProcessingFailed)) - } else { - completion(.success(results)) - } + return Suggestion(name: name, + description: result.addressDescription, + coordinate: result.center?.coordinate, + iconName: result.icon, + distance: distance, + estimatedTime: result.estimatedTime, + placeType: placeTypes ?? .POI, + categories: categories, + routablePoints: routablePoints, + underlying: underlying) } + + completion(.success(resolvedSuggestions)) } } diff --git a/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift index 8b109682d..2a6adf39a 100644 --- a/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift @@ -49,11 +49,62 @@ final class AddressAutofillIntegrationTests: MockServerTestCase { ) let expectedAddressComponents = try! expectedAddress.toAutofillComponents() - guard let actualSuggestion = suggestion else { - XCTFail("Should return non nil suggestion") - return + let actualSuggestion = try! XCTUnwrap(suggestion, "Should return non-nil suggestion") + + let selectionExpectation = XCTestExpectation(description: "Expecting selection result") + + addressAutofill.select(suggestion: actualSuggestion) { result in + switch result { + case .success(let resolvedSuggestion): + XCTAssertEqual(resolvedSuggestion.name, "701 Steiner Street") + XCTAssertEqual(resolvedSuggestion.formattedAddress, expectedAddress.formattedAddress(style: .full)) + XCTAssertEqual(resolvedSuggestion.coordinate, CLLocationCoordinate2D(latitude: 37.784592, longitude: -122.434671)) + XCTAssertEqual(resolvedSuggestion.addressComponents, expectedAddressComponents) + case .failure: + XCTFail("Should return success") + } + selectionExpectation.fulfill() } + wait(for: [selectionExpectation], timeout: 5) + } + + func testSelectSuggestionFromCoordinate() throws { + let expectation = XCTestExpectation(description: "Expecting results") + + try server.setResponse(.retrieveAddressSanFrancisco) + + var suggestion: AddressAutofill.Suggestion? + let query = CLLocationCoordinate2D(latitude: 37.784592, longitude: -122.434671) + addressAutofill.suggestions(for: query) { result in + switch result { + case .success(let success): + XCTAssertEqual(success.first?.name, "701 Steiner Street") + XCTAssertEqual(success.first?.coordinate, query) + suggestion = success.first + case .failure(let failure): + XCTFail(failure.localizedDescription) + } + expectation.fulfill() + } + + wait(for: [expectation], timeout: 5) + + let expectedAddress = Address( + houseNumber: "701", + street: "Steiner Street", + neighborhood: nil, + locality: nil, + postcode: "94117", + place: "San Francisco", + district: nil, + region: "California", + country: "United States" + ) + let expectedAddressComponents = try! expectedAddress.toAutofillComponents() + + let actualSuggestion = try! XCTUnwrap(suggestion, "Should return non-nil suggestion") + let selectionExpectation = XCTestExpectation(description: "Expecting selection result") addressAutofill.select(suggestion: actualSuggestion) { result in diff --git a/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift index f2d98df07..240d45db1 100644 --- a/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift @@ -28,7 +28,7 @@ final class PlaceAutocompleteIntegrationTests: MockServerTestCase { case .success(let suggestions): XCTAssertEqual(suggestions.count, 10) XCTAssertTrue(suggestions.allSatisfy({ suggestion in - if case .result = suggestion.underlying { return true } + if case .suggestion = suggestion.underlying { return true } return false })) suggestion = suggestions[0] @@ -118,8 +118,8 @@ final class PlaceAutocompleteIntegrationTests: MockServerTestCase { switch result { case .success(let suggestions): XCTAssertEqual(suggestions.count, 3) - guard case .result = suggestions[0].underlying else { - XCTFail("First without coordinate should be retrieved") + guard case .suggestion = suggestions[0].underlying else { + XCTFail("First without coordinate should be retrieved and have empty value") return } guard case .suggestion = suggestions[1].underlying else { @@ -146,7 +146,11 @@ final class PlaceAutocompleteIntegrationTests: MockServerTestCase { } wait(for: [expectation], timeout: 5) + let firstSuggestion = try XCTUnwrap(actualSuggestions[0]) + XCTAssertNil(firstSuggestion.coordinate) + let selectionExpectation = XCTestExpectation(description: "Expecting selection result") + XCTAssertEqual(actualSuggestions.count, 3) placeAutocomplete.select(suggestion: actualSuggestions[1]) { result in switch result { case .success(let resolvedSuggestion): diff --git a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift index e4a5a42c4..885958886 100644 --- a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift +++ b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift @@ -97,9 +97,6 @@ final class PlaceAutocompleteTests: XCTestCase { ].map { $0.asCoreSearchResult } searchEngine.searchResponse = CoreSearchResponseStub.successSample(results: results) - let retrieveResults = [CoreSearchResultStub.makePOI().asCoreSearchResult] - searchEngine.nextSearchResponse = CoreSearchResponseStub.successSample(results: retrieveResults) - placeAutocomplete.suggestions(for: "query") { result in switch result { case .success(let returnedSuggestions): @@ -113,7 +110,7 @@ final class PlaceAutocompleteTests: XCTestCase { wait(for: [expectation], timeout: 1.0) XCTAssertEqual(userActivityReporter.passedActivity, "place-autocomplete-forward-geocoding") - XCTAssertTrue(searchEngine.nextSearchCalled) + XCTAssertFalse(searchEngine.nextSearchCalled) XCTAssertEqual(searchEngine.query, "query") XCTAssertEqual(searchEngine.categories, []) XCTAssertEqual(searchEngine.searchOptions?.isIgnoreUR, true) diff --git a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift index d6b727807..1af3b58f2 100644 --- a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift @@ -34,8 +34,8 @@ class CategorySuggestionsIntegrationTestCase: MockServerTestCase { let suggestions = app.categorySuggestionsTableView waitForHittable(suggestions, message: "CategorySuggestionsController tableView not hittable") - XCTAssertTrue(suggestions.cells.count > 0, "No Category suggestions results") - + XCTAssertTrue(suggestions.cells.count > 0 , "Category suggestions results should not be empty") + suggestions.cells.firstMatch.tap() waitForHittable(suggestions) } diff --git a/Tests/MapboxSearchUITests/VisibilityTestCase.swift b/Tests/MapboxSearchUITests/VisibilityTestCase.swift index c7bafc503..f197692cd 100644 --- a/Tests/MapboxSearchUITests/VisibilityTestCase.swift +++ b/Tests/MapboxSearchUITests/VisibilityTestCase.swift @@ -70,7 +70,7 @@ class VisibilityTestCase: BaseTestCase { searchBar.swipeUp() let categoriesTableView = waitForHittable(app.tables["CategoriesTableViewSource.tableView"]) - XCTAssertTrue(categoriesTableView.cells.count > 0, "Categories TableView empty") + XCTAssertTrue(categoriesTableView.cells.count > 0, "Categories TableView should not be empty") for cell in categoriesTableView.cells.allElementsBoundByIndex { XCTAssertTrue(cell.images.element.exists, "Category \(cell.identifier) has no icon") } From 2fa0b68b8241524d787ca7c451b9d7b868466c80 Mon Sep 17 00:00:00 2001 From: Jack Alto <384288+aokj4ck@users.noreply.github.com> Date: Thu, 11 Jan 2024 12:58:42 -0500 Subject: [PATCH 28/31] [SSDK-495] Build with updated Search SDK v2 (#140) ### Description Fixes [#SSDK-495](https://mapbox.atlassian.net/browse/SSDK-495) #### Packages and Project - Update MapboxCommon 23.6.0 -> 24.0.0 - This will require MapboxMaps 11.0.0+ - Update MapboxCoreSearch 0.71.0 -> 2.0.0-alpha.4 - Update CI, fake, and Fastfile devices to supported OS and device combinations - Updated to Xcode 14.1 minimum version - Updated deployment target to iOS 12 - Remove bitcode support #### SDK Changes - Removed parameter-based Access Token. Be sure to provide your token in Info.plist. - Renamed `CoreSuggestAction.isMultiRetrivable` to `multiRetrievable`. - Renamed `CoreSearchResult.center` to `.centerLocation`. - Renamed `CoreSearchOptions.isIgnoreUR` to `ignoreUR`. - Renamed `TileRegionLoadOptions` initializer parameter `start` to `startLocation`. - Replace some `CLLocation` fields with `Coordinate2D` wrapper containing a value of `CLLocationCoordinate2D`. This changes the call-site from `.coordinate` to `.value`. - Added `SdkInformation.defaultInfo` default value for various Core initializer parameters. - Added `SearchAddressRegion` containing `name`, `regionCode`, and `regionCodeFull` fields. - Added `SearchAddressCountry` containing `name`, `countryCode`, and `regionCodeFull` fields. - Added fields `searchAddressRegion` and `searchAddressCountry` to `Address` alongside existing `country` and `region`. - Remove access token parameter from `SearchTileStore`. #### Examples - Update Examples/SearchExamples for Xcode 14.1, iOS 13, and SDK versions found on main branch (preceeding versions) - Add tab icons to MapboxSearch.xcodeproj > Demo build target ### Checklist - [x] Update `CHANGELOG` --- .circleci/config.yml | 2 +- .fastlane/Fastfile | 11 +- CHANGELOG.md | 20 ++- Cartfile | 4 +- Cartfile.resolved | 4 +- .../SearchExamples.xcodeproj/project.pbxproj | 34 +++-- .../xcshareddata/swiftpm/Package.resolved | 123 ++++++++---------- .../MapboxBoundingBoxController.swift | 17 ++- ...boxMapsCategoryResultsViewController.swift | 1 - .../SearchExamples/MapsViewController.swift | 1 + .../SimpleCategorySearchViewController.swift | 1 - .../SimpleListSearchViewController.swift | 1 - .../SimpleUISearchViewController.swift | 1 + Makefile | 8 +- MapboxSearch.podspec | 4 +- MapboxSearch.xcodeproj/project.pbxproj | 20 +++ MapboxSearchUI.podspec | 2 +- Package.resolved | 12 +- Package.swift | 6 +- README.md | 3 +- .../CompatibilityGuide.md | 8 +- .../CompatibilityGuide.md | 8 +- .../xcshareddata/swiftpm/Package.resolved | 4 +- Sources/Demo/Base.lproj/Main.storyboard | 12 +- .../InternalAPI/CoreAliases.swift | 3 + .../InternalAPI/CoreResponseProvider.swift | 2 +- .../CoreSearchResultProtocol.swift | 6 +- .../CoreUserActivityReporter.swift | 3 +- .../InternalAPI/WrapperLocationProvider.swift | 4 +- .../Common/Models/Address/Address.swift | 18 ++- .../Models/Country/SearchAddressCountry.swift | 28 ++++ .../Models/Region/SearchAddressRegion.swift | 28 ++++ .../Engine/AbstractSearchEngine.swift | 20 +-- .../PublicAPI/Engine/SdkInformation.swift | 11 ++ .../PublicAPI/Engine/SearchEngine.swift | 4 +- .../PublicAPI/IndexableRecord.swift | 2 +- .../Offline/SearchOfflineManager.swift | 5 +- .../PublicAPI/Offline/SearchTileStore.swift | 46 ++----- .../TileRegionLoadOptions+Search.swift | 4 +- .../ExternalRecordPlaceholder.swift | 2 +- .../SearchCategorySuggestionImpl.swift | 4 +- .../SearchQuerySuggestionImpl.swift | 4 +- .../SearchResultSuggestionImpl.swift | 6 +- .../Search Results/ServerSearchResult.swift | 14 +- .../PublicAPI/SearchOptions.swift | 16 +-- .../PublicAPI/ServiceProvider.swift | 9 +- .../PublicAPI/Telemetry/FeedbackManager.swift | 6 +- .../Address Autofill/AddressAutofill.swift | 18 +-- .../CoreAddress+AddressComponents.swift | 4 +- .../Use Cases/Discover API/Discover.swift | 10 +- .../Models/PlaceAutocomplete+Suggestion.swift | 2 +- .../PlaceAutocomplete.swift | 16 +-- .../MapboxSearchController.swift | 14 -- .../AddressAutofillIntegrationTests.swift | 1 - ...CategorySearchEngineIntegrationTests.swift | 1 - .../OfflineIntegrationTests.swift | 4 +- .../PlaceAutocompleteIntegrationTests.swift | 5 +- .../SearchEngineIntegrationTests.swift | 1 - .../CLLocationCoordinate2D+Samples.swift | 5 + .../CoreSearchOptions+Samples.swift | 10 +- .../CoreSearchResultStub+Samples.swift | 42 +++--- .../SearchCategorySuggestion+Samples.swift | 2 +- .../SearchQuerySuggestionImpl+Samples.swift | 2 +- .../Common/Models/Address/Address+Tests.swift | 4 +- .../Address/CoreAddress+Extensions.swift | 17 --- .../SearchResultSuggestionImplTests.swift | 8 +- .../ServerSearchResultTests.swift | 4 +- .../Stubs&Models/CoreSearchEngineStub.swift | 12 +- .../Stubs&Models/CoreSearchResultStub.swift | 13 +- .../Stubs&Models/ServiceProviderStub.swift | 6 +- .../Common/Stubs&Models/TestTileStore.swift | 7 +- .../Legacy/CategorySearchEngineTests.swift | 8 +- .../Legacy/IndexableDataProviderTests.swift | 6 +- .../Legacy/LocationProviderTests.swift | 8 +- .../SearchCategorySuggestionImplTests.swift | 4 +- .../Legacy/SearchEngineTests.swift | 34 ++--- .../Legacy/WrapperLocationProviderTests.swift | 2 +- .../AddressAutofill+Tests.swift | 2 +- .../PlaceAutocomplete.Suggestion+Tests.swift | 2 +- .../PlaceAutocompleteTests.swift | 18 +-- scripts/build.sh | 1 - 81 files changed, 432 insertions(+), 413 deletions(-) create mode 100644 Sources/MapboxSearch/PublicAPI/Common/Models/Country/SearchAddressCountry.swift create mode 100644 Sources/MapboxSearch/PublicAPI/Common/Models/Region/SearchAddressRegion.swift create mode 100644 Sources/MapboxSearch/PublicAPI/Engine/SdkInformation.swift diff --git a/.circleci/config.yml b/.circleci/config.yml index cb1d42d08..8a0fd61cc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -283,7 +283,7 @@ commands: steps: - run: name: pre-start simulator - command: xcrun instruments -w "iPhone 11 Pro (14.0) [" || true + command: xcrun instruments -w "iPhone 13 Pro (15.0) [" || true upgrade-carthage: steps: diff --git a/.fastlane/Fastfile b/.fastlane/Fastfile index 4974ffbdb..8924c7f01 100644 --- a/.fastlane/Fastfile +++ b/.fastlane/Fastfile @@ -16,13 +16,10 @@ platform :ios do sh("xcrun simctl erase all") destinations = [ - "-destination platform=iOS\\ Simulator,name=iPhone\\ 11\\ Pro\\ Max", - "-destination platform=iOS\\ Simulator,OS=11.4,name=iPhone\\ 8", - "-destination platform=iOS\\ Simulator,OS=12.4,name=iPhone\\ 8", - "-destination platform=iOS\\ Simulator,OS=11.4,name=iPhone\\ 8\\ Plus", - "-destination platform=iOS\\ Simulator,OS=12.4,name=iPhone\\ 8\\ Plus", - "-destination platform=iOS\\ Simulator,OS=11.4,name=iPhone\\ SE\\ \\(1st\\ generation\\)", - "-destination platform=iOS\\ Simulator,OS=12.4,name=iPhone\\ SE\\ \\(1st\\ generation\\)" + "-destination platform=iOS\\ Simulator,name=iPhone\\ 14\\ Pro\\ Max", + "-destination platform=iOS\\ Simulator,OS=15,name=iPhone\\ 13", + "-destination platform=iOS\\ Simulator,OS=15,name=iPhone\\ 13 Pro", + "-destination platform=iOS\\ Simulator,OS=15,name=iPhone\\ 13 mini", ] destinations.each do |destination| diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ebc72c81..ef0fc9a39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,14 +6,30 @@ Guide: https://keepachangelog.com/en/1.0.0/ ## Unreleased -- [Core] Updated to Xcode 14.1 minimum version -- [Core] Updated deployment target to iOS 12 - [Address Autofill] Suggestions no longer perform a `retrieve` call. - [Address Autofill] `Suggestion.coordinate` is now an optional. `init` requires an Underlying enum parameter. - [Address Autofill] Added new AddressAutofill.Suggestion.Underlying enum parameter with cases for suggestion and result inputs. - [Place Autocomplete] Suggestions no longer perform a `retrieve` call. - [Place Autocomplete] `Suggestion.coordinate` is now an optional. - [Place Autocomplete] `Result.coordinate` is now an optional. +- [Core] Updated to Xcode 14.1 minimum version +- [Core] Updated deployment target to iOS 12 +- [Core] Remove bitcode support +- [Core] Updated API usage: + - Removed parameter-based Access Token. Be sure to provide your token in Info.plist. + - Renamed `CoreSuggestAction.isMultiRetrivable` to `multiRetrievable`. + - Renamed `CoreSearchResult.center` to `.centerLocation`. + - Renamed `CoreSearchOptions.isIgnoreUR` to `ignoreUR`. + - Renamed `TileRegionLoadOptions` initializer parameter `start` to `startLocation`. + - Replace some `CLLocation` fields with `Coordinate2D` wrapper containing a value of `CLLocationCoordinate2D`. This changes the call-site from `.coordinate` to `.value`. + - Added `SdkInformation.defaultInfo` default value for various Core initializer parameters. + - Added `SearchAddressRegion` containing `name`, `regionCode`, and `regionCodeFull` fields. + - Added `SearchAddressCountry` containing `name`, `countryCode`, and `regionCodeFull` fields. + - Added fields `searchAddressRegion` and `searchAddressCountry` to `Address` alongside existing `country` and `region`. + - Remove access token parameter from `SearchTileStore`. + +**MapboxCommon**: v24.0.0 +**MapboxCoreSearch**: v2.0.0 ## 1.0.0-rc.8 - 2023-10-09 diff --git a/Cartfile b/Cartfile index 2b68808ad..2f8a2db14 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" == 0.71.0 -binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" == 23.6.0 +binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" == 2.0.0-alpha.4 +binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" == 24.0.0 \ No newline at end of file diff --git a/Cartfile.resolved b/Cartfile.resolved index 83adff36f..2834b35ed 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" "23.6.0" -binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" "0.71.0" +binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" "24.0.0" +binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" "2.0.0-alpha.4" diff --git a/Examples/SearchExamples.xcodeproj/project.pbxproj b/Examples/SearchExamples.xcodeproj/project.pbxproj index b83fec861..bfe833b55 100644 --- a/Examples/SearchExamples.xcodeproj/project.pbxproj +++ b/Examples/SearchExamples.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 04F0A1612B4F276D0097D316 /* MapboxMaps in Frameworks */ = {isa = PBXBuildFile; productRef = 04F0A1602B4F276D0097D316 /* MapboxMaps */; }; FE00067F26FDCB9E00846819 /* Examples.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE00067E26FDCB9E00846819 /* Examples.swift */; }; FE0720BE26FC86C70065A273 /* MapboxSearch in Frameworks */ = {isa = PBXBuildFile; productRef = FE0720BD26FC86C70065A273 /* MapboxSearch */; }; FE0720C026FC86C70065A273 /* MapboxSearchUI in Frameworks */ = {isa = PBXBuildFile; productRef = FE0720BF26FC86C70065A273 /* MapboxSearchUI */; }; @@ -21,7 +22,6 @@ FE8295832701E46D001005B4 /* MapboxBoundingBoxController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE780E3124C9B3D000C62400 /* MapboxBoundingBoxController.swift */; }; FE849B5626FC9E63001CBC27 /* ExamplesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE849B5526FC9E63001CBC27 /* ExamplesTableViewController.swift */; }; FE849B5A26FCBCEC001CBC27 /* MapsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE849B5926FCBCEC001CBC27 /* MapsViewController.swift */; }; - FE93032526F8D87A00644DF6 /* MapboxMaps in Frameworks */ = {isa = PBXBuildFile; productRef = FE93032426F8D87A00644DF6 /* MapboxMaps */; }; FE9DFDAA26F8D9A60021375F /* MapboxSearch in Frameworks */ = {isa = PBXBuildFile; productRef = FE9DFDA926F8D9A60021375F /* MapboxSearch */; }; FE9DFDAC26F8DA0F0021375F /* MapboxSearchUI in Frameworks */ = {isa = PBXBuildFile; productRef = FE9DFDAB26F8DA0F0021375F /* MapboxSearchUI */; }; FEF1D1BA26FDF642004AE229 /* TextViewLoggerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEF1D1B926FDF642004AE229 /* TextViewLoggerViewController.swift */; }; @@ -52,7 +52,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FE93032526F8D87A00644DF6 /* MapboxMaps in Frameworks */, + 04F0A1612B4F276D0097D316 /* MapboxMaps in Frameworks */, FE0720C026FC86C70065A273 /* MapboxSearchUI in Frameworks */, FE0720BE26FC86C70065A273 /* MapboxSearch in Frameworks */, FE9DFDAC26F8DA0F0021375F /* MapboxSearchUI in Frameworks */, @@ -144,12 +144,12 @@ ); name = SearchExamples; packageProductDependencies = ( - FE93032426F8D87A00644DF6 /* MapboxMaps */, FE9DFDA926F8D9A60021375F /* MapboxSearch */, FE9DFDAB26F8DA0F0021375F /* MapboxSearchUI */, FE0720BD26FC86C70065A273 /* MapboxSearch */, FE0720BF26FC86C70065A273 /* MapboxSearchUI */, FEF1D1BC26FDFB1F004AE229 /* Atlantis */, + 04F0A1602B4F276D0097D316 /* MapboxMaps */, ); productName = SearchExamples; productReference = FE114AA424C10B88001B2CE8 /* SearchExamples.app */; @@ -180,9 +180,9 @@ ); mainGroup = FE114A9B24C10B88001B2CE8; packageReferences = ( - FE93032326F8D87A00644DF6 /* XCRemoteSwiftPackageReference "mapbox-maps-ios" */, FE0720BC26FC86C70065A273 /* XCRemoteSwiftPackageReference "search-ios" */, FEF1D1BB26FDFB1F004AE229 /* XCRemoteSwiftPackageReference "atlantis" */, + 04F0A15F2B4F276D0097D316 /* XCRemoteSwiftPackageReference "mapbox-maps-ios" */, ); productRefGroup = FE114AA524C10B88001B2CE8 /* Products */; projectDirPath = ""; @@ -382,7 +382,6 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = GJZR2MEM28; INFOPLIST_FILE = SearchExamples/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -402,7 +401,6 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = GJZR2MEM28; INFOPLIST_FILE = SearchExamples/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -439,20 +437,20 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - FE0720BC26FC86C70065A273 /* XCRemoteSwiftPackageReference "search-ios" */ = { + 04F0A15F2B4F276D0097D316 /* XCRemoteSwiftPackageReference "mapbox-maps-ios" */ = { isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/mapbox/search-ios"; + repositoryURL = "https://github.com/mapbox/mapbox-maps-ios.git"; requirement = { kind = upToNextMajorVersion; - minimumVersion = "1.0.0-beta"; + minimumVersion = 10.0.0; }; }; - FE93032326F8D87A00644DF6 /* XCRemoteSwiftPackageReference "mapbox-maps-ios" */ = { + FE0720BC26FC86C70065A273 /* XCRemoteSwiftPackageReference "search-ios" */ = { isa = XCRemoteSwiftPackageReference; - repositoryURL = "git@github.com:mapbox/mapbox-maps-ios.git"; + repositoryURL = "https://github.com/mapbox/search-ios"; requirement = { kind = upToNextMajorVersion; - minimumVersion = "10.0.0-rc"; + minimumVersion = "1.0.0-rc.8"; }; }; FEF1D1BB26FDFB1F004AE229 /* XCRemoteSwiftPackageReference "atlantis" */ = { @@ -460,12 +458,17 @@ repositoryURL = "https://github.com/ProxymanApp/atlantis"; requirement = { kind = upToNextMinorVersion; - minimumVersion = 1.11.2; + minimumVersion = 1.23.0; }; }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 04F0A1602B4F276D0097D316 /* MapboxMaps */ = { + isa = XCSwiftPackageProductDependency; + package = 04F0A15F2B4F276D0097D316 /* XCRemoteSwiftPackageReference "mapbox-maps-ios" */; + productName = MapboxMaps; + }; FE0720BD26FC86C70065A273 /* MapboxSearch */ = { isa = XCSwiftPackageProductDependency; package = FE0720BC26FC86C70065A273 /* XCRemoteSwiftPackageReference "search-ios" */; @@ -476,11 +479,6 @@ package = FE0720BC26FC86C70065A273 /* XCRemoteSwiftPackageReference "search-ios" */; productName = MapboxSearchUI; }; - FE93032426F8D87A00644DF6 /* MapboxMaps */ = { - isa = XCSwiftPackageProductDependency; - package = FE93032326F8D87A00644DF6 /* XCRemoteSwiftPackageReference "mapbox-maps-ios" */; - productName = MapboxMaps; - }; FE9DFDA926F8D9A60021375F /* MapboxSearch */ = { isa = XCSwiftPackageProductDependency; productName = MapboxSearch; diff --git a/Examples/SearchExamples.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Examples/SearchExamples.xcworkspace/xcshareddata/swiftpm/Package.resolved index 4c2d29d9f..1586c7ebc 100644 --- a/Examples/SearchExamples.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Examples/SearchExamples.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,70 +1,59 @@ { - "object": { - "pins": [ - { - "package": "Atlantis", - "repositoryURL": "https://github.com/ProxymanApp/atlantis", - "state": { - "branch": null, - "revision": "2ee37f1da01b438d67012cc1405617e158f358a1", - "version": "1.11.2" - } - }, - { - "package": "MapboxCommon", - "repositoryURL": "https://github.com/mapbox/mapbox-common-ios.git", - "state": { - "branch": null, - "revision": "a69e8ec4684ea2db20c94e85bcb54497554500d0", - "version": "18.0.0" - } - }, - { - "package": "MapboxCoreMaps", - "repositoryURL": "https://github.com/mapbox/mapbox-core-maps-ios.git", - "state": { - "branch": null, - "revision": "d5360ef24a2038150ab68c67ada0893f6d5b5b15", - "version": "10.0.0-rc.8" - } - }, - { - "package": "MapboxMobileEvents", - "repositoryURL": "https://github.com/mapbox/mapbox-events-ios.git", - "state": { - "branch": null, - "revision": "e4ded10f5b9594374416f9396d5b540f8c491bbe", - "version": "1.0.3" - } - }, - { - "package": "MapboxMaps", - "repositoryURL": "git@github.com:mapbox/mapbox-maps-ios.git", - "state": { - "branch": null, - "revision": "bedc49744970602ebc10c6de3f8a2b4cc6f084a6", - "version": "10.0.0-rc.8" - } - }, - { - "package": "MapboxSearch", - "repositoryURL": "https://github.com/mapbox/search-ios", - "state": { - "branch": null, - "revision": "9c06beb24ba2d2bf868e14f630773685c10981bd", - "version": "1.0.0-beta.13" - } - }, - { - "package": "Turf", - "repositoryURL": "https://github.com/mapbox/turf-swift.git", - "state": { - "branch": null, - "revision": "555458bd67acce7322c513ddd3647c9a904f4197", - "version": "2.0.0-rc.1" - } + "pins" : [ + { + "identity" : "atlantis", + "kind" : "remoteSourceControl", + "location" : "https://github.com/ProxymanApp/atlantis", + "state" : { + "revision" : "131d757cf8e6e368ad338728379174f7cfff9326", + "version" : "1.23.0" } - ] - }, - "version": 1 + }, + { + "identity" : "mapbox-common-ios", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mapbox/mapbox-common-ios.git", + "state" : { + "revision" : "065cb97a83b8bf8d8584ab56cb6ebed898cc0c97", + "version" : "23.8.6" + } + }, + { + "identity" : "mapbox-core-maps-ios", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mapbox/mapbox-core-maps-ios.git", + "state" : { + "revision" : "798644dafccc37c3be17127e39638f39d6cd57e3", + "version" : "10.16.4" + } + }, + { + "identity" : "mapbox-maps-ios", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mapbox/mapbox-maps-ios.git", + "state" : { + "revision" : "05a275f685ac95982716d87ccb677ebad417c252", + "version" : "10.16.4" + } + }, + { + "identity" : "search-ios", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mapbox/search-ios", + "state" : { + "revision" : "ecd3aa0f782aa0a27267c7118dd6ebd391ea7f82", + "version" : "1.0.0-rc.8" + } + }, + { + "identity" : "turf-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mapbox/turf-swift.git", + "state" : { + "revision" : "f0afe204b4266337066a436becab62fdd2b32378", + "version" : "2.7.0" + } + } + ], + "version" : 2 } diff --git a/Examples/SearchExamples/MapboxBoundingBoxController.swift b/Examples/SearchExamples/MapboxBoundingBoxController.swift index f0d4dc544..5d63cadff 100644 --- a/Examples/SearchExamples/MapboxBoundingBoxController.swift +++ b/Examples/SearchExamples/MapboxBoundingBoxController.swift @@ -20,8 +20,16 @@ class MapboxBoundingBoxController: MapsViewController { super.viewDidAppear(animated) updateSearchResults(proximity: mapboxSFOfficeCoordinate) - - mapDraggingSubscription = mapView.mapboxMap.onEvery(.cameraChanged, handler: reloadResultsOnCameraChange(_:)) + + mapDraggingSubscription = mapView.mapboxMap.onEvery(event: .cameraChanged) { [weak self] cameraChanged in + guard let self else { return } + self.draggingRefreshTimer?.invalidate() + self.draggingRefreshTimer = Timer.scheduledTimer(timeInterval: 1, + target: self, + selector: #selector(self.reloadResultInMapBounds), + userInfo: nil, + repeats: false) + } } func updateSearchResults(proximity: CLLocationCoordinate2D? = nil, boundingBox: MapboxSearch.BoundingBox? = nil) { @@ -39,11 +47,6 @@ class MapboxBoundingBoxController: MapsViewController { } } - func reloadResultsOnCameraChange(_ event: Event) { - draggingRefreshTimer?.invalidate() - draggingRefreshTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(reloadResultInMapBounds), userInfo: nil, repeats: false) - } - @objc func reloadResultInMapBounds() { guard shouldSkipNextCameraChangedUpdate == false else { diff --git a/Examples/SearchExamples/MapboxMapsCategoryResultsViewController.swift b/Examples/SearchExamples/MapboxMapsCategoryResultsViewController.swift index ffc131e57..85ae86ed3 100644 --- a/Examples/SearchExamples/MapboxMapsCategoryResultsViewController.swift +++ b/Examples/SearchExamples/MapboxMapsCategoryResultsViewController.swift @@ -3,7 +3,6 @@ import MapboxSearch class MapboxMapsCategoryResultsViewController: MapsViewController { let searchEngine = CategorySearchEngine() -// let searchEngine = CategorySearchEngine(accessToken: "<#You can pass access token manually#>") override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) diff --git a/Examples/SearchExamples/MapsViewController.swift b/Examples/SearchExamples/MapsViewController.swift index 3f297aee3..20a108325 100644 --- a/Examples/SearchExamples/MapsViewController.swift +++ b/Examples/SearchExamples/MapsViewController.swift @@ -1,3 +1,4 @@ +import UIKit import MapboxMaps import MapboxSearch diff --git a/Examples/SearchExamples/SimpleCategorySearchViewController.swift b/Examples/SearchExamples/SimpleCategorySearchViewController.swift index bbfb7a3f8..479073f8c 100644 --- a/Examples/SearchExamples/SimpleCategorySearchViewController.swift +++ b/Examples/SearchExamples/SimpleCategorySearchViewController.swift @@ -3,7 +3,6 @@ import MapboxSearch class SimpleCategorySearchViewController: MapsViewController { let searchEngine = CategorySearchEngine() -// let searchEngine = CategorySearchEngine(accessToken: "<#You can pass access token manually#>") override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) diff --git a/Examples/SearchExamples/SimpleListSearchViewController.swift b/Examples/SearchExamples/SimpleListSearchViewController.swift index f5e131735..88992e13d 100644 --- a/Examples/SearchExamples/SimpleListSearchViewController.swift +++ b/Examples/SearchExamples/SimpleListSearchViewController.swift @@ -3,7 +3,6 @@ import MapboxSearch class SimpleListSearchViewController: MapsViewController { let searchEngine = SearchEngine() -// let searchEngine = SearchEngine(accessToken: "<#You can pass access token manually#>") override func viewDidLoad() { super.viewDidLoad() diff --git a/Examples/SearchExamples/SimpleUISearchViewController.swift b/Examples/SearchExamples/SimpleUISearchViewController.swift index 729135afa..54e1b8e48 100644 --- a/Examples/SearchExamples/SimpleUISearchViewController.swift +++ b/Examples/SearchExamples/SimpleUISearchViewController.swift @@ -1,5 +1,6 @@ import UIKit import MapboxMaps +import MapboxSearch import MapboxSearchUI class SimpleUISearchViewController: MapsViewController { diff --git a/Makefile b/Makefile index db114ace1..98046d967 100644 --- a/Makefile +++ b/Makefile @@ -30,16 +30,16 @@ offline: aws s3 cp s3://vng-temp/HERE/luxembourg.tgz - | tar -xz -C Sources/Demo/offline/ ci-dev-test: dependencies - fastlane scan --scheme "Demo" --device "iPhone 11 Pro" --result_bundle "true" --testplan "CI-dev" --output_directory "output" + fastlane scan --scheme "Demo" --device "iPhone 13 Pro" --result_bundle "true" --testplan "CI-dev" --output_directory "output" ci-full-test: dependencies - fastlane scan --scheme "Demo" --device "iPhone 11 Pro" --result_bundle "true" --testplan "Demo" --output_directory "output" + fastlane scan --scheme "Demo" --device "iPhone 13 Pro" --result_bundle "true" --testplan "Demo" --output_directory "output" test: dependencies - xcodebuild -scheme MapboxSearchUI -destination platform\=iOS\ Simulator,name\=iPhone\ 11\ Pro clean test + xcodebuild -scheme MapboxSearchUI -destination platform\=iOS\ Simulator,name\=iPhone\ 13\ Pro clean test xctest: dependencies - xcodebuild -scheme MapboxSearch -destination platform\=iOS\ Simulator,name\=iPhone\ 11\ Pro clean test + xcodebuild -scheme MapboxSearch -destination platform\=iOS\ Simulator,name\=iPhone\ 13\ Pro clean test codecov: scripts/coverage/gather_coverage.sh "^MapboxSearch$$" coverage diff --git a/MapboxSearch.podspec b/MapboxSearch.podspec index cd5c80dea..b0d71c5e9 100644 --- a/MapboxSearch.podspec +++ b/MapboxSearch.podspec @@ -19,10 +19,10 @@ Some iOS platform specifics applies. s.author = { 'Mapbox' => 'mobile@mapbox.com' } s.source = { :http => "https://api.mapbox.com/downloads/v2/search-sdk/releases/ios/packages/#{s.version.to_s}/#{s.name}.zip" } - s.ios.deployment_target = '11.0' + s.ios.deployment_target = '12.0' s.swift_versions = [5.2] s.vendored_frameworks = "**/#{s.name}.xcframework" - s.dependency "MapboxCommon", '~> 23.6' + s.dependency "MapboxCommon", '~> 24.0' end diff --git a/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index 343fbc87d..0248f04d6 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 04C0848D2B4C82F3002F9C69 /* SdkInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04C0848C2B4C82F3002F9C69 /* SdkInformation.swift */; }; + 04E5FF962B48828500DADC18 /* SearchAddressCountry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E5FF952B48828500DADC18 /* SearchAddressCountry.swift */; }; + 04E5FF992B48829200DADC18 /* SearchAddressRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E5FF982B48829200DADC18 /* SearchAddressRegion.swift */; }; 043A3D4D2B30F38300DB681B /* CoreAddress+AddressComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043A3D4C2B30F38300DB681B /* CoreAddress+AddressComponents.swift */; }; 140D1BDC286DB479001A51C2 /* SearchResultAccuracy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 140D1BDB286DB479001A51C2 /* SearchResultAccuracy.swift */; }; 140E47A2298BC90E00677E30 /* Discover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 140E47A1298BC90E00677E30 /* Discover.swift */; }; @@ -476,6 +479,9 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 04C0848C2B4C82F3002F9C69 /* SdkInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SdkInformation.swift; sourceTree = ""; }; + 04E5FF952B48828500DADC18 /* SearchAddressCountry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchAddressCountry.swift; sourceTree = ""; }; + 04E5FF982B48829200DADC18 /* SearchAddressRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchAddressRegion.swift; sourceTree = ""; }; 043A3D4C2B30F38300DB681B /* CoreAddress+AddressComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreAddress+AddressComponents.swift"; sourceTree = ""; }; 140D1BDB286DB479001A51C2 /* SearchResultAccuracy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultAccuracy.swift; sourceTree = ""; }; 140E47A1298BC90E00677E30 /* Discover.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Discover.swift; sourceTree = ""; }; @@ -891,6 +897,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 04E5FF972B48829200DADC18 /* Region */ = { + isa = PBXGroup; + children = ( + 04E5FF982B48829200DADC18 /* SearchAddressRegion.swift */, + ); + path = Region; + sourceTree = ""; + }; 140E47A0298BC8F800677E30 /* Discover API */ = { isa = PBXGroup; children = ( @@ -914,6 +928,7 @@ 14173C2C28783DDD00B20E1C /* Country */ = { isa = PBXGroup; children = ( + 04E5FF952B48828500DADC18 /* SearchAddressCountry.swift */, 148DE6612857501D0085684D /* Country.swift */, 14173C2F2878437D00B20E1C /* Country+ISO3166-1.swift */, ); @@ -1161,6 +1176,7 @@ 14173C31287846EA00B20E1C /* Language */, 2C705F042A137CEB00B8B773 /* Navigation */, 14173C3628784A7D00B20E1C /* NonEmptyArray */, + 04E5FF972B48829200DADC18 /* Region */, 14F7186629A1331200D5BC2E /* Result Types */, ); path = Models; @@ -1350,6 +1366,7 @@ FEEDD2E32508DFE400DC0A98 /* AbstractSearchEngine.swift */, FEEDD2D82508DFE400DC0A98 /* SearchEngine.swift */, FEEDD2EB2508DFE400DC0A98 /* CategorySearchEngine.swift */, + 04C0848C2B4C82F3002F9C69 /* SdkInformation.swift */, ); path = Engine; sourceTree = ""; @@ -2337,6 +2354,7 @@ 140E47A7298BCBDF00677E30 /* Discover+Query.swift in Sources */, FEEDD3092508DFE400DC0A98 /* CodablePersistentService.swift in Sources */, FEEDD3192508DFE400DC0A98 /* IndexableDataProvider.swift in Sources */, + 04C0848D2B4C82F3002F9C69 /* SdkInformation.swift in Sources */, 14173C302878437D00B20E1C /* Country+ISO3166-1.swift in Sources */, FEEDD3162508DFE400DC0A98 /* SearchCategorySuggestion.swift in Sources */, FEEDD31D2508DFE400DC0A98 /* HighlightsCalculator.swift in Sources */, @@ -2378,6 +2396,8 @@ 144F32F2298D1FCD0082B2D5 /* Discover+Address.swift in Sources */, FEEDD2FB2508DFE400DC0A98 /* WrapperLocationProvider.swift in Sources */, FE7C73A62566804E0047CA20 /* CoreUserRecordsLayerProtocol.swift in Sources */, + 04E5FF992B48829200DADC18 /* SearchAddressRegion.swift in Sources */, + 04E5FF962B48828500DADC18 /* SearchAddressCountry.swift in Sources */, F9274FEB2732BF0E00708F37 /* SearchTileStore.swift in Sources */, 148DE66C285757AA0085684D /* AddressAutofill+Result.swift in Sources */, FEEDD31C2508DFE400DC0A98 /* IndexableDataResolver.swift in Sources */, diff --git a/MapboxSearchUI.podspec b/MapboxSearchUI.podspec index 775420ff9..e81eb9b47 100644 --- a/MapboxSearchUI.podspec +++ b/MapboxSearchUI.podspec @@ -18,7 +18,7 @@ Card style custom UI with full search functionality powered by Mapbox Search API s.author = { 'Mapbox' => 'mobile@mapbox.com' } s.source = { :http => "https://api.mapbox.com/downloads/v2/search-sdk/releases/ios/packages/#{s.version.to_s}/#{s.name}.zip" } - s.ios.deployment_target = '11.0' + s.ios.deployment_target = '12.0' s.swift_versions = [5.2] s.vendored_frameworks = "**/#{s.name}.xcframework" diff --git a/Package.resolved b/Package.resolved index 5d8dc98c3..943ea9041 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git", "state": { "branch": null, - "revision": "35f9e770f54ce62dd8526470f14c6e137cef3eea", - "version": "2.1.1" + "revision": "3b123999de19bf04905bc1dfdb76f817b0f2cc00", + "version": "2.1.2" } }, { @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git", "state": { "branch": null, - "revision": "c21f7bab5ca8eee0a9998bbd17ca1d0eb45d4688", - "version": "2.1.0" + "revision": "dc9af4781f2afdd1e68e90f80b8603be73ea7abc", + "version": "2.2.0" } }, { @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/mapbox/mapbox-common-ios.git", "state": { "branch": null, - "revision": "584006ae5dcd08ba5ce206c3363bd679600ed39c", - "version": "23.6.0" + "revision": "66c604ce480a5d2e98dbe017b49886652d4d89a2", + "version": "24.0.0" } } ] diff --git a/Package.swift b/Package.swift index 85d6e5760..29452aa81 100644 --- a/Package.swift +++ b/Package.swift @@ -4,10 +4,10 @@ import PackageDescription import Foundation -let (coreSearchVersion, coreSearchVersionHash) = ("0.71.0", "252327e268abc28b9e5546a381d969c5cd1a3a8ccbd4b3ae2a31cef448a61fbc") +let (coreSearchVersion, coreSearchVersionHash) = ("2.0.0-alpha.4", "09077bc9eee2b163964c470dfab1f2ff23b2ab9cf83813aba74b3f7b656d9579") -let commonMinVersion = Version("23.6.0") -let commonMaxVersion = Version("24.0.0") +let commonMinVersion = Version("24.0.0") +let commonMaxVersion = Version("25.0.0") let package = Package( name: "MapboxSearch", diff --git a/README.md b/README.md index 68c9b10cc..6d35ae2ef 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,7 @@ password sk.ey_your_access_token_wit_Read_permission 1. Create a new file named `mapbox` or `.mapbox` in your home directory with content of your access token. We also support `.mapbox` file in the repository root folder. MapboxSearchDemoApplication will automatically handle this key and insert it in corresponding place. _Note: Run `pbpaste > ~/.mapbox` in Terminal.app to insert you Pastebord (Command+C buffer) into `.mapbox` in Home directory._ - 1. Open the Workspace, choose `MapboxSearchDemoApplication` project and select "Info" tab for "MapboxSearchDemoApplication" target. Here you can set your accessToken for `MGLMapboxAccessToken` key in "Custom iOS Target Properties" section. - 1. Provide your accessToken directly in argument named `accessToken` in `SearchDrawer.make(:)` method + 1. Open the Workspace, choose `MapboxSearchDemoApplication` project and select "Info" tab for "MapboxSearchDemoApplication" target. Here you should set your accessToken for `MGLMapboxAccessToken` key in "Custom iOS Target Properties" section. ## Getting Started diff --git a/Search Documentation.docc/CompatibilityGuide.md b/Search Documentation.docc/CompatibilityGuide.md index 89acbb13b..7018a01ac 100644 --- a/Search Documentation.docc/CompatibilityGuide.md +++ b/Search Documentation.docc/CompatibilityGuide.md @@ -5,13 +5,13 @@ What does SDK support ## Overview Mapbox Search SDK works with: -- iOS 11 or newer on any supported iOS powered device including iPad. +- iOS 12 or newer on any supported iOS powered device including iPad. - iOS or Mac Catalyst. It's not possible to run SDK on watchOS or tvOS. macOS support is limited to [Mac Catalyst](https://developer.apple.com/mac-catalyst/). -- Swift 4.2 or newer. -- Xcode 12.5 or newer is recommended for [Swift Package Manager](https://developer.apple.com/documentation/swift_packages) integration. - For non-SPM integration Xcode 11.3 is a minimal requirement. +- Swift 5.7.1 or newer. +- Xcode 14.1 or newer is recommended for [Swift Package Manager](https://developer.apple.com/documentation/swift_packages) integration. + For non-SPM integration Xcode 14.1 is a minimal requirement. - Mapbox Account token with `DOWNLOADS:READ` permission in user NetRC file is required for dependency managers functionality. > Important: Token should be populated in password field inside `~/.netrc` file for `api.mapbox.com` host. diff --git a/SearchUI Documentation.docc/CompatibilityGuide.md b/SearchUI Documentation.docc/CompatibilityGuide.md index 5505a4a52..b6eb0e172 100644 --- a/SearchUI Documentation.docc/CompatibilityGuide.md +++ b/SearchUI Documentation.docc/CompatibilityGuide.md @@ -5,13 +5,13 @@ What does SDK support ## Overview Mapbox Search SDK works with: -- iOS 11 or newer on any supported iOS powered device including iPad. +- iOS 12 or newer on any supported iOS powered device including iPad. - iOS or Mac Catalyst. It's not possible to run SDK on watchOS or tvOS. macOS support is limited to [Mac Catalyst](https://developer.apple.com/mac-catalyst/). -- Swift 4.2 or newer. -- Xcode 12.5 or newer is recommended for [Swift Package Manager](https://developer.apple.com/documentation/swift_packages) integration. - For non-SPM integration Xcode 11.3 is a minimal requirement. +- Swift 5.7.1 or newer. +- Xcode 14.1 or newer is recommended for [Swift Package Manager](https://developer.apple.com/documentation/swift_packages) integration. + For non-SPM integration Xcode 14.1 is a minimal requirement. - Mapbox Account token with `DOWNLOADS:READ` permission in user NetRC file is required for dependency managers functionality. > Important: Token should be populated in password field inside `~/.netrc` file for `api.mapbox.com` host. diff --git a/Sources/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Sources/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index bafb5f04f..3e3f7f398 100644 --- a/Sources/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Sources/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -51,8 +51,8 @@ "repositoryURL": "https://github.com/mapbox/mapbox-common-ios.git", "state": { "branch": null, - "revision": "065cb97a83b8bf8d8584ab56cb6ebed898cc0c97", - "version": "23.8.6" + "revision": "66c604ce480a5d2e98dbe017b49886652d4d89a2", + "version": "24.0.0" } } ] diff --git a/Sources/Demo/Base.lproj/Main.storyboard b/Sources/Demo/Base.lproj/Main.storyboard index 02ec62ac4..806f40fba 100644 --- a/Sources/Demo/Base.lproj/Main.storyboard +++ b/Sources/Demo/Base.lproj/Main.storyboard @@ -34,7 +34,7 @@ - + @@ -75,7 +75,7 @@ - + @@ -233,7 +233,7 @@ - + @@ -306,7 +306,7 @@ - + @@ -405,7 +405,11 @@ + + + + diff --git a/Sources/MapboxSearch/InternalAPI/CoreAliases.swift b/Sources/MapboxSearch/InternalAPI/CoreAliases.swift index c9f2dd9b3..53ab6c32f 100644 --- a/Sources/MapboxSearch/InternalAPI/CoreAliases.swift +++ b/Sources/MapboxSearch/InternalAPI/CoreAliases.swift @@ -24,6 +24,8 @@ typealias CoreImageInfo = MapboxCoreSearch.ImageInfo typealias CoreOpenHours = MapboxCoreSearch.OpenHours typealias CoreOpenPeriod = MapboxCoreSearch.OpenPeriod typealias CoreAccuracy = MapboxCoreSearch.ResultAccuracy +typealias CoreSearchAddressRegion = MapboxCoreSearch.SearchAddressRegion +typealias CoreSearchAddressCountry = MapboxCoreSearch.SearchAddressCountry typealias CoreUserActivityReporter = MapboxCoreSearch.UserActivityReporter typealias CoreUserActivityReporterOptions = MapboxCoreSearch.UserActivityReporterOptions @@ -38,6 +40,7 @@ extension CoreSearchEngine { } typealias CoreExpected = MapboxCommon_Private.Expected +typealias CoreSdkInformation = MapboxCommon_Private.SdkInformation // MARK: - Public @_exported import MapboxCommon diff --git a/Sources/MapboxSearch/InternalAPI/CoreResponseProvider.swift b/Sources/MapboxSearch/InternalAPI/CoreResponseProvider.swift index 48d2b7d36..f34b8ead8 100644 --- a/Sources/MapboxSearch/InternalAPI/CoreResponseProvider.swift +++ b/Sources/MapboxSearch/InternalAPI/CoreResponseProvider.swift @@ -5,6 +5,6 @@ protocol CoreResponseProvider { extension CoreResponseProvider { var searchRequest: SearchRequestOptions { SearchRequestOptions(query: originalResponse.requestOptions.query, - proximity: originalResponse.requestOptions.options.proximity?.coordinate) + proximity: originalResponse.requestOptions.options.proximity?.value) } } diff --git a/Sources/MapboxSearch/InternalAPI/CoreSearchResultProtocol.swift b/Sources/MapboxSearch/InternalAPI/CoreSearchResultProtocol.swift index 420026199..cbea7af6b 100644 --- a/Sources/MapboxSearch/InternalAPI/CoreSearchResultProtocol.swift +++ b/Sources/MapboxSearch/InternalAPI/CoreSearchResultProtocol.swift @@ -21,7 +21,7 @@ protocol CoreSearchResultProtocol { var matchingName: String? { get } - var center: CLLocation? { get } + var centerLocation: CLLocation? { get } var estimatedTime: Measurement? { get } @@ -55,6 +55,10 @@ protocol CoreSearchResultProtocol { } extension CoreSearchResult: CoreSearchResultProtocol { + var centerLocation: CLLocation? { + center.map { CLLocation(latitude: $0.value.latitude, longitude: $0.value.longitude) } + } + var resultTypes: [CoreResultType] { types.compactMap({ CoreResultType(rawValue: $0.intValue) }) } diff --git a/Sources/MapboxSearch/InternalAPI/CoreUserActivityReporter.swift b/Sources/MapboxSearch/InternalAPI/CoreUserActivityReporter.swift index cb72247f1..c50e0cdf0 100644 --- a/Sources/MapboxSearch/InternalAPI/CoreUserActivityReporter.swift +++ b/Sources/MapboxSearch/InternalAPI/CoreUserActivityReporter.swift @@ -3,7 +3,8 @@ import Foundation protocol CoreUserActivityReporterOptionsProtocol { - init(accessToken: String, userAgent: String, eventsUrl: String?) + init(sdkInformation: SdkInformation, eventsUrl: String?) + init(sdkInformation: SdkInformation, eventsUrl: String?, sendEventsDebounce: UInt64, sendEventsInterval: UInt64) } protocol CoreUserActivityReporterProtocol { diff --git a/Sources/MapboxSearch/InternalAPI/WrapperLocationProvider.swift b/Sources/MapboxSearch/InternalAPI/WrapperLocationProvider.swift index daf10887c..56eefb5e6 100644 --- a/Sources/MapboxSearch/InternalAPI/WrapperLocationProvider.swift +++ b/Sources/MapboxSearch/InternalAPI/WrapperLocationProvider.swift @@ -15,10 +15,10 @@ class WrapperLocationProvider: CoreLocationProvider { self.locationProvider = locationProvider } - func getLocation() -> CLLocation? { + func getLocation() -> Coordinate2D? { guard let location = locationProvider.currentLocation() else { return nil } - return CLLocation(latitude: location.latitude, longitude: location.longitude) + return Coordinate2D(value: location) } } diff --git a/Sources/MapboxSearch/PublicAPI/Common/Models/Address/Address.swift b/Sources/MapboxSearch/PublicAPI/Common/Models/Address/Address.swift index c060c38b0..cb97488dd 100644 --- a/Sources/MapboxSearch/PublicAPI/Common/Models/Address/Address.swift +++ b/Sources/MapboxSearch/PublicAPI/Common/Models/Address/Address.swift @@ -29,14 +29,20 @@ public struct Address: Codable, Hashable { /// Features that are smaller than top-level administrative features but typically larger than cities, /// in countries that use such an additional layer in postal addressing (for example, prefectures in China). public var district: String? - + /// Top-level sub-national administrative features, such as states in the United States or provinces in Canada or China. public var region: String? + + /// Top-level sub-national administrative feature object containing the name (required) and ISO 3166-2 subdivision code identifiers. + public var searchAddressRegion: SearchAddressRegion? /// Generally recognized countries or, in some cases like Hong Kong, an area of quasi-national administrative status /// that has been given a designated country code under ISO 3166-1. public var country: String? + /// Generally recognized country object containing the name (required) and ISO 3166-1 country code identifiers. + public var searchAddressCountry: SearchAddressCountry? + /// The postal address associated with the location, formatted for use with the Contacts framework. public var postalAddress: CNPostalAddress { let streetNameAndNumber = [houseNumber, street] @@ -86,8 +92,10 @@ extension Address { postcode: valueOrNil(coreAddress.postcode), place: valueOrNil(coreAddress.place), district: valueOrNil(coreAddress.district), - region: valueOrNil(coreAddress.region), - country: valueOrNil(coreAddress.country) + region: valueOrNil(coreAddress.region?.name), + searchAddressRegion: coreAddress.region.map { SearchAddressRegion($0) }, + country: valueOrNil(coreAddress.country?.name), + searchAddressCountry: coreAddress.country.map { SearchAddressCountry($0) } ) } @@ -99,8 +107,8 @@ extension Address { postcode: postcode, place: place, district: district, - region: region, - country: country) + region: searchAddressRegion?.toCore(), + country: searchAddressCountry?.toCore()) } } diff --git a/Sources/MapboxSearch/PublicAPI/Common/Models/Country/SearchAddressCountry.swift b/Sources/MapboxSearch/PublicAPI/Common/Models/Country/SearchAddressCountry.swift new file mode 100644 index 000000000..d939e3c74 --- /dev/null +++ b/Sources/MapboxSearch/PublicAPI/Common/Models/Country/SearchAddressCountry.swift @@ -0,0 +1,28 @@ +import Foundation + +/// Contains values for a given country including name (required) and possibly ISO 3166-1 Alpha 2 and Alpha 3 codes. +public struct SearchAddressCountry: Codable, Hashable, Equatable { + /// Name of this country + var name: String + + /// ISO 3166-1 Alpha 2 country code + var countryCode: String? + + /// ISO 3166-1 Alpha 3 country code + var countryCodeAlpha3: String? + + init(_ core: CoreSearchAddressCountry) { + self.name = core.name + self.countryCode = core.countryCode + self.countryCodeAlpha3 = core.countryCodeAlpha3 + } +} + +extension SearchAddressCountry { + /// Transform a ``SearchAddressCountry`` to an object compatible with the MapboxCommon framework. + func toCore() -> CoreSearchAddressCountry { + CoreSearchAddressCountry(name: name, + countryCode: countryCode, + countryCodeAlpha3: countryCodeAlpha3) + } +} diff --git a/Sources/MapboxSearch/PublicAPI/Common/Models/Region/SearchAddressRegion.swift b/Sources/MapboxSearch/PublicAPI/Common/Models/Region/SearchAddressRegion.swift new file mode 100644 index 000000000..00276d149 --- /dev/null +++ b/Sources/MapboxSearch/PublicAPI/Common/Models/Region/SearchAddressRegion.swift @@ -0,0 +1,28 @@ +import Foundation + +/// Contains details for top-level sub-national administrative features, such as states in the United States or provinces in Canada or China, including name (required) and code identifiers (optional) +public struct SearchAddressRegion: Codable, Hashable, Equatable { + /// Colloquial name for this region + let name: String + + /// Subdivision portion of ISO 3166-2 code + let regionCode: String? + + /// ISO 3166-2 region code + let regionCodeFull: String? + + init(_ core: CoreSearchAddressRegion) { + self.name = core.name + self.regionCode = core.regionCode + self.regionCodeFull = core.regionCodeFull + } +} + +extension SearchAddressRegion { + /// Transform a ``SearchAddressRegion`` to an object compatible with the MapboxCommon framework. + func toCore() -> CoreSearchAddressRegion { + CoreSearchAddressRegion(name: name, + regionCode: regionCode, + regionCodeFull: regionCodeFull) + } +} diff --git a/Sources/MapboxSearch/PublicAPI/Engine/AbstractSearchEngine.swift b/Sources/MapboxSearch/PublicAPI/Engine/AbstractSearchEngine.swift index 45f4cbf50..489c1b632 100644 --- a/Sources/MapboxSearch/PublicAPI/Engine/AbstractSearchEngine.swift +++ b/Sources/MapboxSearch/PublicAPI/Engine/AbstractSearchEngine.swift @@ -49,21 +49,20 @@ public class AbstractSearchEngine: FeedbackManagerDelegate { /// Basic internal initializer /// - Parameters: - /// - accessToken: Mapbox Access Token to be used. Info.plist value for key `MGLMapboxAccessToken` will be used for `nil` argument /// - locationProvider: Provider configuration of LocationProvider that would grant location data by default /// - serviceProvider: Internal `ServiceProvider` for sharing common dependencies like favoritesService or eventsManager /// - supportSBS: enable support the latest Single-Box Search APIs - init(accessToken: String? = nil, - serviceProvider: ServiceProviderProtocol & EngineProviderProtocol, + init(serviceProvider: ServiceProviderProtocol & EngineProviderProtocol, locationProvider: LocationProvider? = DefaultLocationProvider(), defaultSearchOptions: SearchOptions = SearchOptions(), supportSBS: Bool = false ) { - - guard let accessToken = accessToken ?? serviceProvider.getStoredAccessToken() else { + guard let accessToken = serviceProvider.getStoredAccessToken() else { fatalError("No access token was found. Please, provide it in init(accessToken:) or in Info.plist at '\(accessTokenPlistKey)' key") } - + + MapboxOptions.accessToken = accessToken + self.supportSBS = supportSBS self.locationProvider = locationProvider self.locationProviderWrapper = WrapperLocationProvider(wrapping: locationProvider) @@ -74,18 +73,16 @@ public class AbstractSearchEngine: FeedbackManagerDelegate { self.userActivityReporter = .getOrCreate( for: .init( - accessToken: accessToken, - userAgent: defaultUserAgent, + sdkInformation: SdkInformation.defaultInfo, eventsUrl: nil ) ) self.engine = serviceProvider.createEngine( apiType: engineApi, - accessToken: accessToken, locationProvider: self.locationProviderWrapper ) - self.offlineManager = SearchOfflineManager(engine: engine, tileStore: SearchTileStore(accessToken: accessToken)) + self.offlineManager = SearchOfflineManager(engine: engine, tileStore: SearchTileStore()) self.feedbackManager.delegate = self _Logger.searchSDK.info("Init \(self) for API v.\(engineApi)") @@ -103,18 +100,15 @@ public class AbstractSearchEngine: FeedbackManagerDelegate { /// Initializer with safe-to-go defaults /// - Parameters: - /// - accessToken: Mapbox Access Token to be used. Info.plist value for key `MGLMapboxAccessToken` will be used for `nil` argument /// - locationProvider: Provider configuration of LocationProvider that would grant location data by default /// - defaultSearchOptions: Default options to use when `nil` was passed to the `search(…: options:)` call /// - supportSBS: enable support the latest Single-Box Search APIs public convenience init( - accessToken: String? = nil, locationProvider: LocationProvider? = DefaultLocationProvider(), defaultSearchOptions: SearchOptions = SearchOptions(), supportSBS: Bool = false ) { self.init( - accessToken: accessToken, serviceProvider: ServiceProvider.shared, locationProvider: locationProvider, defaultSearchOptions: defaultSearchOptions, diff --git a/Sources/MapboxSearch/PublicAPI/Engine/SdkInformation.swift b/Sources/MapboxSearch/PublicAPI/Engine/SdkInformation.swift new file mode 100644 index 000000000..e0757aa3f --- /dev/null +++ b/Sources/MapboxSearch/PublicAPI/Engine/SdkInformation.swift @@ -0,0 +1,11 @@ +// Copyright © 2024 Mapbox. All rights reserved. + +import Foundation + +extension SdkInformation { + static var defaultInfo: SdkInformation { + SdkInformation(name: "mapbox-search-ios", + version: mapboxSearchSDKVersion, + packageName: nil) + } +} diff --git a/Sources/MapboxSearch/PublicAPI/Engine/SearchEngine.swift b/Sources/MapboxSearch/PublicAPI/Engine/SearchEngine.swift index 869ea0617..e5a02c57a 100644 --- a/Sources/MapboxSearch/PublicAPI/Engine/SearchEngine.swift +++ b/Sources/MapboxSearch/PublicAPI/Engine/SearchEngine.swift @@ -407,14 +407,14 @@ extension SearchEngine { /// - Parameter suggestions: suggestions list to resolve. All suggestions must originate from the same search request. public func select(suggestions: [SearchSuggestion]) { for suggestion in suggestions { - let supported = (suggestion as? CoreResponseProvider)?.originalResponse.coreResult.action?.isMultiRetrievable == true + let supported = (suggestion as? CoreResponseProvider)?.originalResponse.coreResult.action?.multiRetrievable == true if !supported { _Logger.searchSDK.warning("Unsupported suggestion: \(suggestion.name) of type: \(suggestion.suggestionType)") } } let suggestionsImpls = suggestions .compactMap({ $0 as? CoreResponseProvider }) - .filter({ $0.originalResponse.coreResult.action?.isMultiRetrievable == true }) + .filter({ $0.originalResponse.coreResult.action?.multiRetrievable == true }) guard suggestionsImpls.isEmpty == false else { return diff --git a/Sources/MapboxSearch/PublicAPI/IndexableRecord.swift b/Sources/MapboxSearch/PublicAPI/IndexableRecord.swift index 9d0870565..3b5baa831 100644 --- a/Sources/MapboxSearch/PublicAPI/IndexableRecord.swift +++ b/Sources/MapboxSearch/PublicAPI/IndexableRecord.swift @@ -25,6 +25,6 @@ extension IndexableRecord { .compactMap({ $0 }) .forEach({ tokens.insert($0) }) - return CoreUserRecord(id: id, name: name, center: CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude), address: address?.coreAddress(), categories: nil, indexTokens: Array(tokens)) + return CoreUserRecord(id: id, name: name, center: Coordinate2D(value: coordinate), address: address?.coreAddress(), categories: nil, indexTokens: Array(tokens)) } } diff --git a/Sources/MapboxSearch/PublicAPI/Offline/SearchOfflineManager.swift b/Sources/MapboxSearch/PublicAPI/Offline/SearchOfflineManager.swift index d9cb1fc2b..133f8e0a1 100644 --- a/Sources/MapboxSearch/PublicAPI/Offline/SearchOfflineManager.swift +++ b/Sources/MapboxSearch/PublicAPI/Offline/SearchOfflineManager.swift @@ -33,10 +33,9 @@ public class SearchOfflineManager { /// Sets custom tile store. /// - Parameters: /// - tileStore: TileStore to set into SearchEngine. - /// - accessToken: Mapbox Access Token. /// - completion: this completion called right after SearchEngine finished consuming data from provided TileStore. One can start using offline search after that. - public func setTileStore(_ tileStore: MapboxCommon.TileStore, accessToken: String, completion: (() -> Void)? = nil) { - let searchTileStore = SearchTileStore(commonTileStore: tileStore, accessToken: accessToken) + public func setTileStore(_ tileStore: MapboxCommon.TileStore, completion: (() -> Void)? = nil) { + let searchTileStore = SearchTileStore(commonTileStore: tileStore) self.tileStore = searchTileStore engine.setTileStore(searchTileStore.commonTileStore, completion: completion) } diff --git a/Sources/MapboxSearch/PublicAPI/Offline/SearchTileStore.swift b/Sources/MapboxSearch/PublicAPI/Offline/SearchTileStore.swift index f58c235b3..e2eb988c5 100644 --- a/Sources/MapboxSearch/PublicAPI/Offline/SearchTileStore.swift +++ b/Sources/MapboxSearch/PublicAPI/Offline/SearchTileStore.swift @@ -7,8 +7,6 @@ import Foundation /// Use `commonTileStore` property to access underlaying `MapboxCommon.TileStore` public class SearchTileStore { - struct AccessTokenNotFound: Error { } - /// Default API Url used for `Search` tile data domain. public let defaultEndPoint = "https://api.mapbox.com" @@ -17,58 +15,34 @@ public class SearchTileStore { /// Creates with shared `MapboxCommon.TileStore` instance at the default location. /// Creates a new `MapboxCommon.TileStore` if one doesn't yet exist. - /// - Parameter accessToken: Mapbox access token - public init(accessToken: String) { + public init() { commonTileStore = MapboxCommon.TileStore.__create() - setup(tileStore: commonTileStore, accessToken: accessToken) - } - - /// Creates with shared `MapboxCommon.TileStore` instance at the default location. - /// Creates a new `MapboxCommon.TileStore` if one doesn't yet exist. - /// Throws AccessTokenNotFound if no access token found. - public convenience init() throws { - guard let token = ServiceProvider.shared.getStoredAccessToken() else { - throw AccessTokenNotFound() - } - self.init(accessToken: token) + setup(tileStore: commonTileStore) } - + /// Creates with custom CommonTileStore. /// - Parameter commonTileStore: SearchEngine will start using provided TileStore - /// - Parameter accessToken: Mapbox access token - public init(commonTileStore: MapboxCommon.TileStore, accessToken: String) { + public init(commonTileStore: MapboxCommon.TileStore) { self.commonTileStore = commonTileStore - setup(tileStore: commonTileStore, accessToken: accessToken) - } - - /// Creates with custom CommonTileStore. - /// - Parameter commonTileStore: SearchEngine will start using provided TileStore - /// Throws AccessTokenNotFound if no access token found. - public convenience init(commonTileStore: MapboxCommon.TileStore) throws { - guard let token = ServiceProvider.shared.getStoredAccessToken() else { - throw AccessTokenNotFound() - } - self.init(commonTileStore: commonTileStore, accessToken: token) + setup(tileStore: commonTileStore) } /// Creates with shared `MapboxCommon.TileStore` instance for the given storage path. /// Creates a new `MapboxCommon.TileStore` if one doesn't yet exist. /// If the given path is empty, the tile store at the default location is returned. /// - Parameters: - /// - accessToken: Mapbox access token /// - path: The path on disk where tiles and metadata will be stored. - public init(accessToken: String, path: String) { + public init(path: String) { commonTileStore = MapboxCommon.TileStore.__create(forPath: path) - setup(tileStore: commonTileStore, accessToken: accessToken) + setup(tileStore: commonTileStore) } + + // MARK: - - func setup(tileStore: MapboxCommon.TileStore, accessToken: String) { + func setup(tileStore: MapboxCommon.TileStore) { tileStore.setOptionForKey(MapboxCommon.TileStoreOptions.mapboxAPIURL, domain: MapboxCommon.TileDataDomain.search, value: defaultEndPoint) - tileStore.setOptionForKey(MapboxCommon.TileStoreOptions.mapboxAccessToken, - domain: MapboxCommon.TileDataDomain.search, - value: accessToken) } /// Loads a new tile region or updates the existing one. diff --git a/Sources/MapboxSearch/PublicAPI/Offline/TileRegionLoadOptions+Search.swift b/Sources/MapboxSearch/PublicAPI/Offline/TileRegionLoadOptions+Search.swift index 5415feb29..bcda58790 100644 --- a/Sources/MapboxSearch/PublicAPI/Offline/TileRegionLoadOptions+Search.swift +++ b/Sources/MapboxSearch/PublicAPI/Offline/TileRegionLoadOptions+Search.swift @@ -36,13 +36,13 @@ extension TileRegionLoadOptions { return nil } } - + return TileRegionLoadOptions(__geometry: geometry, descriptors: descriptors, metadata: metadata, acceptExpired: acceptExpired, networkRestriction: networkRestriction, - start: nil, + startLocation: nil, averageBytesPerSecond: averageBytesPerSecond.map(NSNumber.init), extraOptions: nil) } diff --git a/Sources/MapboxSearch/PublicAPI/Search Results/ExternalRecordPlaceholder.swift b/Sources/MapboxSearch/PublicAPI/Search Results/ExternalRecordPlaceholder.swift index 15c95dde9..c8763f30f 100644 --- a/Sources/MapboxSearch/PublicAPI/Search Results/ExternalRecordPlaceholder.swift +++ b/Sources/MapboxSearch/PublicAPI/Search Results/ExternalRecordPlaceholder.swift @@ -39,7 +39,7 @@ class ExternalRecordPlaceholder: SearchResultSuggestion, CoreResponseProvider { self.serverIndex = coreResult.serverIndex?.intValue self.descriptionText = coreResult.addresses?.first.map(Address.init)?.formattedAddress(style: .medium) - self.batchResolveSupported = coreResult.action?.isMultiRetrievable ?? false + self.batchResolveSupported = coreResult.action?.multiRetrievable ?? false switch layerIdentifier { case HistoryProvider.providerIdentifier: diff --git a/Sources/MapboxSearch/PublicAPI/Search Results/SearchCategorySuggestionImpl.swift b/Sources/MapboxSearch/PublicAPI/Search Results/SearchCategorySuggestionImpl.swift index 823c1541d..bfe274e5e 100644 --- a/Sources/MapboxSearch/PublicAPI/Search Results/SearchCategorySuggestionImpl.swift +++ b/Sources/MapboxSearch/PublicAPI/Search Results/SearchCategorySuggestionImpl.swift @@ -25,7 +25,7 @@ class SearchCategorySuggestionImpl: SearchCategorySuggestion, CoreResponseProvid let batchResolveSupported: Bool init?(coreResult: CoreSearchResultProtocol, response: CoreSearchResponseProtocol) { - assert(coreResult.center == nil) + assert(coreResult.centerLocation == nil) guard coreResult.resultTypes == [.category] else { return nil } @@ -37,7 +37,7 @@ class SearchCategorySuggestionImpl: SearchCategorySuggestion, CoreResponseProvid self.serverIndex = coreResult.serverIndex?.intValue self.originalResponse = CoreSearchResultResponse(coreResult: coreResult, response: response) self.distance = coreResult.distanceToProximity - self.batchResolveSupported = coreResult.action?.isMultiRetrievable ?? false + self.batchResolveSupported = coreResult.action?.multiRetrievable ?? false self.categories = coreResult.categories self.descriptionText = coreResult.addressDescription diff --git a/Sources/MapboxSearch/PublicAPI/Search Results/SearchQuerySuggestionImpl.swift b/Sources/MapboxSearch/PublicAPI/Search Results/SearchQuerySuggestionImpl.swift index 4fcc83608..32c9d9910 100644 --- a/Sources/MapboxSearch/PublicAPI/Search Results/SearchQuerySuggestionImpl.swift +++ b/Sources/MapboxSearch/PublicAPI/Search Results/SearchQuerySuggestionImpl.swift @@ -26,7 +26,7 @@ class SearchQuerySuggestionImpl: SearchQuerySuggestion, CoreResponseProvider { let batchResolveSupported: Bool init?(coreResult: CoreSearchResultProtocol, response: CoreSearchResponseProtocol) { - assert(coreResult.center == nil) + assert(coreResult.centerLocation == nil) guard coreResult.resultTypes == [.query] else { return nil } @@ -37,7 +37,7 @@ class SearchQuerySuggestionImpl: SearchQuerySuggestion, CoreResponseProvider { self.iconName = nil // Queries should use it's special icon self.originalResponse = CoreSearchResultResponse(coreResult: coreResult, response: response) self.distance = coreResult.distanceToProximity - self.batchResolveSupported = coreResult.action?.isMultiRetrievable ?? false + self.batchResolveSupported = coreResult.action?.multiRetrievable ?? false self.categories = coreResult.categories self.descriptionText = coreResult.addressDescription diff --git a/Sources/MapboxSearch/PublicAPI/Search Results/SearchResultSuggestionImpl.swift b/Sources/MapboxSearch/PublicAPI/Search Results/SearchResultSuggestionImpl.swift index 9e1823d7e..0fb17b828 100644 --- a/Sources/MapboxSearch/PublicAPI/Search Results/SearchResultSuggestionImpl.swift +++ b/Sources/MapboxSearch/PublicAPI/Search Results/SearchResultSuggestionImpl.swift @@ -26,9 +26,9 @@ class SearchResultSuggestionImpl: SearchResultSuggestion, CoreResponseProvider { let batchResolveSupported: Bool init?(coreResult: CoreSearchResultProtocol, response: CoreSearchResponseProtocol) { - assert(coreResult.center == nil, "CoreSearchResult should not contain coordinate. Instantiate \(ServerSearchResult.self) instead.") + assert(coreResult.centerLocation == nil, "CoreSearchResult should not contain coordinate. Instantiate \(ServerSearchResult.self) instead.") - guard coreResult.center == nil else { return nil } + guard coreResult.centerLocation == nil else { return nil } switch coreResult.resultTypes { case _ where CoreResultType.hasOnlyAddressSubtypes(types: coreResult.resultTypes): @@ -48,7 +48,7 @@ class SearchResultSuggestionImpl: SearchResultSuggestion, CoreResponseProvider { self.serverIndex = coreResult.serverIndex?.intValue self.originalResponse = CoreSearchResultResponse(coreResult: coreResult, response: response) self.distance = coreResult.distanceToProximity - self.batchResolveSupported = coreResult.action?.isMultiRetrievable ?? false + self.batchResolveSupported = coreResult.action?.multiRetrievable ?? false self.categories = coreResult.categories self.descriptionText = coreResult.addressDescription diff --git a/Sources/MapboxSearch/PublicAPI/Search Results/ServerSearchResult.swift b/Sources/MapboxSearch/PublicAPI/Search Results/ServerSearchResult.swift index 5d264be7a..50e4ed596 100644 --- a/Sources/MapboxSearch/PublicAPI/Search Results/ServerSearchResult.swift +++ b/Sources/MapboxSearch/PublicAPI/Search Results/ServerSearchResult.swift @@ -55,11 +55,11 @@ class ServerSearchResult: SearchResult, SearchResultSuggestion, CoreResponseProv } init?(coreResult: CoreSearchResultProtocol, response: CoreSearchResponseProtocol) { - guard let coordinate = coreResult.center?.coordinate else { return nil } + guard let center = coreResult.centerLocation else { return nil } guard let type = SearchResultType(coreResultTypes: coreResult.resultTypes) else { return nil } self.type = type - + self.id = coreResult.id self.name = coreResult.names[0] self.matchingName = coreResult.matchingName @@ -70,12 +70,14 @@ class ServerSearchResult: SearchResult, SearchResultSuggestion, CoreResponseProv self.accuracy = coreResult.resultAccuracy.flatMap(SearchResultAccuracy.from(coreAccuracy:)) self.address = coreResult.addresses?.first.map(Address.init) self.categories = coreResult.categories - self.coordinateCodable = .init(coordinate) + self.coordinateCodable = .init(center.coordinate) self.originalResponse = CoreSearchResultResponse(coreResult: coreResult, response: response) - self.distance = coreResult.distanceToProximity ?? - response.request.options.proximity?.distance(from: CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)) + + let proximityValue = response.request.options.proximity?.value + let proximityLocation = proximityValue.map { CLLocation(latitude: $0.latitude, longitude: $0.longitude) } + self.distance = coreResult.distanceToProximity ?? proximityLocation?.distance(from: center) self.routablePoints = coreResult.routablePoints?.map(RoutablePoint.init) - self.batchResolveSupported = coreResult.action?.isMultiRetrievable ?? false + self.batchResolveSupported = coreResult.action?.multiRetrievable ?? false self.descriptionText = coreResult.addressDescription assert(!id.isEmpty) diff --git a/Sources/MapboxSearch/PublicAPI/SearchOptions.swift b/Sources/MapboxSearch/PublicAPI/SearchOptions.swift index db1ebb795..954a121ca 100644 --- a/Sources/MapboxSearch/PublicAPI/SearchOptions.swift +++ b/Sources/MapboxSearch/PublicAPI/SearchOptions.swift @@ -162,14 +162,14 @@ public struct SearchOptions { public var defaultDebounce: TimeInterval = 300 init(coreSearchOptions options: CoreSearchOptions) { - let proximity = options.proximity.map { CLLocationCoordinate2D(latitude: $0.coordinate.latitude, longitude: $0.coordinate.longitude) } - let origin = options.origin.map { CLLocationCoordinate2D(latitude: $0.coordinate.latitude, longitude: $0.coordinate.longitude) } + let proximity = options.proximity.map { CLLocationCoordinate2D(latitude: $0.value.latitude, longitude: $0.value.longitude) } + let origin = options.origin.map { CLLocationCoordinate2D(latitude: $0.value.latitude, longitude: $0.value.longitude) } let filterTypes: [SearchQueryType]? = options.types? .compactMap({ CoreQueryType(rawValue: $0.intValue) }) .compactMap({ SearchQueryType.fromCoreValue($0) }) var routeOptions: RouteOptions? - let coordinates = options.route?.map({ $0.coordinate }) + let coordinates = options.route?.map({ $0.value }) if let route = coordinates.map({ Route(coordinates: $0) }), let time = options.timeDeviation.map({ TimeInterval($0.floatValue * 60) }) { let sarType = RouteOptions.Deviation.SARType(coreValue: options.sarType) routeOptions = RouteOptions(route: route, time: time, sarType: sarType) @@ -188,7 +188,7 @@ public struct SearchOptions { navigationOptions: profile, routeOptions: routeOptions, filterTypes: filterTypes, - ignoreIndexableRecords: options.isIgnoreUR, + ignoreIndexableRecords: options.ignoreUR, indexableRecordsDistanceThreshold: options.urDistanceThreshold?.doubleValue, unsafeParameters: options.addonAPI) } @@ -204,9 +204,9 @@ public struct SearchOptions { } else { searchLanguages = languages } - - return CoreSearchOptions(proximity: proximity.flatMap({ CLLocation(latitude: $0.latitude, longitude: $0.longitude) }), - origin: origin.flatMap({ CLLocation(latitude: $0.latitude, longitude: $0.longitude) }), + + return CoreSearchOptions(proximity: proximity.map(Coordinate2D.init(value:)), + origin: origin.map(Coordinate2D.init(value:)), navProfile: navigationOptions?.profile.string, etaType: navigationOptions?.etaType.toCore(), bbox: boundingBox.map(CoreBoundingBox.init), @@ -218,7 +218,7 @@ public struct SearchOptions { ignoreUR: ignoreIndexableRecords, urDistanceThreshold: indexableRecordsDistanceThreshold.map(NSNumber.init), requestDebounce: NSNumber(value: defaultDebounce), - route: routeOptions?.route.coordinates.map({ CLLocation(latitude: $0.latitude, longitude: $0.longitude) }), + route: routeOptions?.route.coordinates.map(Coordinate2D.init(value:)), sarType: routeOptions?.deviation.sarType?.toCore(), timeDeviation: routeOptions?.deviation.time.map({ $0 / 60 }).map(NSNumber.init), addonAPI: unsafeParameters) diff --git a/Sources/MapboxSearch/PublicAPI/ServiceProvider.swift b/Sources/MapboxSearch/PublicAPI/ServiceProvider.swift index 3cc051b00..62ea5b776 100644 --- a/Sources/MapboxSearch/PublicAPI/ServiceProvider.swift +++ b/Sources/MapboxSearch/PublicAPI/ServiceProvider.swift @@ -15,7 +15,6 @@ protocol ServiceProviderProtocol { protocol EngineProviderProtocol { func createEngine( apiType: CoreSearchEngine.ApiType, - accessToken: String, locationProvider: CoreLocationProvider? ) -> CoreSearchEngineProtocol @@ -56,22 +55,20 @@ extension ServiceProvider: EngineProviderProtocol { Bundle.main.object(forInfoDictionaryKey: accessTokenPlistKey) as? String ?? Bundle.main.object(forInfoDictionaryKey: legacyAccessTokenPlistKey) as? String } - + func createEngine( apiType: CoreSearchEngine.ApiType, - accessToken: String, locationProvider: CoreLocationProvider? ) -> CoreSearchEngineProtocol { // UserDefaults can be used to setup base url in runtime (e.g. UI tests) // UserDefaults can be used to setup base url in runtime (e.g. UI tests) let defaultsBaseURL = UserDefaults.standard.value(forKey: baseURLPlistKey) as? String let bundleBaseURL = Bundle.main.object(forInfoDictionaryKey: baseURLPlistKey) as? String - + let engineOptions = CoreSearchEngine.Options( - accessToken: accessToken, baseUrl: bundleBaseURL ?? defaultsBaseURL, apiType: NSNumber(value: apiType.rawValue), - userAgent: eventsManager.userAgentName, + sdkInformation: SdkInformation.defaultInfo, eventsUrl: nil ) diff --git a/Sources/MapboxSearch/PublicAPI/Telemetry/FeedbackManager.swift b/Sources/MapboxSearch/PublicAPI/Telemetry/FeedbackManager.swift index b2340d0d6..5d450d61b 100644 --- a/Sources/MapboxSearch/PublicAPI/Telemetry/FeedbackManager.swift +++ b/Sources/MapboxSearch/PublicAPI/Telemetry/FeedbackManager.swift @@ -63,7 +63,7 @@ public class FeedbackManager { } if let proximity = response.request.options.proximity { - attributes["proximity"] = [proximity.coordinate.longitude, proximity.coordinate.latitude] + attributes["proximity"] = [proximity.value.longitude, proximity.value.latitude] } attributes["responseUuid"] = response.responseUUID @@ -76,7 +76,7 @@ public class FeedbackManager { attributes["language"] = result?.languages attributes["resultId"] = result?.id ?? attributePlaceholder - if let center = result?.center { + if let center = result?.centerLocation { attributes["resultCoordinates"] = [center.coordinate.longitude, center.coordinate.latitude] } } @@ -101,7 +101,7 @@ public class FeedbackManager { attributes["external_ids"] = result.externalIDs attributes["category"] = result.categories - if let center = result.center { + if let center = result.centerLocation { attributes["coordinates"] = [center.coordinate.longitude, center.coordinate.latitude] } diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift index b4fb5a35e..397698092 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/AddressAutofill.swift @@ -19,26 +19,16 @@ public final class AddressAutofill { /// Basic internal initializer /// - Parameters: - /// - accessToken: Mapbox Access Token to be used. Info.plist value for key `MGLMapboxAccessToken` will be used for `nil` argument /// - locationProvider: Provider configuration of LocationProvider that would grant location data by default - public convenience init( - accessToken: String? = nil, - locationProvider: LocationProvider? = DefaultLocationProvider() - ) { - guard let accessToken = accessToken ?? ServiceProvider.shared.getStoredAccessToken() else { - fatalError("No access token was found. Please, provide it in init(accessToken:) or in Info.plist at '\(accessTokenPlistKey)' key") - } - + public convenience init(locationProvider: LocationProvider? = DefaultLocationProvider()) { let searchEngine = ServiceProvider.shared.createEngine( apiType: Self.apiType, - accessToken: accessToken, locationProvider: WrapperLocationProvider(wrapping: locationProvider) ) - + let userActivityReporter = CoreUserActivityReporter.getOrCreate( for: CoreUserActivityReporterOptions( - accessToken: accessToken, - userAgent: defaultUserAgent, + sdkInformation: SdkInformation.defaultInfo, eventsUrl: nil ) ) @@ -222,7 +212,7 @@ private extension AddressAutofill { return Suggestion(name: name, formattedAddress: fullAddress, - coordinate: result.center?.coordinate, + coordinate: result.center?.value, addressComponents: resultAddress, underlying: underlying) } diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/CoreAddress+AddressComponents.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/CoreAddress+AddressComponents.swift index 724a2357b..0815530c8 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/CoreAddress+AddressComponents.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Address Autofill/Models/Suggestion/CoreAddress+AddressComponents.swift @@ -17,8 +17,8 @@ extension CoreAddress { postcode.map { components.append(.init(kind: .postcode, value: $0)) } place.map { components.append(.init(kind: .place, value: $0)) } district.map { components.append(.init(kind: .district, value: $0)) } - region.map { components.append(.init(kind: .region, value: $0)) } - country.map { components.append(.init(kind: .country, value: $0)) } + region.map { components.append(.init(kind: .region, value: $0.name)) } + country.map { components.append(.init(kind: .country, value: $0.name)) } guard let first = components.first else { throw AutofillParsingError.emptyAddressComponents diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift index c8b0bb2b6..af6ca4970 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift @@ -9,26 +9,18 @@ public final class Discover { /// Basic internal initializer /// - Parameters: - /// - accessToken: Mapbox Access Token to be used. Info.plist value for key `MGLMapboxAccessToken` will be used for `nil` argument /// - locationProvider: Provider configuration of LocationProvider that would grant location data by default public convenience init( - accessToken: String? = nil, locationProvider: LocationProvider? = DefaultLocationProvider() ) { - guard let accessToken = accessToken ?? ServiceProvider.shared.getStoredAccessToken() else { - fatalError("No access token was found. Please, provide it in init(accessToken:) or in Info.plist at '\(accessTokenPlistKey)' key") - } - let searchEngine = CategorySearchEngine( - accessToken: accessToken, locationProvider: locationProvider, supportSBS: true ) let userActivityReporter = CoreUserActivityReporter.getOrCreate( for: CoreUserActivityReporterOptions( - accessToken: accessToken, - userAgent: defaultUserAgent, + sdkInformation: SdkInformation.defaultInfo, eventsUrl: nil ) ) diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift index 5b802d8a3..ca786bce5 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/Models/PlaceAutocomplete+Suggestion.swift @@ -129,7 +129,7 @@ extension PlaceAutocomplete.Suggestion { throw Error.invalidResultType } - guard let coordinate = searchSuggestion.center?.coordinate, + guard let coordinate = searchSuggestion.centerLocation?.coordinate, CLLocationCoordinate2DIsValid(coordinate) else { throw Error.invalidCoordinates } diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift index 058c0fbbd..ddfccbdc1 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Place Autocomplete/PlaceAutocomplete.swift @@ -20,26 +20,16 @@ public final class PlaceAutocomplete { /// Basic internal initializer /// - Parameters: - /// - accessToken: Mapbox Access Token to be used. Info.plist value for key `MGLMapboxAccessToken` will be used for `nil` argument /// - locationProvider: Provider configuration of LocationProvider that would grant location data by default - public convenience init( - accessToken: String? = nil, - locationProvider: LocationProvider? = DefaultLocationProvider() - ) { - guard let accessToken = accessToken ?? ServiceProvider.shared.getStoredAccessToken() else { - fatalError("No access token was found. Please, provide it in init(accessToken:) or in Info.plist at '\(accessTokenPlistKey)' key") - } - + public convenience init(locationProvider: LocationProvider? = DefaultLocationProvider()) { let searchEngine = ServiceProvider.shared.createEngine( apiType: Self.apiType, - accessToken: accessToken, locationProvider: WrapperLocationProvider(wrapping: locationProvider) ) let userActivityReporter = CoreUserActivityReporter.getOrCreate( for: CoreUserActivityReporterOptions( - accessToken: accessToken, - userAgent: defaultUserAgent, + sdkInformation: SdkInformation.defaultInfo, eventsUrl: nil ) ) @@ -303,7 +293,7 @@ private extension PlaceAutocomplete { return Suggestion(name: name, description: result.addressDescription, - coordinate: result.center?.coordinate, + coordinate: result.center?.value, iconName: result.icon, distance: distance, estimatedTime: result.estimatedTime, diff --git a/Sources/MapboxSearchUI/MapboxSearchController.swift b/Sources/MapboxSearchUI/MapboxSearchController.swift index ccff9d204..82d46f132 100644 --- a/Sources/MapboxSearchUI/MapboxSearchController.swift +++ b/Sources/MapboxSearchUI/MapboxSearchController.swift @@ -145,20 +145,6 @@ public class MapboxSearchController: UIViewController { } } - /// Instantiate MapboxSearchController with explicit accessToken and custom location provider - /// - Parameters: - /// - accessToken: Mapbox public access token. Checkout `init(locationProvider:)` to - /// - configuration: configuration for search and categorySearch engines. - public required init(accessToken: String, configuration: Configuration = Configuration()) { - self.categorySearchEngine = CategorySearchEngine(accessToken: accessToken, locationProvider: configuration.locationProvider) - self.searchEngine = SearchEngine(accessToken: accessToken, locationProvider: configuration.locationProvider) - self.configuration = configuration - - super.init(nibName: nil, bundle: .mapboxSearchUI) - - self.searchEngine.delegate = self - } - /// MapboxSearchController initializer with accessToken taken from application Info.plist /// /// Access token is expected to be at `MGLMapboxAccessToken` key in application Info.plist. diff --git a/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift index 2a6adf39a..0b4e4979f 100644 --- a/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift @@ -11,7 +11,6 @@ final class AddressAutofillIntegrationTests: MockServerTestCase { super.setUp() addressAutofill = AddressAutofill( - accessToken: "access-token", locationProvider: DefaultLocationProvider() ) } diff --git a/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift index 7b3c48d2c..e9abc66b5 100644 --- a/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift @@ -5,7 +5,6 @@ import CoreLocation class CategorySearchEngineIntegrationTests: MockServerTestCase { lazy var searchEngine = CategorySearchEngine( - accessToken: "access-token", locationProvider: DefaultLocationProvider(), supportSBS: true ) diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index d03a98a8b..83779e7b9 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -26,10 +26,8 @@ class OfflineIntegrationTests: MockServerTestCase { } wait(for: [enableOfflineExpectation], timeout: 10) - // Integration offline tests requires tileStore with valid access token. - // TestTileStore builds TileStore with stored access or nil if none found // TestTileStore builds tileStores with unique path allowing runs tests in parallel - let tileStore = try XCTUnwrap(TestTileStore.build()) + let tileStore = TestTileStore.build() let setTileStoreExpectation = expectation(description: "TileStore setup completion") searchEngine.offlineManager.setTileStore(tileStore) { setTileStoreExpectation.fulfill() diff --git a/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift index 240d45db1..fc6c4e882 100644 --- a/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift @@ -11,7 +11,6 @@ final class PlaceAutocompleteIntegrationTests: MockServerTestCase { super.setUp() placeAutocomplete = PlaceAutocomplete( - accessToken: "access-token", locationProvider: DefaultLocationProvider() ) } @@ -75,7 +74,7 @@ final class PlaceAutocompleteIntegrationTests: MockServerTestCase { } suggestion = suggestions[0] let coordinate = CLLocationCoordinate2D(latitude: 38.900017, longitude: -77.032161) - XCTAssertEqual(coreSuggestion.center?.coordinate, coordinate) + XCTAssertEqual(coreSuggestion.centerLocation?.coordinate, coordinate) XCTAssertEqual(suggestion?.coordinate, coordinate) let point = RoutablePoint( name: "POI", @@ -188,7 +187,7 @@ final class PlaceAutocompleteIntegrationTests: MockServerTestCase { } suggestion = suggestions[0] let coordinate = CLLocationCoordinate2D(latitude: 38.900017, longitude: -77.032161) - XCTAssertEqual(coreSuggestion.center?.coordinate, coordinate) + XCTAssertEqual(coreSuggestion.centerLocation?.coordinate, coordinate) XCTAssertEqual(suggestion?.coordinate, coordinate) let point = RoutablePoint( name: "POI", diff --git a/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift index 3999b94bb..5102897a2 100644 --- a/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift @@ -6,7 +6,6 @@ class SearchEngineIntegrationTests: MockServerTestCase { let delegate = SearchEngineDelegateStub() lazy var searchEngine = SearchEngine( - accessToken: "access-token", locationProvider: DefaultLocationProvider(), supportSBS: true ) diff --git a/Tests/MapboxSearchTests/Common/Data Samples/CLLocationCoordinate2D+Samples.swift b/Tests/MapboxSearchTests/Common/Data Samples/CLLocationCoordinate2D+Samples.swift index 3f62b55fb..296094186 100644 --- a/Tests/MapboxSearchTests/Common/Data Samples/CLLocationCoordinate2D+Samples.swift +++ b/Tests/MapboxSearchTests/Common/Data Samples/CLLocationCoordinate2D+Samples.swift @@ -18,3 +18,8 @@ extension CLLocationCoordinate2DCodable { static let sample1 = CLLocationCoordinate2DCodable(.sample1) static let sample2 = CLLocationCoordinate2DCodable(.sample2) } + +extension Coordinate2D { + static let sample1 = Coordinate2D(value: .sample1) + static let sample2 = Coordinate2D(value: .sample2) +} diff --git a/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchOptions+Samples.swift b/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchOptions+Samples.swift index 861f88d67..2db3fa720 100644 --- a/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchOptions+Samples.swift +++ b/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchOptions+Samples.swift @@ -19,8 +19,8 @@ extension CoreSearchOptions { urDistanceThreshold: NSNumber(value: 300), requestDebounce: 1, route: [ - CLLocation(latitude: 11.65, longitude: 12.14), - CLLocation(latitude: 11.66, longitude: 12.15) + Coordinate2D(value: CLLocationCoordinate2D(latitude: 11.65, longitude: 12.14)), + Coordinate2D(value: CLLocationCoordinate2D(latitude: 11.66, longitude: 12.15)) ], sarType: "isochrone", timeDeviation: 10, addonAPI: nil) @@ -39,9 +39,9 @@ extension CoreSearchOptions { urDistanceThreshold: NSNumber(value: 300), requestDebounce: 0, route: [ - CLLocation(latitude: 11.65, longitude: 12.14), - CLLocation(latitude: 11.66, longitude: 12.15), - CLLocation(latitude: 11.20, longitude: 12.02) + Coordinate2D(value: CLLocationCoordinate2D(latitude: 11.65, longitude: 12.14)), + Coordinate2D(value: CLLocationCoordinate2D(latitude: 11.66, longitude: 12.15)), + Coordinate2D(value: CLLocationCoordinate2D(latitude: 11.20, longitude: 12.02)) ], sarType: "isochrone", timeDeviation: 10, addonAPI: nil) diff --git a/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchResultStub+Samples.swift b/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchResultStub+Samples.swift index c740a8b5e..fb85b5ace 100644 --- a/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchResultStub+Samples.swift +++ b/Tests/MapboxSearchTests/Common/Data Samples/CoreSearchResultStub+Samples.swift @@ -16,7 +16,7 @@ extension CoreSearchResultStub { static let externalRecordSample = CoreSearchResultStub(id: "sample-3", type: .userRecord, - center: .sample1, + centerLocation: .sample1, layer: FavoritesProvider.providerIdentifier, userRecordID: "external-record-1", action: .sample1, @@ -25,7 +25,7 @@ extension CoreSearchResultStub { static func makeSuggestionsSet() -> [CoreSearchResultStub] { let results = makeMixedResultsSet() - results.forEach({ $0.center = nil }) + results.forEach({ $0.centerLocation = nil }) return results } @@ -35,7 +35,7 @@ extension CoreSearchResultStub { type: .place, names: ["Some Place Name"], languages: ["en"], - center: nil, + centerLocation: nil, categories: ["cafe"], icon: Maki.alcoholShop.name, metadata: metadata @@ -62,7 +62,7 @@ extension CoreSearchResultStub { } static func makeSuggestionTypeQuery() -> CoreSearchResultStub { - CoreSearchResultStub(id: "recursion", type: .query, center: nil) + CoreSearchResultStub(id: "recursion", type: .query, centerLocation: nil) } static func makeCategory() -> CoreSearchResultStub { @@ -83,7 +83,7 @@ extension CoreSearchResultStub { type: .place, names: ["Some Place Name"], languages: ["en"], - center: center, + centerLocation: center, categories: ["cafe"], icon: Maki.alcoholShop.name ) @@ -97,7 +97,7 @@ extension CoreSearchResultStub { type: .address, names: ["Some Place Name"], languages: ["en"], - center: .sample1, + centerLocation: .sample1, categories: ["address", "location"], icon: Maki.alcoholShop.name ) @@ -114,8 +114,12 @@ extension CoreSearchResultStub { postcode: nil, place: nil, district: "poi-land", - region: "poi-region", - country: "poi-country" + region: CoreSearchAddressRegion(name: "poi-region", + regionCode: nil, + regionCodeFull: nil), + country: CoreSearchAddressCountry(name: "poi-country", + countryCode: nil, + countryCodeAlpha3: nil) ) let result = CoreSearchResultStub( id: UUID().uuidString, @@ -123,7 +127,7 @@ extension CoreSearchResultStub { names: ["Some Place Name"], languages: ["en"], addresses: [address], - center: center, + centerLocation: center, categories: ["poi"], icon: Maki.viewpoint.name ) @@ -140,8 +144,12 @@ extension CoreSearchResultStub { postcode: nil, place: nil, district: "pizza-land", - region: "pizza-region", - country: "pizza-country" + region: CoreSearchAddressRegion(name: "pizza-region", + regionCode: nil, + regionCodeFull: nil), + country: CoreSearchAddressCountry(name: "pizza-country", + countryCode: nil, + countryCodeAlpha3: nil) ) let result = CoreSearchResultStub( id: UUID().uuidString, @@ -149,7 +157,7 @@ extension CoreSearchResultStub { names: ["Some Place Name"], languages: ["en"], addresses: [address], - center: center, + centerLocation: center, categories: ["pizza", "cafe"], icon: Maki.fastFood.name ) @@ -166,8 +174,12 @@ extension CoreSearchResultStub { postcode: nil, place: nil, district: "history-land", - region: "history-region", - country: "history-country" + region: CoreSearchAddressRegion(name: "history-region", + regionCode: nil, + regionCodeFull: nil), + country: CoreSearchAddressCountry(name: "history-country", + countryCode: nil, + countryCodeAlpha3: nil) ) let result = CoreSearchResultStub( id: UUID().uuidString, @@ -175,7 +187,7 @@ extension CoreSearchResultStub { names: ["Some Place Name"], languages: ["en"], addresses: [address], - center: center, + centerLocation: center, categories: ["history", "other"], icon: Maki.fastFood.name ) diff --git a/Tests/MapboxSearchTests/Common/Data Samples/SearchCategorySuggestion+Samples.swift b/Tests/MapboxSearchTests/Common/Data Samples/SearchCategorySuggestion+Samples.swift index 731758e6d..a265b7053 100644 --- a/Tests/MapboxSearchTests/Common/Data Samples/SearchCategorySuggestion+Samples.swift +++ b/Tests/MapboxSearchTests/Common/Data Samples/SearchCategorySuggestion+Samples.swift @@ -4,7 +4,7 @@ import XCTest extension SearchCategorySuggestionImpl { static let sample1 = SearchCategorySuggestionImpl(coreResult: CoreSearchResultStub(id: "sample-2", type: .category, - center: nil), + centerLocation: nil), response: CoreSearchResponseStub(id: 42, options: .sample1, result: .success([]))) diff --git a/Tests/MapboxSearchTests/Common/Data Samples/SearchQuerySuggestionImpl+Samples.swift b/Tests/MapboxSearchTests/Common/Data Samples/SearchQuerySuggestionImpl+Samples.swift index a45f1a190..287018686 100644 --- a/Tests/MapboxSearchTests/Common/Data Samples/SearchQuerySuggestionImpl+Samples.swift +++ b/Tests/MapboxSearchTests/Common/Data Samples/SearchQuerySuggestionImpl+Samples.swift @@ -4,7 +4,7 @@ import XCTest extension SearchQuerySuggestionImpl { static let sample1 = SearchQuerySuggestionImpl(coreResult: CoreSearchResultStub(id: "sample-43", type: .query, - center: nil), + centerLocation: nil), response: CoreSearchResponseStub(id: 42, options: .sample1, result: .success([]))) diff --git a/Tests/MapboxSearchTests/Common/Models/Address/Address+Tests.swift b/Tests/MapboxSearchTests/Common/Models/Address/Address+Tests.swift index 4238f92ff..c469680f2 100644 --- a/Tests/MapboxSearchTests/Common/Models/Address/Address+Tests.swift +++ b/Tests/MapboxSearchTests/Common/Models/Address/Address+Tests.swift @@ -77,8 +77,8 @@ class AddressFormatterTests: XCTestCase { XCTAssertEqual(coreAddress.postcode, address.postcode) XCTAssertEqual(coreAddress.place, address.place) XCTAssertEqual(coreAddress.district, address.district) - XCTAssertEqual(coreAddress.region, address.region) - XCTAssertEqual(coreAddress.country, address.country) + XCTAssertEqual(coreAddress.region, address.searchAddressRegion?.toCore()) + XCTAssertEqual(coreAddress.country, address.searchAddressCountry?.toCore()) } func testEmptyCoreAddressConversion() { diff --git a/Tests/MapboxSearchTests/Common/Models/Address/CoreAddress+Extensions.swift b/Tests/MapboxSearchTests/Common/Models/Address/CoreAddress+Extensions.swift index 9a8adcadb..c3802d860 100644 --- a/Tests/MapboxSearchTests/Common/Models/Address/CoreAddress+Extensions.swift +++ b/Tests/MapboxSearchTests/Common/Models/Address/CoreAddress+Extensions.swift @@ -1,19 +1,2 @@ @testable import MapboxSearch -extension CoreAddress { - open override func isEqual(_ object: Any?) -> Bool { - if let rhs = object as? CoreAddress { - return houseNumber == rhs.houseNumber && - street == rhs.street && - neighborhood == rhs.neighborhood && - locality == rhs.locality && - postcode == rhs.postcode && - place == rhs.place && - district == rhs.district && - region == rhs.region && - country == rhs.country - } else { - return false - } - } -} diff --git a/Tests/MapboxSearchTests/Common/Models/Search Result/SearchResultSuggestionImplTests.swift b/Tests/MapboxSearchTests/Common/Models/Search Result/SearchResultSuggestionImplTests.swift index b2b8aeb6a..f32a960f4 100644 --- a/Tests/MapboxSearchTests/Common/Models/Search Result/SearchResultSuggestionImplTests.swift +++ b/Tests/MapboxSearchTests/Common/Models/Search Result/SearchResultSuggestionImplTests.swift @@ -7,7 +7,7 @@ class SearchResultSuggestionImplTests: XCTestCase { func testSuccessfulInitForAddressType() throws { let suggestionImpl = try XCTUnwrap(SearchResultSuggestionImpl(coreResult: CoreSearchResultStub(id: "sample-2", type: .address, - center: nil), + centerLocation: nil), response: CoreSearchResponseStub(id: 42, options: .sample1, result: .success([])))) @@ -17,7 +17,7 @@ class SearchResultSuggestionImplTests: XCTestCase { func testSuccessfulInitForPOIType() throws { let suggestionImpl = try XCTUnwrap(SearchResultSuggestionImpl(coreResult: CoreSearchResultStub(id: "sample-2", type: .poi, - center: nil), + centerLocation: nil), response: CoreSearchResponseStub(id: 42, options: .sample1, result: .success([])))) @@ -27,7 +27,7 @@ class SearchResultSuggestionImplTests: XCTestCase { func testFailedInit() throws { XCTAssertNil(SearchResultSuggestionImpl(coreResult: CoreSearchResultStub(id: "sample-2", type: .category, - center: nil), + centerLocation: nil), response: CoreSearchResponseStub(id: 42, options: .sample1, result: .success([])))) @@ -41,7 +41,7 @@ class SearchResultSuggestionImplTests: XCTestCase { let exception = catchBadInstruction { _ = SearchResultSuggestionImpl(coreResult: CoreSearchResultStub(id: "sample-2", type: .category, - center: .sample1), + centerLocation: .sample1), response: CoreSearchResponseStub(id: 42, options: .sample1, result: .success([]))) diff --git a/Tests/MapboxSearchTests/Common/Models/Search Result/ServerSearchResultTests.swift b/Tests/MapboxSearchTests/Common/Models/Search Result/ServerSearchResultTests.swift index 23f9ecf37..45d66c1ed 100644 --- a/Tests/MapboxSearchTests/Common/Models/Search Result/ServerSearchResultTests.swift +++ b/Tests/MapboxSearchTests/Common/Models/Search Result/ServerSearchResultTests.swift @@ -24,7 +24,7 @@ class ServerSearchResultTests: XCTestCase { } func testServerSearchResultNilForMissingCoordinates() { - let result = ServerSearchResult(coreResult: CoreSearchResultStub(id: UUID().uuidString, type: .userRecord, center: nil), + let result = ServerSearchResult(coreResult: CoreSearchResultStub(id: UUID().uuidString, type: .userRecord, centerLocation: nil), response: CoreSearchResponseStub.failureSample) XCTAssertNil(result) @@ -37,7 +37,7 @@ class ServerSearchResultTests: XCTestCase { XCTAssertEqual(result.suggestionType, .POI) XCTAssertEqual(result.descriptionText, coreResult.addressDescription) - XCTAssertEqual(result.coordinate, coreResult.center?.coordinate) + XCTAssertEqual(result.coordinate, coreResult.centerLocation?.coordinate) result.coordinate = .init(latitude: -38.23, longitude: 89.356) XCTAssertEqual(result.coordinateCodable.latitude, -38.23) diff --git a/Tests/MapboxSearchTests/Common/Stubs&Models/CoreSearchEngineStub.swift b/Tests/MapboxSearchTests/Common/Stubs&Models/CoreSearchEngineStub.swift index ce2e6bc76..da6232232 100644 --- a/Tests/MapboxSearchTests/Common/Stubs&Models/CoreSearchEngineStub.swift +++ b/Tests/MapboxSearchTests/Common/Stubs&Models/CoreSearchEngineStub.swift @@ -4,7 +4,6 @@ import Foundation import CoreLocation class CoreSearchEngineStub { - var accessToken: String let locationProvider: CoreLocationProvider? var searchResponse: CoreSearchResponseProtocol? @@ -27,8 +26,7 @@ class CoreSearchEngineStub { var callbackWrapper: (@escaping () -> Void) -> Void = { $0() } - init(accessToken: String, location: CoreLocationProvider?) { - self.accessToken = accessToken + init(location: CoreLocationProvider?) { self.locationProvider = location } } @@ -48,8 +46,8 @@ extension CoreSearchEngineStub: CoreSearchEngineProtocol { "lat": 53.92068293258732, "lng": 27.587735185708915, "proximity": - [\(request.options.proximity?.coordinate.longitude ?? -1), - \(request.options.proximity?.coordinate.latitude ?? -1)], + [\(request.options.proximity?.value.longitude ?? -1), + \(request.options.proximity?.value.latitude ?? -1)], "queryString": "\(request.query)", "resultId": "\(result?.id ?? "nope")", "resultIndex": \(result?.serverIndex ?? -1), @@ -70,10 +68,6 @@ extension CoreSearchEngineStub: CoreSearchEngineProtocol { assertionFailure("Not Implemented") completion?() } - - func setAccessTokenForToken(_ token: String) { - accessToken = token - } func createUserLayer(_ layer: String, priority: Int32) -> CoreUserRecordsLayerProtocol { CoreUserRecordsLayerStub(name: layer) diff --git a/Tests/MapboxSearchTests/Common/Stubs&Models/CoreSearchResultStub.swift b/Tests/MapboxSearchTests/Common/Stubs&Models/CoreSearchResultStub.swift index c513ae740..c6066afbd 100644 --- a/Tests/MapboxSearchTests/Common/Stubs&Models/CoreSearchResultStub.swift +++ b/Tests/MapboxSearchTests/Common/Stubs&Models/CoreSearchResultStub.swift @@ -11,7 +11,7 @@ class CoreSearchResultStub: CoreSearchResultProtocol { addresses: [CoreAddress]? = [Address.mapboxDCOffice.coreAddress()], addressDescription: String? = nil, matchingName: String? = nil, - center: CLLocation? = .sample1, + centerLocation: CLLocation? = .sample1, categories: [String]? = nil, routablePoints: [CoreRoutablePoint]? = nil, icon: String? = nil, @@ -30,7 +30,7 @@ class CoreSearchResultStub: CoreSearchResultProtocol { self.languages = languages self.addresses = addresses self.addressDescription = addressDescription - self.center = center + self.centerLocation = centerLocation self.categories = categories self.routablePoints = routablePoints self.icon = icon @@ -61,7 +61,7 @@ class CoreSearchResultStub: CoreSearchResultProtocol { var addresses: [CoreAddress]? var addressDescription: String? var matchingName: String? - var center: CLLocation? + var centerLocation: CLLocation? var categories: [String]? var routablePoints: [CoreRoutablePoint]? var icon: String? @@ -102,7 +102,7 @@ extension CoreSearchResultStub: Equatable { && lhs.names == rhs.names && lhs.languages == rhs.languages && lhs.addresses == rhs.addresses - && lhs.center == rhs.center + && lhs.centerLocation == rhs.centerLocation && lhs.categories == rhs.categories && lhs.icon == rhs.icon && lhs.layer == rhs.layer @@ -125,10 +125,13 @@ extension CoreSearchResultProtocol { fullAddress: nil, distance: distance, eta: nil, - center: center, + center: centerLocation.map { Coordinate2D(value: $0.coordinate) }, accuracy: 100, routablePoints: routablePoints, categories: categories, + categoryIDs: [], + brand: [], + brandID: nil, icon: icon, metadata: nil, externalIDs: nil, diff --git a/Tests/MapboxSearchTests/Common/Stubs&Models/ServiceProviderStub.swift b/Tests/MapboxSearchTests/Common/Stubs&Models/ServiceProviderStub.swift index a8e91fc22..525fbdede 100644 --- a/Tests/MapboxSearchTests/Common/Stubs&Models/ServiceProviderStub.swift +++ b/Tests/MapboxSearchTests/Common/Stubs&Models/ServiceProviderStub.swift @@ -4,7 +4,7 @@ class ServiceProviderStub: ServiceProviderProtocol, EngineProviderProtocol { func getStoredAccessToken() -> String? { "mapbox-access-token" } - + lazy var dataLayerProviders: [IndexableDataProvider] = [localFavoritesProvider, localHistoryProvider] let localFavoritesProvider = LocalDataProvider() @@ -14,9 +14,9 @@ class ServiceProviderStub: ServiceProviderProtocol, EngineProviderProtocol { var latestCoreEngine: CoreSearchEngineStub! - func createEngine(apiType: CoreSearchEngine.ApiType, accessToken: String, locationProvider: CoreLocationProvider?) -> CoreSearchEngineProtocol { + func createEngine(apiType: CoreSearchEngine.ApiType, locationProvider: CoreLocationProvider?) -> CoreSearchEngineProtocol { let locationProvider: CoreLocationProvider? = WrapperLocationProvider(wrapping: DefaultLocationProvider()) - latestCoreEngine = CoreSearchEngineStub(accessToken: "mapbox-access-token", location: locationProvider) + latestCoreEngine = CoreSearchEngineStub(location: locationProvider) return latestCoreEngine } } diff --git a/Tests/MapboxSearchTests/Common/Stubs&Models/TestTileStore.swift b/Tests/MapboxSearchTests/Common/Stubs&Models/TestTileStore.swift index 650e87d62..e42efe715 100644 --- a/Tests/MapboxSearchTests/Common/Stubs&Models/TestTileStore.swift +++ b/Tests/MapboxSearchTests/Common/Stubs&Models/TestTileStore.swift @@ -2,11 +2,8 @@ import Foundation @testable import MapboxSearch enum TestTileStore { - static func build() -> SearchTileStore? { + static func build() -> SearchTileStore { let path = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString).path - if let token = ServiceProvider.shared.getStoredAccessToken() { - return SearchTileStore(accessToken: token, path: path) - } - return nil + return SearchTileStore(path: path) } } diff --git a/Tests/MapboxSearchTests/Legacy/CategorySearchEngineTests.swift b/Tests/MapboxSearchTests/Legacy/CategorySearchEngineTests.swift index 90b50d025..5279b7510 100644 --- a/Tests/MapboxSearchTests/Legacy/CategorySearchEngineTests.swift +++ b/Tests/MapboxSearchTests/Legacy/CategorySearchEngineTests.swift @@ -15,7 +15,7 @@ class CategorySearchEngineTests: XCTestCase { } func testEmptySearch() throws { - let categorySearchEngine = CategorySearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let categorySearchEngine = CategorySearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) let engine = try XCTUnwrap(categorySearchEngine.engine as? CoreSearchEngineStub) let expectedResults = [CoreSearchResultStub]() let response = CoreSearchResponseStub.successSample(results: expectedResults) @@ -37,7 +37,7 @@ class CategorySearchEngineTests: XCTestCase { } func testCategorySearch() throws { - let categorySearchEngine = CategorySearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let categorySearchEngine = CategorySearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) let engine = try XCTUnwrap(categorySearchEngine.engine as? CoreSearchEngineStub) let expectedResults = CoreSearchResultStub.makeCategoryResultsSet() let response = CoreSearchResponseStub.successSample(results: expectedResults) @@ -58,7 +58,7 @@ class CategorySearchEngineTests: XCTestCase { } func testErrorSearch() throws { - let categorySearchEngine = CategorySearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let categorySearchEngine = CategorySearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) let engine = try XCTUnwrap(categorySearchEngine.engine as? CoreSearchEngineStub) let response = CoreSearchResponseStub.failureSample engine.searchResponse = response @@ -86,7 +86,7 @@ class CategorySearchEngineTests: XCTestCase { #if !arch(x86_64) throw XCTSkip("Unsupported architecture") #else - let categorySearchEngine = CategorySearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let categorySearchEngine = CategorySearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) let engine = try XCTUnwrap(categorySearchEngine.engine as? CoreSearchEngineStub) engine.callbackWrapper = { callback in diff --git a/Tests/MapboxSearchTests/Legacy/IndexableDataProviderTests.swift b/Tests/MapboxSearchTests/Legacy/IndexableDataProviderTests.swift index 89a3d7c68..dc3a3f2d3 100644 --- a/Tests/MapboxSearchTests/Legacy/IndexableDataProviderTests.swift +++ b/Tests/MapboxSearchTests/Legacy/IndexableDataProviderTests.swift @@ -8,7 +8,7 @@ class IndexableDataProviderTests: XCTestCase { func testOneDataProvider() throws { let dataProvider = TestDataProvider() - let searchEngine = SearchEngine(accessToken: "Stub_token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate dataProvider.records = TestDataProviderRecord.testData(count: 2) let interactor = try searchEngine.register(dataProvider: dataProvider, priority: 10) @@ -31,7 +31,7 @@ class IndexableDataProviderTests: XCTestCase { func testDataProviderWithNoRecords() throws { let dataProvider = TestDataProvider() - let searchEngine = SearchEngine(accessToken: "Stub_token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let interactor = try searchEngine.register(dataProvider: dataProvider, priority: 10) dataProvider.registerProviderInteractor(interactor: interactor) @@ -58,7 +58,7 @@ class IndexableDataProviderTests: XCTestCase { let dataProviderManyRecords = TestDataProvider() dataProviderManyRecords.records = TestDataProviderRecord.testData(count: 10000) - let searchEngine = SearchEngine(accessToken: "Stub_token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate for (index, dataProvider) in [dataProviderNoRecords, dataProviderSomeRecords, dataProviderManyRecords].enumerated() { diff --git a/Tests/MapboxSearchTests/Legacy/LocationProviderTests.swift b/Tests/MapboxSearchTests/Legacy/LocationProviderTests.swift index 26bd5f1a7..139bd05c8 100644 --- a/Tests/MapboxSearchTests/Legacy/LocationProviderTests.swift +++ b/Tests/MapboxSearchTests/Legacy/LocationProviderTests.swift @@ -5,20 +5,20 @@ import CoreLocation class LocationProviderTests: XCTestCase { func testPointLocationProvider() { let coordinate = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060) - let pointProvider: LocationProvider = PointLocationProvider(coordinate: coordinate) + let pointProvider = PointLocationProvider(coordinate: coordinate) XCTAssertEqual(pointProvider.currentLocation(), coordinate) } func testCoordinateWrapperLocationProvider() throws { let coordinate = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060) - let pointProvider: LocationProvider = PointLocationProvider(coordinate: coordinate) + let pointProvider = PointLocationProvider(coordinate: coordinate) let locationProviderWrapper = try XCTUnwrap(WrapperLocationProvider(wrapping: pointProvider)) let wrapperCoordinate = try XCTUnwrap(locationProviderWrapper.getLocation()) - XCTAssertEqual(wrapperCoordinate.coordinate.latitude, 40.7128) - XCTAssertEqual(wrapperCoordinate.coordinate.longitude, -74.0060) + XCTAssertEqual(wrapperCoordinate.value.latitude, 40.7128) + XCTAssertEqual(wrapperCoordinate.value.longitude, -74.0060) } func testNilWrapperLocationProvider() { diff --git a/Tests/MapboxSearchTests/Legacy/SearchCategorySuggestionImplTests.swift b/Tests/MapboxSearchTests/Legacy/SearchCategorySuggestionImplTests.swift index 733132407..960791295 100644 --- a/Tests/MapboxSearchTests/Legacy/SearchCategorySuggestionImplTests.swift +++ b/Tests/MapboxSearchTests/Legacy/SearchCategorySuggestionImplTests.swift @@ -6,7 +6,7 @@ class SearchCategorySuggestionImplTests: XCTestCase { func testSuccessfulInit() throws { let suggestionImpl = try XCTUnwrap(SearchCategorySuggestionImpl(coreResult: CoreSearchResultStub(id: "sample-2", type: .category, - center: nil), + centerLocation: nil), response: CoreSearchResponseStub(id: 42, options: .sample1, result: .success([])))) @@ -14,7 +14,7 @@ class SearchCategorySuggestionImplTests: XCTestCase { } func testFailedInitForPOI() throws { - XCTAssertNil(SearchCategorySuggestionImpl(coreResult: CoreSearchResultStub(id: "sample-1", type: .poi, center: nil), + XCTAssertNil(SearchCategorySuggestionImpl(coreResult: CoreSearchResultStub(id: "sample-1", type: .poi, centerLocation: nil), response: CoreSearchResponseStub(id: 42, options: .sample1, result: .success([])))) diff --git a/Tests/MapboxSearchTests/Legacy/SearchEngineTests.swift b/Tests/MapboxSearchTests/Legacy/SearchEngineTests.swift index 0e62074fd..cb896f12f 100644 --- a/Tests/MapboxSearchTests/Legacy/SearchEngineTests.swift +++ b/Tests/MapboxSearchTests/Legacy/SearchEngineTests.swift @@ -15,7 +15,7 @@ class SearchEngineTests: XCTestCase { } func testEmptySearch() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) let results = [CoreSearchResultStub]() @@ -34,7 +34,7 @@ class SearchEngineTests: XCTestCase { } func testMixedSearch() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) let results = CoreSearchResultStub.makeMixedResultsSet() @@ -52,7 +52,7 @@ class SearchEngineTests: XCTestCase { } func testReverseGeocodingSearch() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) let results = CoreSearchResultStub.makeMixedResultsSet() @@ -71,7 +71,7 @@ class SearchEngineTests: XCTestCase { } func testErrorSearch() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) let coreResponse = CoreSearchResponseStub.failureSample @@ -84,7 +84,7 @@ class SearchEngineTests: XCTestCase { } func testIgnoreResultsForOutdatedSearchQuery() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) let results = CoreSearchResultStub.makeMixedResultsSet() @@ -114,7 +114,7 @@ class SearchEngineTests: XCTestCase { } func testIgnoreErrorForOutdatedSearchQuery() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) let results = CoreSearchResultStub.makeMixedResultsSet() @@ -140,7 +140,7 @@ class SearchEngineTests: XCTestCase { } func testResolvedSearchResult() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) @@ -174,7 +174,7 @@ class SearchEngineTests: XCTestCase { let serviceProvider = provider serviceProvider.dataLayerProviders.append(dataLayerProvider) - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: serviceProvider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: serviceProvider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) @@ -200,7 +200,7 @@ class SearchEngineTests: XCTestCase { } func testBatchResolve() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) @@ -220,7 +220,7 @@ class SearchEngineTests: XCTestCase { } func testEmptyBatchResolve() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) @@ -237,7 +237,7 @@ class SearchEngineTests: XCTestCase { } func testSuggestionTypeQuery() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) @@ -248,7 +248,7 @@ class SearchEngineTests: XCTestCase { let updateExpectation = delegate.updateExpectation let coreSuggestion = CoreSearchResultStub.makeSuggestionTypeQuery() - coreSuggestion.center = nil + coreSuggestion.centerLocation = nil let suggestion = try XCTUnwrap(SearchResultSuggestionImpl(coreResult: coreSuggestion, response: coreResponse)) searchEngine.query = "sample-1" searchEngine.select(suggestion: suggestion) @@ -260,7 +260,7 @@ class SearchEngineTests: XCTestCase { } func testBatchResolveFailedResponse() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) @@ -294,7 +294,7 @@ class SearchEngineTests: XCTestCase { throw XCTSkip("Unsupported architecture") #else - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) searchEngine.delegate = delegate let expectation = delegate.errorExpectation @@ -325,7 +325,7 @@ class SearchEngineTests: XCTestCase { throw XCTSkip("Unsupported architecture") #else - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) engine.callbackWrapper = { callback in @@ -353,7 +353,7 @@ class SearchEngineTests: XCTestCase { } func testReverseGeocodingFailedResponse() throws { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) let engine = try XCTUnwrap(searchEngine.engine as? CoreSearchEngineStub) let expectedError = NSError(domain: mapboxCoreSearchErrorDomain, code: 500, @@ -405,7 +405,7 @@ class SearchEngineTests: XCTestCase { } func testQueryGetterSetter() { - let searchEngine = SearchEngine(accessToken: "mapbox-access-token", serviceProvider: provider, locationProvider: DefaultLocationProvider()) + let searchEngine = SearchEngine(serviceProvider: provider, locationProvider: DefaultLocationProvider()) XCTAssertEqual(searchEngine.query, "") diff --git a/Tests/MapboxSearchTests/Legacy/WrapperLocationProviderTests.swift b/Tests/MapboxSearchTests/Legacy/WrapperLocationProviderTests.swift index ab890c797..19f496f55 100644 --- a/Tests/MapboxSearchTests/Legacy/WrapperLocationProviderTests.swift +++ b/Tests/MapboxSearchTests/Legacy/WrapperLocationProviderTests.swift @@ -6,7 +6,7 @@ class WrapperLocationProviderTests: XCTestCase { func testLocationBypass() throws { let wrapperLocationProvider = try XCTUnwrap(WrapperLocationProvider(wrapping: PointLocationProvider(coordinate: .sample1))) - XCTAssertEqual(wrapperLocationProvider.getLocation()?.coordinate, CLLocation.sample1.coordinate) + XCTAssertEqual(wrapperLocationProvider.getLocation()?.value, CLLocation.sample1.coordinate) } func testViewport() throws { diff --git a/Tests/MapboxSearchTests/Use Cases/Address Autofill/AddressAutofill+Tests.swift b/Tests/MapboxSearchTests/Use Cases/Address Autofill/AddressAutofill+Tests.swift index 825462715..c1af53b83 100644 --- a/Tests/MapboxSearchTests/Use Cases/Address Autofill/AddressAutofill+Tests.swift +++ b/Tests/MapboxSearchTests/Use Cases/Address Autofill/AddressAutofill+Tests.swift @@ -10,7 +10,7 @@ final class AddressAutofillTests: XCTestCase { override func setUp() { super.setUp() - searchEngine = CoreSearchEngineStub(accessToken: "test", location: nil) + searchEngine = CoreSearchEngineStub(location: nil) searchEngine.searchResponse = CoreSearchResponseStub.successSample(results: []) addressAutofill = AddressAutofill( diff --git a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Suggestion+Tests.swift b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Suggestion+Tests.swift index 9609ab21e..ef9cb6516 100644 --- a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Suggestion+Tests.swift +++ b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocomplete.Suggestion+Tests.swift @@ -27,7 +27,7 @@ final class PlaceAutocompleteSuggestionTests: XCTestCase { func testCreationFromCoreSuggestion() { let coreSuggestion = CoreSearchResultStub.makeSuggestion() coreSuggestion.resultTypes = [.poi] - coreSuggestion.center = CLLocation(latitude: 10.0, longitude: 20.0) + coreSuggestion.centerLocation = CLLocation(latitude: 10.0, longitude: 20.0) let suggestion = try? PlaceAutocomplete.Suggestion.from( searchSuggestion: coreSuggestion, diff --git a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift index 885958886..5e52b340e 100644 --- a/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift +++ b/Tests/MapboxSearchTests/Use Cases/Place Autocomplete/PlaceAutocompleteTests.swift @@ -14,7 +14,7 @@ final class PlaceAutocompleteTests: XCTestCase { override func setUp() { super.setUp() - searchEngine = CoreSearchEngineStub(accessToken: "test", location: nil) + searchEngine = CoreSearchEngineStub(location: nil) searchEngine.searchResponse = CoreSearchResponseStub.successSample(results: []) userActivityReporter = CoreUserActivityReporterStub() coordinate = CLLocationCoordinate2D(latitude: 40.730610, longitude: -73.935242) @@ -38,9 +38,9 @@ final class PlaceAutocompleteTests: XCTestCase { XCTAssertEqual(userActivityReporter.passedActivity, "place-autocomplete-forward-geocoding") XCTAssertEqual(searchEngine.query, "query") XCTAssertEqual(searchEngine.categories, []) - XCTAssertEqual(searchEngine.searchOptions?.isIgnoreUR, true) - XCTAssertEqual(searchEngine.searchOptions?.proximity?.coordinate, coordinate) - XCTAssertEqual(searchEngine.searchOptions?.origin?.coordinate, coordinate) + XCTAssertEqual(searchEngine.searchOptions?.ignoreUR, true) + XCTAssertEqual(searchEngine.searchOptions?.proximity?.value, coordinate) + XCTAssertEqual(searchEngine.searchOptions?.origin?.value, coordinate) XCTAssertNil(searchEngine.searchOptions?.navProfile) XCTAssertNil(searchEngine.searchOptions?.etaType) } @@ -75,9 +75,9 @@ final class PlaceAutocompleteTests: XCTestCase { XCTAssertEqual(userActivityReporter.passedActivity, "place-autocomplete-forward-geocoding") XCTAssertEqual(searchEngine.query, "query") XCTAssertEqual(searchEngine.categories, []) - XCTAssertEqual(searchEngine.searchOptions?.isIgnoreUR, true) - XCTAssertEqual(searchEngine.searchOptions?.proximity?.coordinate, coordinate) - XCTAssertEqual(searchEngine.searchOptions?.origin?.coordinate, coordinate) + XCTAssertEqual(searchEngine.searchOptions?.ignoreUR, true) + XCTAssertEqual(searchEngine.searchOptions?.proximity?.value, coordinate) + XCTAssertEqual(searchEngine.searchOptions?.origin?.value, coordinate) XCTAssertEqual(searchEngine.searchOptions?.navProfile, "cycling") XCTAssertEqual(searchEngine.searchOptions?.etaType, "navigation") XCTAssertEqual(searchEngine.searchOptions?.countries, ["us", "gb"]) @@ -113,7 +113,7 @@ final class PlaceAutocompleteTests: XCTestCase { XCTAssertFalse(searchEngine.nextSearchCalled) XCTAssertEqual(searchEngine.query, "query") XCTAssertEqual(searchEngine.categories, []) - XCTAssertEqual(searchEngine.searchOptions?.isIgnoreUR, true) + XCTAssertEqual(searchEngine.searchOptions?.ignoreUR, true) } func testDoNotCallRetrieveForSuggestionWithCoordinate() { @@ -141,7 +141,7 @@ final class PlaceAutocompleteTests: XCTestCase { func testSelectSuggestionIfNeedToRetrieve() { let coreSuggestion = CoreSearchResultStub.makeSuggestion() coreSuggestion.resultTypes = [.poi] - coreSuggestion.center = CLLocation(latitude: 10.0, longitude: 20.0) + coreSuggestion.centerLocation = CLLocation(latitude: 10.0, longitude: 20.0) let suggestion = PlaceAutocomplete.Suggestion.makeMock( underlying: .suggestion(coreSuggestion, options) diff --git a/scripts/build.sh b/scripts/build.sh index 6b82b56ed..0780880cb 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -57,7 +57,6 @@ do xcodebuild -create-xcframework -output "${RESULT_PRODUCTS_DIR}/${frameworkName}.xcframework" \ -framework "${DEVICE_ARCHIVE_NAME}/Products/Library/Frameworks/${frameworkName}.framework" \ -debug-symbols "${DEVICE_ARCHIVE_NAME}/dSYMs/${frameworkName}.framework.dSYM" \ - -debug-symbols "${DEVICE_ARCHIVE_NAME}/BCSymbolMaps/${DSYM_UUID}.bcsymbolmap" \ -framework "${SIMULATOR_ARCHIVE_NAME}/Products/Library/Frameworks/${frameworkName}.framework" \ -debug-symbols "${SIMULATOR_ARCHIVE_NAME}/dSYMs/${frameworkName}.framework.dSYM" From 69e28277836f713d204c365fc92f9d0aa1827667 Mon Sep 17 00:00:00 2001 From: Jack Alto <384288+aokj4ck@users.noreply.github.com> Date: Thu, 11 Jan 2024 15:22:13 -0500 Subject: [PATCH 29/31] [SSDK-528] Prepare 2.0.0-alpha.1 release, update version number (#145) ### Description **Fixes [SSDK-528](https://mapbox.atlassian.net/browse/SSDK-528)** - Fine tune Swift and Xcode version numbers in docs ### Checklist - [x] Update `CHANGELOG` [SSDK-528]: https://mapbox.atlassian.net/browse/SSDK-528 --- CHANGELOG.md | 11 +++++++++-- MapboxSearch.podspec | 4 ++-- MapboxSearchUI.podspec | 6 +++--- README.md | 6 +++--- Search Documentation.docc/Installation.md | 4 ++-- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef0fc9a39..6099d6e8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,18 @@ Guide: https://keepachangelog.com/en/1.0.0/ ## Unreleased + + +## 2.0.0-alpha.1 + +### Breaking changes + - [Address Autofill] Suggestions no longer perform a `retrieve` call. -- [Address Autofill] `Suggestion.coordinate` is now an optional. `init` requires an Underlying enum parameter. +- [Address Autofill] `AddressAutofill.Suggestion` field `coordinate: CLLocationCoordinate2D?` is now an optional. +- [Address Autofill] `AddressAutofill.Suggestion.init` now requires an `AddressAutofill.Suggestion.Underlying` enum parameter. - [Address Autofill] Added new AddressAutofill.Suggestion.Underlying enum parameter with cases for suggestion and result inputs. - [Place Autocomplete] Suggestions no longer perform a `retrieve` call. -- [Place Autocomplete] `Suggestion.coordinate` is now an optional. +- [Place Autocomplete] `PlaceAutocomplete.Suggestion` field `coordinate: CLLocationCoordinate2D?` is now an optional. - [Place Autocomplete] `Result.coordinate` is now an optional. - [Core] Updated to Xcode 14.1 minimum version - [Core] Updated deployment target to iOS 12 diff --git a/MapboxSearch.podspec b/MapboxSearch.podspec index b0d71c5e9..e03213122 100644 --- a/MapboxSearch.podspec +++ b/MapboxSearch.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MapboxSearch' - s.version = '1.0.0-rc.8' + s.version = '2.0.0-alpha.1' s.summary = 'Search SDK for Mapbox Search API ' # This description is used to generate tags and improve search results. @@ -20,7 +20,7 @@ Some iOS platform specifics applies. s.source = { :http => "https://api.mapbox.com/downloads/v2/search-sdk/releases/ios/packages/#{s.version.to_s}/#{s.name}.zip" } s.ios.deployment_target = '12.0' - s.swift_versions = [5.2] + s.swift_versions = [5.7.1] s.vendored_frameworks = "**/#{s.name}.xcframework" diff --git a/MapboxSearchUI.podspec b/MapboxSearchUI.podspec index e81eb9b47..f767d3b0c 100644 --- a/MapboxSearchUI.podspec +++ b/MapboxSearchUI.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MapboxSearchUI' - s.version = '1.0.0-rc.8' + s.version = '2.0.0-alpha.1' s.summary = 'Search UI for Mapbox Search API' # This description is used to generate tags and improve search results. @@ -19,9 +19,9 @@ Card style custom UI with full search functionality powered by Mapbox Search API s.source = { :http => "https://api.mapbox.com/downloads/v2/search-sdk/releases/ios/packages/#{s.version.to_s}/#{s.name}.zip" } s.ios.deployment_target = '12.0' - s.swift_versions = [5.2] + s.swift_versions = [5.7.1] s.vendored_frameworks = "**/#{s.name}.xcframework" - s.dependency 'MapboxSearch', "1.0.0-rc.8" + s.dependency 'MapboxSearch', "2.0.0-alpha.1" end diff --git a/README.md b/README.md index 6d35ae2ef..5d469009f 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ The Search SDK is pre-configured for autocomplete, local search biasing, and inc ## Requirements - iOS 12.0 and newer -- Xcode 14 and newer +- Xcode 14.1 and newer - Swift 5.7.1 and newer - Objective-C is not supported - macOS/tvOS/watchOS platforms currently are not supported @@ -104,13 +104,13 @@ MapboxSearchDemoApplication provides a Demo app wih MapboxSearchUI.framework pre ##### MapboxSearch To integrate latest preview version of `MapboxSearch` into your Xcode project using CocoaPods, specify it in your `Podfile`: ``` -pod 'MapboxSearch', ">= 1.0.0-rc.8", "< 2.0" +pod 'MapboxSearch', ">= 2.0.0-alpha.1", "< 3.0" ``` ##### MapboxSearchUI To integrate latest preview version of `MapboxSearchUI` into your Xcode project using CocoaPods, specify it in your `Podfile`: ``` -pod 'MapboxSearchUI', ">= 1.0.0-rc.8", "< 2.0" +pod 'MapboxSearchUI', ">= 2.0.0-alpha.1", "< 3.0" ``` ### Swift Package Manager diff --git a/Search Documentation.docc/Installation.md b/Search Documentation.docc/Installation.md index 3dd3892aa..f2161f045 100644 --- a/Search Documentation.docc/Installation.md +++ b/Search Documentation.docc/Installation.md @@ -59,7 +59,7 @@ To add the Mapbox Search SDK dependency with CocoaPods, you will need to configu ```ruby use_frameworks! target "TargetNameForYourApp" do - pod 'MapboxSearchUI', ">= 1.0.0-rc.8", "< 2.0" + pod 'MapboxSearchUI', ">= 2.0.0-alpha.1", "< 3.0" end ``` @@ -68,7 +68,7 @@ To add the Mapbox Search SDK dependency with CocoaPods, you will need to configu ```ruby use_frameworks! target "TargetNameForYourApp" do - pod 'MapboxSearch', ">= 1.0.0-rc.8", "< 2.0" + pod 'MapboxSearch', ">= 2.0.0-alpha.1", "< 3.0" end ``` From d1ebd47c455d17977131b2283946a960c3abdb28 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Thu, 11 Jan 2024 15:35:02 -0500 Subject: [PATCH 30/31] Correct Swift version (remove patch version) for cocoapods - SSDK-528 --- .swift-version | 2 +- MapboxSearch.podspec | 2 +- MapboxSearchUI.podspec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.swift-version b/.swift-version index 262122f67..760606e1f 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -5.7.1 \ No newline at end of file +5.7 diff --git a/MapboxSearch.podspec b/MapboxSearch.podspec index e03213122..72b0875b4 100644 --- a/MapboxSearch.podspec +++ b/MapboxSearch.podspec @@ -20,7 +20,7 @@ Some iOS platform specifics applies. s.source = { :http => "https://api.mapbox.com/downloads/v2/search-sdk/releases/ios/packages/#{s.version.to_s}/#{s.name}.zip" } s.ios.deployment_target = '12.0' - s.swift_versions = [5.7.1] + s.swift_versions = [5.7] s.vendored_frameworks = "**/#{s.name}.xcframework" diff --git a/MapboxSearchUI.podspec b/MapboxSearchUI.podspec index f767d3b0c..60c8bb2d6 100644 --- a/MapboxSearchUI.podspec +++ b/MapboxSearchUI.podspec @@ -19,7 +19,7 @@ Card style custom UI with full search functionality powered by Mapbox Search API s.source = { :http => "https://api.mapbox.com/downloads/v2/search-sdk/releases/ios/packages/#{s.version.to_s}/#{s.name}.zip" } s.ios.deployment_target = '12.0' - s.swift_versions = [5.7.1] + s.swift_versions = [5.7] s.vendored_frameworks = "**/#{s.name}.xcframework" From d9c39f352408b6442bf6f7c4da8bc851deabaa61 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Fri, 12 Jan 2024 12:01:21 -0500 Subject: [PATCH 31/31] Update build scripts to skip codesigning - SSDK-528 --- scripts/build.sh | 4 ++-- scripts/build_spm_sample.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 0780880cb..8e649f8ed 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -26,8 +26,8 @@ pushd "${PROJECT_ROOT}" > /dev/null SIMULATOR_ARCHIVE_NAME="${RESULT_PRODUCTS_DIR}/Search-iphonesimulator.xcarchive" DEVICE_ARCHIVE_NAME="${RESULT_PRODUCTS_DIR}/Search-iphoneos.xcarchive" -xcodebuild archive -scheme "MapboxSearchUI" -destination "generic/platform=iOS Simulator" SKIP_INSTALL=NO ${MARKETING_VERSION:+MARKETING_VERSION=${MARKETING_VERSION}} -archivePath "${SIMULATOR_ARCHIVE_NAME}" -xcodebuild archive -scheme "MapboxSearchUI" -destination "generic/platform=iOS" SKIP_INSTALL=NO ${MARKETING_VERSION:+MARKETING_VERSION=${MARKETING_VERSION}} -archivePath "${DEVICE_ARCHIVE_NAME}" +xcodebuild archive -scheme "MapboxSearchUI" -destination "generic/platform=iOS Simulator" SKIP_INSTALL=NO ${MARKETING_VERSION:+MARKETING_VERSION=${MARKETING_VERSION}} -archivePath "${SIMULATOR_ARCHIVE_NAME}" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO +xcodebuild archive -scheme "MapboxSearchUI" -destination "generic/platform=iOS" SKIP_INSTALL=NO ${MARKETING_VERSION:+MARKETING_VERSION=${MARKETING_VERSION}} -archivePath "${DEVICE_ARCHIVE_NAME}" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO for frameworkName in "MapboxSearch" "MapboxSearchUI" do diff --git a/scripts/build_spm_sample.sh b/scripts/build_spm_sample.sh index 83e20dbb7..ab675f032 100755 --- a/scripts/build_spm_sample.sh +++ b/scripts/build_spm_sample.sh @@ -38,7 +38,7 @@ EOF BASEDIR="${BASEDIR}" xcodegen xcodebuild -resolvePackageDependencies -derivedDataPath derivedData -scheme CircleCIApp -xcodebuild -scheme "CircleCIApp" -destination 'platform=iOS Simulator,name=iPhone 13,OS=15.0' -derivedDataPath derivedData/ -project CircleCIApp.xcodeproj CODE_SIGNING_ALLOWED=NO +xcodebuild -scheme "CircleCIApp" -destination 'platform=iOS Simulator,name=iPhone 13,OS=15.0' -derivedDataPath derivedData/ -project CircleCIApp.xcodeproj CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO popd