Code Monkey home page Code Monkey logo

roam-ios's Introduction


Pod version CocoaPod Publish

Official Roam iOS SDK

This is the official Roam iOS SDK developed and maintained by Roam B.V

Note: Before you get started signup to our dashboard to get your API Keys.

Quickstart

The Roam iOS SDK makes it quick and easy to build a location tracker for your iOS app. We provide powerful and customizable tracking modes and features that can be used to collect your users’ location updates.

Requirements

To use the Roam SDK, the following things are required: Get yourself a free Roam Account. No credit card required.

  • Create a project and add an iOS app to the project.
  • You need the SDK_KEY in your project settings which you’ll need to initialize the SDK.
  • Now you’re ready to integrate the SDK into your iOS application.
  • The Roam iOS SDK requires Xcode 10.0 or later and it compatible with apps targeting iOS version 10 and above.

Xcode Setup

To integrate the Roam SDK, you need a Roam account.

  1. Go to Xcode > File > New Project

  2. Configure the information property list file Info.plist with an XML snippet that contains data about your app. You need to add strings for NSLocationWhenInUseUsageDescription in the Info.plist file to prompt the user during location permissions for foreground location tracking. For background location tracking, you also need to add a string for NSLocationAlwaysUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription in the same Info.plist file.

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Add description for foreground only location usage.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Add description for background location usage. iOS 10 and below"</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Add description for background location usage. iOS 11 and above</string>

    Screenshot 2021-06-25 at 8 40 46 PM

  3. Next you need to enableBackground fetch and Location updates under Project Setting > Capabilities > Background Modes.

    Screenshot 2021-06-25 at 8 38 24 PM

Include the SDK for iOS in an Existing Application

There are several ways to integrate the Roam Mobile SDK for iOS into your own project:

  • Swift Package Manager
  • CocoaPods
  • Carthage (Will be added soon)
  • Dynamic Frameworks

Swift Package Manager Installation

  1. Swift Package Manager is distributed with Xcode. To start adding the AWS SDK to your iOS project, open your project in Xcode and select File > Swift Packages > Add Package Dependency.

image

  1. Enter the URL for the Roam SDK for iOS Swift Package Manager GitHub repo (https://github.com/roam-ai/roam-ios) into the search bar and click Next.

Screenshot 2021-06-29 at 12 17 45 PM

  1. You'll see the repository rules for which version of the SDK you want Swift Package Manager to install. Choose the first rule, Version, and select Up to Next Minor as it will use the latest compatible version of the dependency that can be detected from the main branch, then click Next.

Screenshot 2021-06-29 at 12 20 11 PM

  1. Select all that are appropriate, then click Finish.

Screenshot 2021-06-29 at 12 22 38 PM

You can always go back and modify which SPM packages are included in your project by opening the Swift Packages tab for your project: Click on the Project file in the Xcode navigator, then click on your project's icon, then select the Swift Packages tab.

CocoaPods Installation

Follow the steps below to add the SDK to the project using CocoaPods. Add the below to the Podfile

pod 'roam-ios'

Then run pod install.

This will add the Roam SDK and its dependencies to your project. The Roam SDK depends on CoreLocation, AWSMobileClient and AWSIoT for fetching locations and its transmission to our servers. The SDK supports iOS 10 and above.

Manual Installation

If you’re not familiar with using Cocoapods or prefer manual installation, we’ve added a ZIP file to the SDK. Use this link to download the Roam.zip file.

Unzip the file and add the Roam Roam.framework to your Xcode project by dragging the file into your Project Navigator.

You can do this by selecting the project file in the navigator on the left side of the Xcode window, and then navigating to the Linked Frameworks and Libraries section. From there, click the “+” button to add the Roam framework. You will also want to add the following frameworks from this link.

AWSAuthCore.xcframework
AWSCognitoIdentityProvider.xcframework
AWSCognitoIdentityProviderASF.xcframework
AWSCore.xcframework
AWSIoT.xcframework
AWSMobileClientXCF.xcframework

Make sure the the added frameworks under Linked Frameworks and Libraries section are selected as Embed & Sign

Screenshot 2021-06-25 at 8 45 56 PM

Initialize SDK

Add the following code in AppDelegate file. This code imports the SDK and allows the SDK to use other methods.

import Roam

After import, add the below code under application(_:didFinishLaunchingWithOptions:) in your AppDelegate file. The SDK must be initialized before calling any of the other SDK methods using your project's publishable key.

Roam.initialize("YOUR-SDK-KEY-GOES-HERE")

Creating Users

Once the SDK is initialised, you need to create or get a user to start the tracking and use other methods. Every user created will have a unique Roam identifier which will be used to login and access developer APIs. We call this Roam user_Id.

Roam.createUser("YOUR-USER-DESCRIPTION-GOES-HERE") {(RoamUser, Error) in
            // Access Roam user data below
            // RoamUser?.userId
            // RoamUser?.description
            // RoamUser?.locationListener
            // RoamUser?.eventsListener
            // RoamUser?.locationEvents
            // RoamUser?.geofenceEvents
            // RoamUser?.tripsEvents
            // RoamUser?.nearbyEvents
            
            // Access error code & message below
            // Error?.code
            // Error?.message
        }

The option user description can be used to update user information such as name, address or add an existing user ID. Make sure the information is encrypted if you are planning to save personal information like an email or phone number.

You can always set or update user descriptions later using the below code.

Roam.setDescription("SET-USER-DESCRIPTION-HERE")

Get User

If you already have a Roam user_ID which you would like to reuse instead of creating a new user, use the code below to get a user session.

Roam.getUser("YOUR-ROAM-USER-ID") {(RoamUser, Error) in
            // Access Roam user data below
            // RoamUser?.userId
            // RoamUser?.description
            // RoamUser?.locationListener
            // RoamUser?.eventsListener
            // RoamUser?.locationEvents
            // RoamUser?.geofenceEvents
            // RoamUser?.tripsEvents
            // RoamUser?.nearbyEvents
            
            // Access error code & message below
            // Error?.code
            // Error?.message
        }

Request Permissions

Before you start location tracking, you need to get permission from the user for your application to access locations.

  1. Import CoreLocation at the top of the AppDelegate file.

    import CoreLocation
  2. Make the below class declaration for Location Manager and add this line before the return statement in application(_:didFinishLaunchingWithOptions:) With this line, you ask users to allow the app to access location data both in the background and the foreground.

    let locationManager = CLLocationManager()
    locationManager.requestLocation()

SDK Configurations

Accuracy Engine

For enabling accuracy engine for Passive, Active, and Balanced tracking.

Roam.enableAccuracyEngine()

For Custom tracking mores, you can pass the desired accuracy values in integers ranging from 25-150m.

Roam.enableAccuracyEngine(50)

To disable accuracy engine

Roam.disableAccuracyEngine()

Offline Location Tracking

To modify the offline location tracking configuration, which will enabled by default.

Roam.offlineLocationTracking(true)

Location Tracking

Start Tracking

Use the below tracking modes while you use the startTracking method Roam.startTracking

Tracking Modes

You can now start tracking your users. Roam has three default tracking modes along with a custom version. They are different based on the frequency of location updates and battery consumption. The higher the frequency, the higher the battery consumption.

Mode Battery usage Updates every Optimised for/advised for
Active 6% - 12% 25 ~ 250 meters Ride Hailing / Sharing
Balanced 3% - 6% 50 ~ 500 meters On Demand Services
Passive 0% - 1% 100 ~ 1000 meters Social Apps
//active tracking
Roam.startTracking(RoamTrackingMode.active)
// balanced tracking
Roam.startTracking(RoamTrackingMode.balanced)
// passive tracking
Roam.startTracking(RoamTrackingMode.passive)

Custom Tracking Modes

The SDK also provides a custom tracking mode which allows you to customize and build your own tracking mode as per your requirement.

Type Unit Unit Range
Distance Interval Meters 1m ~ 2500m

Distance between location updates example code:

// Define a custom tracking method
let trackingMethod = RoamTrackingCustomMethods()

// Update the settings for the created method as per need
trackingMethod.activityType = .fitness
trackingMethod.pausesLocationUpdatesAutomatically = true
trackingMethod.showsBackgroundLocationIndicator = true
trackingMethod.useSignificant = false
trackingMethod.useRegionMonitoring = false
trackingMethod.useVisits = false
trackingMethod.accuracyFilter = 10
trackingMethod.desiredAccuracy = .kCLLocationAccuracyNearestTenMeters

// Update the distance intervel as per the use case in meters
trackingMethod.distanceFilter = 10

// Start the tracking with the above created custom tracking method
Roam.startTracking(.custom, options: trackingMethod)

Time between location updates example code:

// Define a custom tracking method
let trackingMethod = RoamTrackingCustomMethods()

// Update the settings for the created method as per need
trackingMethod.activityType = .fitness
trackingMethod.pausesLocationUpdatesAutomatically = true
trackingMethod.showsBackgroundLocationIndicator = true
trackingMethod.useSignificant = false
trackingMethod.useRegionMonitoring = false
trackingMethod.useVisits = false
trackingMethod.accuracyFilter = 10
trackingMethod.desiredAccuracy = .kCLLocationAccuracyNearestTenMeters

// Update the time intervel as per the use case in seconds
trackingMethod.updateInterval = 10

// Start the tracking with the above created custom tracking method
Roam.startTracking(.custom, options: trackingMethod)

Stop Tracking

To stop the tracking use the below method.

Roam.stopTracking()

Publish Messages

It will publish location data and these data will be sent to roam-ios servers for further processing and data will be saved in our database servers.

let locationData = RoamPublish()
Roam.publishSave(locationData)

To stop publishing the location data to other clients.

Roam.stopPublishing()

Subscribe Messages

Now that you have enabled the location listener, use the below method to subscribe to your own or other user's location updates and events.

Subscribe

Roam.subscribe(TYPE, "ROAM-USER-ID")

UnSubscribe

Roam.unsubscribe(TYPE, "ROAM-USER-ID")
Type Description
RoamSubscribe.Events Subscribe to your own events.
RoamSubscribe.Location Subscribe to your own location (or) other user's location updates.
RoamSubscribe.Both Subscribe to your own events and location (or) other user's location updates.

Listeners

Now that the location tracking is set up, you can subscribe to locations and events and use the data locally on your device or send it directly to your own backend server.

To do that, you need to toggle the location and event listener to true. By default, the status will set to false and needs to be set to true in order to stream the location and events updates to the same device or other devices.

Roam.toggleListener(Events: true, Locations: true) {(RoamUser, Error) in
            // Access Roam user data below
            // RoamUser?.userId
            // RoamUser?.description
            // RoamUser?.locationListener
            // RoamUser?.eventsListener
            // RoamUser?.locationEvents
            // RoamUser?.geofenceEvents
            // RoamUser?.tripsEvents
            // RoamUser?.nearbyEvents
            
            // Access error code & message below
            // Error?.code
            // Error?.message
        }

Once the listener toggles are set to true, to listen to location updates create a class that implements RoamDelegate and then call Roam.delegate.

Set your RoamDelegate in a code path that will be initialized and executed in the background. For example, make your AppDelegate implement GeoSparkDelegate, not a ViewController. AppDelegate will be initialized in the background, whereas a ViewController may not be.

import UIKit
import Roam
import CoreLocation

@main
class AppDelegate: UIResponder, UIApplicationDelegate, RoamDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        Roam.delegate = self
        Roam.initialize("YOUR-SDK-KEY-GOES-HERE")
        return true
    }
    func didUpdateLocation(_ location: RoamLocation) {
        // Do something with the user location
    }
    func didReceiveEvents(_ events: RoamEvents) {
        // Do smoething with user events
    }
    func didReceiveUserLocation(_ location: RoamLocationReceived) {
        // Do something with location of other users' subscribed location
    }

