Skip to content

Commit

Permalink
Merge branch 'main' into fix-maki-reference
Browse files Browse the repository at this point in the history
  • Loading branch information
aokj4ck authored Apr 9, 2024
2 parents 1eaeb8b + 2ed6263 commit 75566df
Show file tree
Hide file tree
Showing 18 changed files with 288 additions and 55 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ Guide: https://keepachangelog.com/en/1.0.0/

<!-- Add changes for active work here -->

- [Offline] Add optional `language` parameter to SearchOfflineManager.createTilesetDescriptor and SearchOfflineManager.createPlacesTilesetDescriptor functions.
- [Tests] Add Spanish language offline search test.

- [Offline] Added OfflineIndexObserver which accepts two blocks for indexChanged or error events. This can be assigned to the offline search engine to receive state updates.

- [Offline] Change default tileset name to `mbx-main`
- [Tests] Fix Offline tests and re-enable.
- [Tests] Add `offlineResultsUpdated` delegate function to `SearchEngineDelegateStub`.
- [Tests] Demonstrate providing a `Geometry(point: NSValue(mkCoordinate: CLLocationCoordinate2D))` with `TileRegionLoadOptions.build` function.
- [Core] Increment minimum MapboxCommon version from 24.0.0 to 24.2.0.

**MapboxCommon**: v24.2.0

## 2.0.0-rc.3

- [Core] Add `SearchResultAccuracy.proximate` case which "is a known address point but does not intersect a known rooftop/parcel."
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" == 2.0.0-alpha.14
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" == 24.0.0
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" == 24.2.0
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" "24.0.0"
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" "24.2.0"
binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" "2.0.0-alpha.14"
16 changes: 16 additions & 0 deletions MapboxSearch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
0477904D2B890F4E00A99528 /* search-box-retrieve-minsk.json in Resources */ = {isa = PBXBuildFile; fileRef = 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */; };
0477904E2B890F4E00A99528 /* search-box-retrieve-minsk.json in Resources */ = {isa = PBXBuildFile; fileRef = 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */; };
0477904F2B890F4E00A99528 /* search-box-retrieve-minsk.json in Resources */ = {isa = PBXBuildFile; fileRef = 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */; };
0484BCDF2BC4865C003CF408 /* OfflineIndexObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */; };
0484BCE22BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */; };
048823482B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; };
048823492B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; };
0488234A2B6B0A9E00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; };
Expand Down Expand Up @@ -540,6 +542,8 @@
046818E02B87FF5C0082B188 /* search-box-suggestions-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-suggestions-minsk.json"; sourceTree = "<group>"; };
047790482B890A8500A99528 /* search-box-recursion.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-recursion.json"; sourceTree = "<group>"; };
0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-retrieve-minsk.json"; sourceTree = "<group>"; };
0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfflineIndexObserver.swift; sourceTree = "<group>"; };
0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreOfflineIndexChangeEventType.swift; sourceTree = "<group>"; };
04970F8C2B7A97C900213763 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = mapbox.places.san.francisco.json; sourceTree = "<group>"; };
04AB0B792B6AF37800FDE7D5 /* DiscoverIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverIntegrationTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1052,6 +1056,14 @@
path = sbs;
sourceTree = "<group>";
};
0484BCE02BC49A18003CF408 /* Offline */ = {
isa = PBXGroup;
children = (
0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */,
);
path = Offline;
sourceTree = "<group>";
};
04970F8B2B7A97C900213763 /* Resources */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1554,6 +1566,7 @@
F9274FF127394AE600708F37 /* TileRegionError.swift */,
F9274FEA2732BF0E00708F37 /* SearchTileStore.swift */,
F9274FF6273AAE7200708F37 /* TileRegionLoadOptions+Search.swift */,
0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */,
);
path = Offline;
sourceTree = "<group>";
Expand Down Expand Up @@ -1731,6 +1744,7 @@
FEEDD2C12508DFE400DC0A98 /* InternalAPI */ = {
isa = PBXGroup;
children = (
0484BCE02BC49A18003CF408 /* Offline */,
04C127562B62FFD000884325 /* Engine */,
148DE66E285777050085684D /* Common */,
F98BECBB2577B9150081D3BC /* Telemetry */,
Expand Down Expand Up @@ -2664,13 +2678,15 @@
F9E8146225418E7D00F6378E /* EventsManager.swift in Sources */,
FEEDD3002508DFE400DC0A98 /* CLLocationCoordinate2DCodable.swift in Sources */,
FEEDD3042508DFE400DC0A98 /* SearchResultType.swift in Sources */,
0484BCE22BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift in Sources */,
F91FD66C258CCB41008CB8E1 /* CoreResultType+Extensions.swift in Sources */,
FEEDD3152508DFE400DC0A98 /* ServerSearchResult.swift in Sources */,
140E47A2298BC90E00677E30 /* Discover.swift in Sources */,
14FA65872953644400056E5B /* PlaceAutocomplete+Suggestion.swift in Sources */,
04C127552B62F6BC00884325 /* ApiType.swift in Sources */,
FE059C5A251A0AE6001F7701 /* SearchCategorySuggestionImpl.swift in Sources */,
FEEDD2F62508DFE400DC0A98 /* CoreSearchResultResponse.swift in Sources */,
0484BCDF2BC4865C003CF408 /* OfflineIndexObserver.swift in Sources */,
FE260A6725C063880037B725 /* ReverseGeocodingOptions.swift in Sources */,
FECA461026D3F81800BC7B18 /* MapboxSearchUserAgent.swift in Sources */,
FEEDD2F32508DFE400DC0A98 /* CoreBoundingBox.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
</EnvironmentVariable>
</EnvironmentVariables>
<LocationScenarioReference
identifier = "com.apple.dt.IDEFoundation.CurrentLocationScenarioIdentifier"
identifier = "San Francisco, CA, USA"
referenceType = "1">
</LocationScenarioReference>
</LaunchAction>
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Foundation

let (coreSearchVersion, coreSearchVersionHash) = ("2.0.0-alpha.14", "c3e61341f2beb1b8043f3c71caccdd9bea12a23f221cb90eb452e2abe299c3e0")

let commonMinVersion = Version("24.0.0")
let commonMinVersion = Version("24.2.0")
let commonMaxVersion = Version("25.0.0")

let package = Package(
Expand Down
7 changes: 6 additions & 1 deletion Sources/Demo/MapRootController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class MapRootController: UIViewController {

engine.setOfflineMode(.enabled) {
let descriptor = SearchOfflineManager.createDefaultTilesetDescriptor()
let dcLocation = NSValue(cgPoint: CGPoint(x: 38.89992081005698, y: -77.03399849939174))

let dcLocation = NSValue(mkCoordinate: CLLocationCoordinate2D(
latitude: 38.89992081005698,
longitude: -77.03399849939174
))

guard let options = MapboxCommon.TileRegionLoadOptions.build(
geometry: Geometry(point: dcLocation),
descriptors: [descriptor],
Expand Down
6 changes: 6 additions & 0 deletions Sources/MapboxSearch/InternalAPI/CoreAliases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ typealias CoreUserActivityReporterOptions = MapboxCoreSearch.UserActivityReporte

typealias CoreReverseGeoOptions = MapboxCoreSearch.ReverseGeoOptions

// Offline
typealias CoreOfflineIndexObserver = MapboxCoreSearch.OfflineIndexObserver
typealias CoreOfflineIndexChangeEvent = MapboxCoreSearch.OfflineIndexChangeEvent
typealias CoreOfflineIndexError = MapboxCoreSearch.OfflineIndexError
typealias CoreOfflineIndexChangeEventType = MapboxCoreSearch.OfflineIndexChangeEventType

let mapboxCoreSearchErrorDomain = "MapboxCoreSearchErrorDomain"

extension CoreSearchEngine {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ protocol CoreSearchEngineProtocol {
func setTileStore(_ tileStore: MapboxCommon.TileStore, completion: (() -> Void)?)

func setTileStore(_ tileStore: MapboxCommon.TileStore)

func addOfflineIndexObserver(for observer: CoreOfflineIndexObserver)

func removeOfflineIndexObserver(for observer: CoreOfflineIndexObserver)
}

extension CoreSearchEngine: CoreSearchEngineProtocol {
Expand Down
57 changes: 53 additions & 4 deletions Sources/MapboxSearch/InternalAPI/CoreSearchEngineStatics.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
import Foundation

enum CoreSearchEngineStatics {
static func createTilesetDescriptor(dataset: String, version: String) -> MapboxCommon.TilesetDescriptor {
CoreSearchEngine.createTilesetDescriptor(forDataset: dataset, version: version)
enum Constants {
static let delimiter = "_"
}

static func createPlacesTilesetDescriptor(dataset: String, version: String) -> MapboxCommon.TilesetDescriptor {
CoreSearchEngine.createPlacesTilesetDescriptor(forDataset: dataset, version: version)
static func createTilesetDescriptor(dataset: String, version: String, language: String? = nil) -> MapboxCommon
.TilesetDescriptor {
let identifier: String
if let language {
if ISOLanguages.contains(language: language) {
identifier = dataset + Constants.delimiter + language
} else {
_Logger.searchSDK
.warning(
"Provided language code '\(language)' for tileset is non-ISO. Dataset '\(dataset)' without language will be used."
)
identifier = dataset
}
} else {
identifier = dataset
}
return CoreSearchEngine.createTilesetDescriptor(forDataset: identifier, version: version)
}

static func createPlacesTilesetDescriptor(dataset: String, version: String, language: String? = nil) -> MapboxCommon
.TilesetDescriptor {
let identifier: String
if let language {
if ISOLanguages.contains(language: language) {
identifier = dataset + Constants.delimiter + language
} else {
_Logger.searchSDK
.warning(
"Provided language code '\(language)' for places tileset is non-ISO. Dataset '\(dataset)' without language will be used."
)
identifier = dataset
}
} else {
identifier = dataset
}
return CoreSearchEngine.createPlacesTilesetDescriptor(forDataset: identifier, version: version)
}
}

enum ISOLanguages {
static func contains(language: String) -> Bool {
var validLanguage: Bool
if #available(iOS 16, *) {
validLanguage = Locale.LanguageCode.isoLanguageCodes
.map(\.identifier)
.contains(language)
} else {
validLanguage = Locale.isoLanguageCodes
.contains(language)
}
return validLanguage
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright © 2024 Mapbox. All rights reserved.

import Foundation

extension CoreOfflineIndexChangeEventType: CustomDebugStringConvertible {
public var debugDescription: String {
switch self {
case .added:
return "Added"
case .removed:
return "Removed"
case .updated:
return "Updated"
@unknown default:
return "Unknown"
}
}
}
3 changes: 1 addition & 2 deletions Sources/MapboxSearch/PublicAPI/DefaultLocationProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import CoreLocation
/// Would not trigger Location Permission dialogs but will retrieve permission changes notification.
/// Suitable for `SearchEngine` for providing user location by default without additional efforts.
public class DefaultLocationProvider {
// not used anywhere as public
/* public */ let locationManager: CLLocationManager
let locationManager: CLLocationManager

#if FAST_LOCATION_CHANGES_TRACKING
let locationRequestFrequency: TimeInterval = 1
Expand Down
29 changes: 29 additions & 0 deletions Sources/MapboxSearch/PublicAPI/Offline/OfflineIndexObserver.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright © 2024 Mapbox. All rights reserved.

import Foundation

class OfflineIndexObserver: CoreOfflineIndexObserver {
enum Types {
typealias indexChangedBlock = (CoreOfflineIndexChangeEvent) -> Void
typealias errorBlock = (CoreOfflineIndexError) -> Void
}

private var onIndexChangedBlock: Types.indexChangedBlock
private var onErrorBlock: Types.errorBlock

init(
onIndexChangedBlock: @escaping Types.indexChangedBlock = { _ in },
onErrorBlock: @escaping Types.errorBlock = { _ in }
) {
self.onIndexChangedBlock = onIndexChangedBlock
self.onErrorBlock = onErrorBlock
}

func onIndexChanged(for event: CoreOfflineIndexChangeEvent) {
onIndexChangedBlock(event)
}

func onError(forError error: CoreOfflineIndexError) {
onErrorBlock(error)
}
}
39 changes: 33 additions & 6 deletions Sources/MapboxSearch/PublicAPI/Offline/SearchOfflineManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

/// OfflineManager handles `TileStore`s and responsible for creating Search `TilsetDescriptor`s
public class SearchOfflineManager {
static let defaultDatasetName = "test-dataset"
static let defaultDatasetName = "mbx-main"

var engine: CoreSearchEngineProtocol

Expand Down Expand Up @@ -41,26 +41,53 @@ public class SearchOfflineManager {
engine.setTileStore(searchTileStore.commonTileStore, completion: completion)
}

/// Creates TilesetDescriptor for offline search index data with provided dataset name and version.
// MARK: - Tileset with name, version, and language parameters

/// Creates TilesetDescriptor for offline search index data with provided dataset name, version, and language.
/// Providing nil or excluding the language parameter will use the dataset name as-is.
/// Providing a language will append it to the name.
/// - Parameters:
/// - dataset: dataset name
/// - version: dataset version
/// - language: Provide a ISO 639-1 Code language from NSLocale. Values will be appended to the place dataset
/// name.
/// - Returns: TilesetDescriptor for TileStore
public static func createTilesetDescriptor(dataset: String, version: String? = nil) -> MapboxCommon
public static func createTilesetDescriptor(
dataset: String,
version: String? = nil,
language: String? = nil
) -> MapboxCommon
.TilesetDescriptor {
CoreSearchEngineStatics.createTilesetDescriptor(dataset: dataset, version: version ?? "")
CoreSearchEngineStatics.createTilesetDescriptor(
dataset: dataset,
version: version ?? "",
language: language
)
}

/// Creates TilesetDescriptor for offline search boundaries with provided dataset name and version.
/// Providing nil or excluding the language parameter will use the places dataset name as-is.
/// Providing a language will append it to the name.
/// - Parameters:
/// - dataset: dataset name
/// - version: dataset version
/// - language: Provide a ISO 639-1 Code language from NSLocale. Values will be appended to the dataset name.
/// - Returns: TilesetDescriptor for TileStore
public static func createPlacesTilesetDescriptor(dataset: String, version: String? = nil) -> MapboxCommon
public static func createPlacesTilesetDescriptor(
dataset: String,
version: String? = nil,
language: String? = nil
) -> MapboxCommon
.TilesetDescriptor {
CoreSearchEngineStatics.createPlacesTilesetDescriptor(dataset: dataset, version: version ?? "")
CoreSearchEngineStatics.createPlacesTilesetDescriptor(
dataset: dataset,
version: version ?? "",
language: language
)
}

// MARK: - Default tileset

/// Creates TilesetDescriptor for offline search index data using default dataset name.
/// - Returns: TilesetDescriptor for TileStore
public static func createDefaultTilesetDescriptor() -> MapboxCommon.TilesetDescriptor {
Expand Down
3 changes: 1 addition & 2 deletions Tests/Demo.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
"testTargets" : [
{
"skippedTests" : [
"MockServerIntegrationTestCase",
"OfflineIntegrationTests"
"MockServerIntegrationTestCase"
],
"target" : {
"containerPath" : "container:MapboxSearch.xcodeproj",
Expand Down
Loading

0 comments on commit 75566df

Please sign in to comment.