Swiftpack.co - ably/ably-asset-tracking-swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ably.
ably/ably-asset-tracking-swift v1.0.0-preview.2
iOS client SDKs for the Ably Asset Tracking service.
⭐️ 5
🕓 47 weeks ago
iOS
.package(url: "https://github.com/ably/ably-asset-tracking-swift.git", from: "v1.0.0-preview.2")

Ably SDK

Ably is the platform that powers synchronized digital experiences in realtime. Whether attending an event in a virtual venue, receiving realtime financial information, or monitoring live car performance data – consumers simply expect realtime digital experiences as standard. Ably provides a suite of APIs to build, extend, and deliver powerful digital experiences in realtime for more than 250 million devices across 80 countries each month. Organizations like Bloomberg, HubSpot, Verizon, and Hopin depend on Ably's platform to offload the growing complexity of business-critical realtime data synchronization at global scale. For more information, see the Ably documentation.

Ably Asset Tracking SDKs for Swift

.github/workflows/check.yml

Overview

Ably Asset Tracking SDKs provide an easy way to track multiple assets with realtime location updates powered by the Ably realtime network and Mapbox Navigation SDK with location enhancement.

Status

This SDK is a beta version. That means it contains a subset of the final SDK functionality, and the APIs are subject to change. The latest release of the SDKs is available in the Releases section of this repository.

Ably Asset Tracking is:

  • easy to integrate - comprising two complementary SDKs with easy to use APIs, available for multiple platforms:
  • Asset Publishing SDK, for embedding in apps running on the courier's device.
  • Asset Subscribing SDK, for embedding in apps running on the customer's observing device.
  • extensible - as Ably is used as the underlying transport, you have direct access to your data and can use Ably integrations for a wide range of applications in addition to direct realtime subscriptions - examples include:
  • passing to a 3rd party system
  • persistence for later retrieval
  • built for purpose - the APIs and underlying functionality are explicitly designed to meet the requirements of a range of common asset tracking use-cases

This repo holds an Xcode workspace (Examples/AblyAssetTracking.workspace), containing:

Multiple example apps/ Xcode projects, and

One Swift Package (ably-asset-tracking-swift), containing two libraries/ SDKs:

  • Publisher SDK: The AblyAssetTrackingPublisher library allows you to use import AblyAssetTrackingPublisher.

  • Subscriber SDK: The AblyAssetTrackingSubscriber library allows you to use import AblyAssetTrackingSubscriber.

Documentation

Visit the Ably Asset Tracking documentation for a complete API reference and code examples.

Useful Resources

Installation

Requirements

These SDKs support support iOS and iPadOS. Support for macOS/ tvOS may be developed in the future, depending on interest/ demand.

  • Publisher SDK: iOS 12.0+ / iPadOS 12.0+

  • Subscriber SDK: iOS 12.0+ / iPadOS 12.0+

  • Xcode 12.4+

  • Swift 5.3+

Swift package manager

  • To install this package in an Xcode Project:
  • Paste https://github.com/ably/ably-asset-tracking-swift in the "Swift Packages" search box. (Xcode project > Swift Packages.. > + button)
  • Select the relevant SDK for your target. (Publisher SDK, Subscriber SDK or both)
  • This apple guide explains the steps in more detail.
  • To install this package into a Swift Package, add the following to your manifest (Package.swift):
.package(url: "https://github.com/ably/ably-asset-tracking-swift", from: LATEST_VERSION),

You can find the version on the releases page.

Example Apps

  • Configure your Mapbox credentials (~/.netrc) to download the Mapbox SDK by following this guide. You'll need a Mapbox account.
  • An Examples/Secrets.xcconfig file containing credentials (keys/ tokens) is required to build the example apps. (You can use the example Examples/Example.Secrets.xcconfig, e.g. by running cp Examples/Example.Secrets.xcconfig Examples/Secrets.xcconfig). Update the following values in Examples/Secrets.xcconfig:
  • ABLY_API_KEY: Used by all example apps to authenticate with Ably using basic authentication. Not recommended in production, and can be taken from here.
  • MAPBOX_ACCESS_TOKEN: Used to access Mapbox Navigation SDK/ APIs, and can be taken from here. Using the Mapbox token is only required to run the Publisher example apps.
  • Open AblyAssetTracking.xcworkspace to open an Xcode workspace containing example apps and the Swift Package containing the SDKs that showcase how to use the Ably Asset Tracking SDKs.