Example

See a Swift example app in Example/. To run the example app, clone this repository, add your sdk "YOUR-SDK-KEY" key in AppDelegate.swift, and build the app.

Need Help?

If you have any problems or issues over our SDK, feel free to create a github issue or submit a request on Roam Help.

roam-ios's People

Contributors

dinesh-roam avatar jothipriyadharshanr avatar manojadithya avatar ravikanththummala avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

roam-ios's Issues

Update location when user comes to stationary

Discussed in #18

Originally posted by jothipriyadharshanr July 22, 2021
When
users are not moving
I want to
fetch user location on regular time interval
So that
we can get location updates when user is stationary.

Xcode 12+ fails to build Example app for both simulator and device

Xcode 12.5 displays this error when running a build for either device or simulator:
"Building for iOS Simulator, but the linked and embedded framework 'Roam.framework' was built for iOS + iOS Simulator."

This appears to require building an XCFramework by the third party, i.e. Roam.ai.

These links may be instructive:

Does Roam SDK - XCFramework version support new ARM based Mac?

Description:

Hi, we integrated XCFramework version of Roam iOS SDK and it worked on an Intel CPU Macbook, however it didn't work on new ARM based Mac (M1) e.g. Mac Mini, Macbook Air, Macbook Pro. Are we missing anything while setting this up?

