Pathshare is a realtime location sharing platform. For more information please visit the Pathshare Developer Page.
PathshareSDK for iOS supports iOS 12.x, 13.x, 14.x, 15.x and 16.x.
Add the following line to your Podfile:
pod 'PathshareSDK', '~> 2.3'Then install PathshareSDK into your project by executing the following code:
pod installThe installation of the Pathshare SDK is simple. Please follow the following steps:
- Drag and drop the
PathshareSDK.xcframeworkyou received upon registration into your project. - Add the
PathshareSDK.xcframeworkto the Embedded Binaries in the general tab of your target.
In order to allow access to the location services and to use the location services in the background, please add the following configuration in your project:
- Add the
NSLocationAlwaysUsageDescription, theNSMotionUsageDescription,NSLocationAlwaysAndWhenInUseUsageDescriptionand theNSLocationWhenInUseUsageDescriptionkeys with the corresponding descriptions to yourInfo.plistfile. - If you are building against iOS 11.+, go to your
Project Target>Capabilities>Background Modesand enableLocation updates.
In order to initialize the Pathshare SDK, create a file named pathshare.plist inside your project and add your account token:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>account_token</key>
<string>your PathshareSDK account token</string>
</dict>
</plist>
Next, add the following to the application:didFinishLaunchingWithOptions: method of your AppDelegate class:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self initPathshare];
return YES;
}
...
- (void)initPathshare
{
NSString *pathshare = [NSBundle.mainBundle pathForResource:@"pathshare" ofType:@"plist"];
NSDictionary *config = [[NSDictionary alloc] initWithContentsOfFile:pathshare];
[Pathshare setAccountToken:config[@"account_token"]];
[Pathshare setTrackingMode:PSTrackingModeSmart];
}func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
initPathshare()
return true
}
...
private func initPathshare() {
let pathshare = NSBundle.mainBundle().pathForResource("Pathshare", ofType:"plist") as String!
let config = NSDictionary(contentsOfFile: pathshare) as NSDictionary!
Pathshare.setAccountToken(config!.valueForKey("account_token") as! String)
Pathshare.setTrackingMode(.smart)
}Optionally, you can specify a tracking mode to configure the behavior of the location tracker. The following tracking modes are available:
| Tracking Mode | Description |
|---|---|
PSTrackingModeSmart |
Adapts intelligently to the environment and usage of the device. Includes awareness of battery level, travel speed and motion activity. |
PSTrackingModeEco |
Static mode providing constant tracking data with very low accuracy (several kilometers) and great distance between single locations and ensuring maximum battery life. |
PSTrackingModeApproximate |
Static mode providing constant tracking data with low accuracy (several hundred meters) and middle distance between single locations. Useful when a low battery drain is a important criteria. |
PSTrackingModeAccurate |
Static mode providing constant tracking with the highest accuracy possible (few meters) and small distances between locations. Useful for scenarios where a high accuracy is an essential requirement. |
Before creating a session, you need to set a username:
[Pathshare saveUser:@"SDK User ios"
type:UserTypeTechnician
email:@"me@email.com"
phone:@"+12345678901"
image:[UIImage imageNamed:@"image"]
completionHandler:^(NSError *error) {
if (error) {
// ...
} else {
// ...
}
}
];Pathshare.saveUser("SDK User",
type: .technician,
email: "me@email.com",
phone: "+12345678901",
image: UIImage.init(named: "image")) { (error: NSError!) -> Void in
if error != nil {
// ...
} else {
// ...
}
}The email address can be nil.
Use the same method Pathshare.saveUser() to create or update the user.
There are different types of users for specific industries:
| User Types | Description |
|---|---|
TECHNICIAN, MOTORIST |
For roadside assitance industry or similar |
DRIVER, RECIPIENT |
For delivery services or similar |
INVESTIGATOR, CLIENT |
For legal services industry or similar |
Use the session initializer to create a session:
Session *session = [[Session alloc] init];
session.expirationDate = expirationDate;
session.name = @"Shopping";var session = Session()
session.expirationDate = expirationDate
session.name = "Shopping"A session must have an expiration date and a name. You can create multiple sessions at the same time, the SDK will manage them for you.
Make sure to save the session after initializing:
[session save:^(NSError *error) { ... }];
session.identifier // => 3fd919fe824d8e7b78e2c11c1570a6f168d2c...
[session isExpired] // => false
[session URL] // => https://pathsha.re/6d39d5session.save { (error: NSError!) -> Void in ... }
session.identifier // => 3fd919fe824d8e7b78e2c11c1570a6f168d2c...
session.isExpired() // => false
session.URL() // => https://pathsha.re/6d39d5In order to react to the expiration of the session, implement the SessionExpirationDelegate protocol in your class:
@interface ViewController : UIViewController <SessionExpirationDelegate>
// ...
@endclass ViewController: UIViewController, SessionExpirationDelegate { ... }Then set the delegate on your session instance:
Session *session = [[Session alloc] init];
session.delegate = self;var session = Session()
session.delegate = selfFinally, implement the sessionDidExpire method in your class to react to the expiration event:
- (void)sessionDidExpire { ... }func sessionDidExpire() { ... }Optionally, you can add a destination to the session. Sessions with destination will show the estimated time of arrival (ETA) for each user. The destination identifier is used to group sessions by destination.
Destination *destination = [[Destination alloc] init];
destination.identifier = @"W2342";
destination.latitude = 47.378178;
destination.longitude = 8.539256;
Session *session = [[Session alloc] init];
//...
session.destination = destination;var destination = Destination()
destination.identifier = "W2342"
destination.latitude = 47.378178
destination.longitude = 8.539256
var session = Session()
//...
session.destination = destinationTo join the session you created, call the join: method on the session object:
[session join:^(NSError *error) { ... }];
[session isUserJoined] // => truesession.join { (error: NSError!) -> Void in ... }
session.isUserJoined() // => trueThis call will add your Pathshare user to the session and you will be able to see his location in realtime on a map in the Pathshare Professional web interface.
To invite a customer to the session, call the inviteUser: method on the session object:
[self.session inviteUserWithName:@"Customer"
type:UserTypeClient
email:@"customer@me.com"
phone:@"+12345678901"
canSetDestination:YES
completionHandler:^(NSURL *url, NSError *error) {
if (error) {
// ...
} else {
// ...
NSLog(@"Invitation URL: %@", url.absoluteString);
}
}];session.inviteUser(withName: "Customer",
type: .client,
email: "customer@me.com",
phone: "+12345678901",
canSetDestination: true) { (url, error) in
if error != nil {
// ...
} else {
// ...
NSLog("Invitation URL: \(String(describing: url?.absoluteString))")
}
}This call will create a customer user and return an invitation URL that can be sent to the customer using your preffered channel. The customer will then see the driver's location in realtime as well as the ETA in a white-labeled view with your corporate identity.
The customer will be able to enjoy the full realtime experience in the web browser of their smartphone:
In order to stop sending user locations and remove the user from the session, call the leave: method:
[session leaveUser:^(NSError *error) { ... }];session.leaveUser { (error: NSError!) -> Void in ... }To find an existing session, use the findSessionWithIdentifier:completionHandler: method with the corresponding session identifier:
[Pathshare findSessionWithIdentifier:@"e2e422"
completionHandler:^(Session *session, NSError *error) {
if (session) {
session.delegate = self;
self.session = session;
}
}];Pathshare.findSessionWithIdentifier("e2e422") { (session: Session!, error: NSError!) -> Void in
if session != nil {
session.delegate = self
self.session = session
}
}