Usage

Publisher SDK

The Asset Publisher SDK can efficiently acquire the location data on a device and publish location updates to other subscribers in realtime. Here is an example of how the Asset Publisher SDK can be used:

import AblyAssetTrackingPublisher

// Initialise a Publisher

publisher = try? PublisherFactory.publishers() // get a Publisher Builder
    .connection(ConnectionConfiguration(apiKey: ABLY_API_KEY, clientId: CLIENT_ID)) // provide Ably configuration with credentials
    .log(LogConfiguration()) // provide logging configuration
    .transportationMode(TransportationMode()) // provide mode of transportation for better location enhancements
    .delegate(self) // provide delegate to handle location updates locally if needed
    .start()
    
// Start tracking an asset

publisher?.track(trackable: Trackable(id: trackingId)) // provide a tracking ID of the asset

Subscriber SDK

The Asset Subscriber SDK can be used to receive location updates from a publisher in realtime. Here is an example of how Asset Subscribing SDK can be used:

import AblyAssetTrackingSubscriber

// Initialise a Subscriber

subscriber = try? SubscriberFactory.subscribers() // get a Subscriber Builder
    .connection(ConnectionConfiguration(apiKey: ABLY_API_KEY, clientId: CLIENT_ID)) // provide Ably configuration with credentials
    .trackingId(trackingId) // provide a Tracking ID for the asset to be tracked
    .routingProfile(.cycling) // provide a routing profile for better location enhancements
    .log(LogConfiguration()) // provide logging configuration
    .delegate(self) // provide a delegate to handle received location updates
    .start() // start listening to updates

Authentication

Both Subscriber and Publisher SDK support basic authentication (API key) and token authentication. Specify this by passing a ConnectionConfiguration to the Subscriber or Publisher builder: SubscriberFactory.subscribers().connection(connectionConfiguration).

To use basic authentication, set the following ConnectionConfiguration on the Subscriber or Publisher builder:


let connectionConfiguration = ConnectionConfiguration(apiKey: ABLY_API_KEY, clientId: clientId)

To use token authentication, you can pass a closure which will be called when the Ably client needs to authenticate or reauthenticate:

let connectionConfiguration = ConnectionConfiguration(clientId: clientId) { tokenParams, resultHandler in

    // Implement a request to your servers which provides either a TokenRequest (simplest), TokenDetails, JWT or token string.

    getTokenRequestJSONFromYourServer(tokenParams: tokenParams) { result in
        switch result {
        case .success(let tokenRequest):
            resultHandler(.success(.tokenRequest(tokenRequest)))
        case .failure(let error):
            resultHandler(.failure(error))
        }
    }
}

Alternatively, in token authentication, you can specify an authUrl, which will be used by Ably to authenticate.

let connectionConfiguration = ConnectionConfiguration(authUrl: authUrl, clientId: clientId)

Resources

Feature Support

iOS Client Library feature support matrix.

Support, feedback and troubleshooting

Please visit http://support.ably.com/ for access to our knowledgebase and to ask for any assistance.

You can also view the community reported Github issues.

To see what has changed in recent versions, see the CHANGELOG.

Known Limitations

These SDKs support iOS and iPadOS. Support for macOS / tvOS may be developed in the future, depending on interest / demand.

Contributing

For guidance on how to contribute to this project, see CONTRIBUTING.md.

GitHub

link
Stars: 5
Last commit: 14 hours ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.0.0, Beta 1
1 year ago

Full Changelog

Closed issues:

  • Setup CocoaPods-Keys or similar tool to manage apiKeys locally #25

Merged pull requests:

  • [ATS-119] Set up secrets using .xcconfig file. #78 (robertkuraj)
  • Add maintainers file #72 (niksilver)
  • [ATS-180] Displaying resolution info in PublisherExample app. #67 (robertkuraj)
  • [ATS-179] Setting and changing RoutingProfile in Publisher. #61 (robertkuraj)
  • [ATS-178] Request resolution change from Subscriber Example app #60 (mmiedlarz)
  • [ATS-183] Add support for adding multiple assets in Publisher Example App #59 (mmiedlarz)

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