Swiftpack.co - mapbox/mapbox-search-ios as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by mapbox.
mapbox/mapbox-search-ios v2.0.0-rc.3
Search SDK for iOS with preconfigured UI in Swift
⭐️ 13
🕓 2 weeks ago
iOS macOS
.package(url: "https://github.com/mapbox/mapbox-search-ios.git", from: "v2.0.0-rc.3")

CircleCI Swift version iOS version Xcode version codecov swift-doc

Mapbox Search SDK for iOS

Table of contents

Overview

The Mapbox Search SDK is a developer toolkit to add location search on mobile devices. With the same speed and scale of the Mapbox Search API, the SDK is built specifically for on-demand and local search use cases, like ride-share, food delivery, and store finders apps. Whether your users are trying to find a place among the vast amount of data on a global map, or to find the exact location of a venue a few miles down the road, the Search SDK provides location search for countries all over the globe, in many different languages.

Previously, implementing search into your application required custom tuning with every API request to set a language, location biasing, and result types. There was no pre-built UI and no option for a user to see their search history, or save favorites.

The Mapbox Search SDK allows you to drop pre-tuned search into your application, removing the complexity of API configuration, while still giving you control to customize. It ships with an optional UI framework, or you can build a completely custom implementation with your own UI elements by using the core library. The Search SDK is pre-configured for autocomplete, local search biasing, and includes new features like category search, search history, and search favorites.

Requirements

  • iOS 12.0 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

Main features

  • Easy-to-use pre-tuned search options to integrate search into your app quickly.
    • Local search for a specific address or POI
  • Pre-configured and customizable category search for popular categories like cafes, ATMs, hotels, and gas stations.
  • On-device user search history
  • On-device favorites
  • Import/export customer data with your own protocols
  • Provide you own persistent providers for customer data like History or Favorites

Prerequisites

The SDK requires Carthage which you can install using Homebrew.

  1. Check that Homebrew is installed by running brew -v. If you don't have Homebrew, install before proceeding.
  2. Update Homebrew data to install latest tools versions including Carthage (v0.38 or newer)
    • brew update && brew bundle install
  3. Set up .netrc file for sdk registry access
    1. Create .netrc file in user home directory ($HOME/.netrc, e.g. /Users/victorprivalov/.netrc)
    2. File content:
    machine api.mapbox.com
    login mapbox
    password sk.ey_Your_Access_Token_With_Read_permission
    
  4. Set up commit hooks with ./scripts/install_git_hooks
  5. Build dependencies: make dependencies
  6. Mapbox APIs require a Mapbox account and access token. Get an access token from the Mapbox account page. To run a Demo you can provide a token in different ways:
    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.

    2. Open the Workspace, choose MapboxSearchDemoApplication project and select "Info" tab for "MapboxSearchDemoApplication" target. Here you may set your accessToken for MBXAccessToken key in "Custom iOS Target Properties" section.

  7. Alternatively, you could provide your accessToken as a parameter to SearchEngine.init and other initializers that accept an accessToken parameter. Use this approach to deliver your key dynamically and implement a key rotation schedule.

Getting Started

Once you've installed the prerequisites, no additional steps are needed: Open the Workspace and use any available scheme. The SDK includes a demo app that you can run on your iOS device or simulator by choosing MapboxSearchDemoApplication.

Documentation

You can find the following documentation pages helpful:

Project structure overview

MapboxSearch project consist of five targets:

  1. search-native.a (hidden; Bindgen generated Xcode project)
  2. MapboxCoreSearch.framework (hidden; Bindgen generated Xcode project)
  3. MapboxSearch.framework
  4. MapboxSearchUI.framework
  5. MapboxSearchDemoApplication

search-native.a written in C++ and MapboxCoreSearch.framework is generated by bindgen using Objective-C++ language. Both targets live in submodule and get compiled by scripts in this submodule.

While search-native.a implements most of the shared logic, MapboxSearch.framework contains all the platform business logic for Search.

MapboxSearchUI.framework provides a default UI implementation with customization points to meet the most common customer needs. The UI elements include a search bar with result list, category search icons, history and favorites management, and a combined search/category search UI. (Screenshots coming soon)

MapboxSearchDemoApplication provides a Demo app wih MapboxSearchUI.framework presentation over the basic MapView. To get access to nightly builds in TestFlight, make a request to Search iOS developers.

Integration

Cocoapods

MapboxSearch

To integrate latest preview version of MapboxSearch into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'MapboxSearch', ">= 2.0.0-rc.3", "< 3.0"
MapboxSearchUI

To integrate latest preview version of MapboxSearchUI into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'MapboxSearchUI', ">= 2.0.0-rc.3", "< 3.0"

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/mapbox/mapbox-search-ios.git")
]

Contributing

We welcome feedback and code contributions!

If you found a bug or want to request a feature open a github issue. Please use the appropriate issue template.

Code of Conduct

Our Standards

Examples of behavior that contributes to creating a positive environment include:

  • Using welcoming and inclusive language.
  • Being respectful of differing viewpoints and experiences.
  • Gracefully accepting constructive criticism.
  • Focusing on what is best for the community.
  • Showing empathy towards other community members.

We recommend reading this blog post from Github on writing great PRs..

Versioning

We use SemVer for versioning. For the versions available, see the tags on repository.

GitHub

link
Stars: 13
Last commit: Yesterday
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Release v1.0.0-rc.9
6 days ago

🎉 Added

  • [Core] Add SearchError.owningObjectDeallocated when network responses fail to unwrap guard-let-self. If you encounter this error you must own the reference to the search engine.
  • [Tests] Add UnownedObjectError tests to validate behavior of SearchError.owningObjectDeallocated.

🐞 Fixed

  • [Core] Add xcprivacy for MapboxSearch and MapboxSearchUI
  • [Privacy] Add Search history collected data for the purpose of product personalization (used for displaying the search history)
  • [License] Update license to reflect 2024 usage
  • [SearchUI] Add distanceFormatter field to Configuration to support changing the search suggestions distance format. Nil values will use the default behavior.
  • [UI] Add Right-to-Left language support for Categories/Favorites segment control and fix xib errors.
  • [UI] Add Preview file for CategoriesFavoritesSegmentControl to fix compiler problems.
  • [Tests] Reorganize tests based on API type
  • [Tests] Change MockResponse into a protocol, create separate enums conforming to MockResponse for each API type (geocoding, sbs, autofill), add MockResponse as generic to each test base class and MockWebServer.
  • [Unit Tests] Update and correct tests for iOS 17 using all mocked data.
  • [UI Tests] Update and correct tests for iOS 17 using all mocked data.

❗️ Breaking changes

  • [Core] Stop reading "MapboxAPIBaseURL" from UserDefaults in ServiceProvider.createEngine. (Providing a value in Info.plist is still supported).
  • [Discover] Fix charging station category canonical ID
  • [SearchExample] Update Examples/SearchExample.xcworkspace to use the local package (parent directory) for MapboxSearch.
  • [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.

🔨 Project changes

  • [Core] Updated to Xcode 14.1 minimum version
  • [Core] Updated deployment target to iOS 12
  • [Core] Remove Swifter library dependency from MapboxSearch target (only used in Test targets)
  • [Core] Update SwiftLint to 0.54.0 and SwiftFormat to 0.52.11
  • [Core] Fix project compliance with linter, reformat Swift files
  • [Core] Add Brewfile for project
  • [Core] Remove legacy MGLMapboxAccessToken.
  • [Core] Remove bitcode support

📚 Dependencies

MapboxCommon: v23.0.0 MapboxCoreSearch: v2.0.0

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics