This sample demonstrates how to use AWSLocationTracker
to start and stop location tracking.
- The AWS Mobile SDK for iOS is available through CocoaPods. If you have not installed CocoaPods, install CocoaPods:
sudo gem install cocoapods
pod setup
- To install the AWS Mobile SDK for iOS, change the current directory to the one with your Podfile in it and run the following command:
pod install
- Create new AWS backend resources and pull the AWS services configuration into the app by running the following command:
amplify init # accept default options to get started
amplify push # create the configuration file
- Add the required Cognito resource to your app's cloud-enabled backend using the following CLI command:
amplify add auth
? How do you want users to be able to sign in? `Username`
? Do you want to configure advanced settings? `No, I am done.`
- Create the specified backend by running the following command:
amplify push
-
Allow users access to Amazon Location Service
- Navigate to your Cognito Identity Pool by running the following command:
amplify console auth ? Which console `Identity Pool`
-
Enable access to unauthenticated identities
- From Identity Pool, choose Edit Identity Pool. Note down the name of your Unauthenticated role
- Open the drop down for Unauthenticated Identities, choose Enable access to unauthenticated identities, and then choose Save.
-
Add permission to access Amazon Location Service
- Navigate to the AWS IAM Console, select Roles, and filter on the name of your unauthenticated role. For example,
amplify-<project_name>-<env_name>-<id>-unauthRole
. Select the role you would like to use. - Choose +Add inline policy, make sure to replace
[REGION]
and[ACCOUNT_ID]
with the region that Amazon Location Service is located in and your AWS Account Id, when entering in the following content:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "UpdateDevicePositions", "Effect": "Allow", "Action": [ "geo:BatchUpdateDevicePosition" ], "Resource": [ "arn:aws:geo:[REGION]:[ACCOUNT_ID]:tracker/TrackerExample" ] } ] }
- Navigate to the AWS IAM Console, select Roles, and filter on the name of your unauthenticated role. For example,
-
In order to start tracking, create an Amazon Location Tracking resource to capture and store positions of your users. Create a tracker named
TrackerExample
through Amazon Location Service console. -
Open
TrackingSample.xcworkspace
. -
Click on
awsconfiguration.json
and add theLocation
section, replacing[REGION]
with the region that your Amazon Location Service is located in:
{
"UserAgent": "aws-amplify/cli",
"Version": "0.1.0",
// ...
"Location": {
"Default": {
"Region": "[REGION]"
}
}
}
- In
LocationManagement.swift
, replace the[REGION]
with region that your Amazon Location Service is located in:
let locationTracker = AWSLocationTracker(trackerName: "TrackerExample",
region: AWSRegionType.[REGION],
credentialsProvider: AWSMobileClient.default())
- Build and run the sample app.