Environment:

  1. Version: 0.0.6 XCFramework
  2. Cocoapods

Steps to Reproduce Issue: NA
Anything else: NA

(crash stacktraces, as well as any other information here)

Crash creating user

Unsuccessful getting data from the sdk. The following images illustrate our actions and crash console output.

The call to Roam.createUser( [user description]) always results in a crash (building on devices iPhone 7 and iPhone 10X).

initialization-image
create-user-image
console-image.

The following is an iPhone 7 device crash log.

TestRoam 6-21-21, 7-50 PM.crash.txt (without symbolication of SDK selectors).


The GeoSpark project playground shows a number of users, presumably created by multiple attempts to create a user in code, but the result of the call crashes. Also, attempts to save a userID from the Roam user object returned to the invocation closure fail.

Note that only invoking Roam.initialize([production key]) and Roam.setLogging(true) results in console output, "GeoSpark initialized Success", without a crash, but with no functionality.
initialize-success-console

Also note that building to simulator IPhone 12 Pro always results in many undefined symbol errors, along with the warning:
Ignoring file /Users/eturner/Programming/Learning/TestRoam/Pods/roam-ios/Roam/Roam.framework/Roam, building for iOS Simulator-x86_64 but attempting to link with file built for iOS-arm64

Target is not building successfully on Simulator after the CocoaPods installation for Apple Silicon

Hi,

I am using Apple Silicon machine and not running Xcode in Rosetta anymore. After the installation via CocoaPods, I'm getting multiple missing architecture error for every different target in my project like;

The linked and embedded framework '{......}.framework' is missing one or more architectures required by this target: x86_64.

The project building fine on device though, but I can import Roam SDK anyway.

I tried all other installation types and I've got different errors. I will open different issues for them but CocoaPods preferable way for us.

What can we do about it?

Allow meta-data support for updating location ie. updateCurrentLocation method

Discussed in #16

Originally posted by jothipriyadharshanr July 22, 2021
When
being a developer, during updateCurrentLocation() method
I want to
send custom meta-data (ie. key value pairs) along with that specific location update
So that
we can tag the meta-data only to single location update and not for all the location update, when we add the same using publishSave() method.

Things to notice

  • If the publishSave() method already has meta-data added, this will be overwritten by the meta-data passed in updateCurrentLocation() method and applied only for that specific location update and rest will continue to use the previous configurations passed in publishSave() method.

Error while the implementing SDK via manually

Hi,

I'm using M1 Macbook Pro and Xcode vs13.4.1

I also tried to implement SDK via manually. I downloaded all other AWS dependencies via CocoaPods. I've got a couple of AWSCocoaLumberjack errors and I fixed them all on my locale to see the result.

As a result I've got an error while I'm trying to import Roam SDK like;

Failed to build module 'Roam!: this SDK is not supported b the compiler (the SDK is built with 'Apole Swift version 5.4.2 (swiftlang-1205.0.28.2
clang-1205 0 19 571 while this comniler is 'Anne Swift versinn 5 6 1 (swiftlana-5 6 0 323 66 clang-1316 0 20 121) PlAase select a toolr
hain which matcher
SDK.

Looks like we are using higher version of Swift.

Are you planning to support higher swift version?

Add support for the new xcframework format

Apple introduced a new .xcframework bundle format for both ObjC and Swift/mixed frameworks. The main benefit is that this structure can contain multiple architectures and doesn't require lipo to fuse them together.

An xcframework can be made by xcodebuild -create-xcframework which takes -framework and -output options. xcframework supports both source and binary frameworks. dSYM still need to be manually added, just like you had to with binary frameworks.

What we need:

  • CocoaPods should be able to integrate xcframework bundles just like it does with regular (binary) framework bundles.
  • Stripping architectures is no longer necessary

Make `startTrip` independent by combining it with `startTracking` and `createTrip` methods

Discussed in #27

Originally posted by jothipriyadharshanr August 10, 2021
Currently

  • The startTrip() method has a mandatory input parameter ie. trip_id and return success or error callbacks when trips starts or error.
  • The restriction for the developer is that they need a valid trip_id which has to be either created by createTrip() method or Create Trip API assigned to the user initially before startTrip()
  • And if the developer wants to startTracking() with desired tracking method along with the startTrip() is not possible.

Proposed

  • We need the startTrip() method to have optional values below:
  • trackingMode
  • description
  • metaData
  • localTrip
  • origin(s) & destination(s)
  • tripId
  • We also need the stopTrip() method to have optional values below:
  • tripId
  • trackingMode
  • forceStop

Example

Roam.startTrip(tripId: String,  metaData: Dictionary, localTrip: Bool, origin: Dictionary, destination: Dictionary, description: String, trackingMethod: RoamTrackingMode, options: RoamTrackingCustomMethods ) { RoamStartTrip, RoamError in
            RoamStartTrip.tripId,
            RoamStartTrip.status,
            RoamStartTrip.createdAt,
            RoamStartTrip.updatedAt,
            RoamStartTrip.userId,
            RoamStartTrip.tripTrackingUrl,
            RoamStartTrip.origin,
            RoamStartTrip.destination,
            RoamStartTrip.isStarted,
            RoamStartTrip.isDeleted,
            RoamStartTrip.isEnded,
            RoamStartTrip.metaData,
            RoamStartTrip.isLocalTrip,
            RoamStartTrip.description
        }
Roam.endTrip(tripId: String, trackingMethod: RoamTrackingMode, options: RoamTrackingCustomMethods, forceStopTracking: Bool) { RoamEndTrip, RoamError in
            RoamEndTrip.status
            RoamEndTrip.tripId
        }

Combine `startTracking` and `startSelfTracking` methods

Discussed in #17

Originally posted by jothipriyadharshanr July 22, 2021
Currently

  • The startSelfTracking() does not need user sessions which are basically created using createUser() or getUser() methods.
  • And, they track location locally and does not publish location to Roam.ai servers. Even if the publishSave() methods are being called, they will throw an error.
  • In order to publish location updates to server, along with createUser() or getUser() methods, we have use startTracking() instead of startSelfTracking().

Proposed

  • We can combine the startTracking() and startSelfTracking() into a single method and name it as startTracking()
  • If the user session is not available ie. createUser() or getUser() not being called, the location update works locally and behaves similar to startSelfTracking()
  • And if the user session are enabled using createUser() or getUser() methods and startTracking() will still continue to update locations locally unless until the publishSave() or publishOnly() methods are called
  • Along with this the stopTracking() and stopSelfTracking() into a single method and name it as stopTracking()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.