Repository navigation
Location Sharing iOS SDK
This article describes how to implement location sharing using the iOS SDK.
Location sharing is a Meridian feature that lets users share their location with each other.
Location Sharing requires a blue dot subscription.

If you haven’t already done so, you’ll need to generate a valid token in the Editor. To generate one, in the sidebar menu click Permissions, and then click Application Tokens. Click Add Application + to generate a token for your app. You can name it anything.
When configuring the Meridian SDK, set the application token you generated in the Editor:
MRConfig *config = [[MRConfig alloc] init];
config.applicationToken = @"kd84hf83ck93k39dyi3nxo3mf94";
[Meridian configure:config];The MRSharingSession class is used to create, log in to, and delete accounts. It’s also used to start and stop the sharing service and to receive location sharing updates.
// Creates an account (password can be any string).
self.password = [NSUUID UUID].UUIDString;
[MRSharingSession createAccountWithPassword:self.password firstName:@"Morgan" lastName:@"Smith" appKey:myAppKey completion:^(MRSharingSession * _Nullable session, NSError * _Nullable error) {
if (error) {
NSLog(@"Something went wrong: %@", error.localizedDescription);
} else {
// Now there's a sharing session.
NSLog(@"Got session: %@", session.key.identifier);
// Keeps a reference to the session. Needed for most subsequent requests.
self.session = session;
// Makes self the delegate to get callbacks with fresh data.
self.session.delegate = self;
}
}]; // Logging back in later.
[MRSharingSession loginWithKey:self.session.key password:self.password appKey:myAppKey completion:^(MRSharingSession * _Nullable session, NSError * _Nullable error) {
if (error) {
NSLog(@"Something went wrong: %@", error.localizedDescription);
} else {
NSLog(@"Got session: %@", session.key.identifier);
}
}]; // Starting/stopping the service.
- (void)startSharing {
[self.session startListeningForUpdates];
[self.session startPostingLocationUpdates];
}
- (void)stopSharing {
[self.session stopListeningForUpdates];
[self.session stopPostingLocationUpdates];
}
// Adopts the MRSharingSessionDelegate protocol to receive callbacks.
- (void)sharingSession:(MRSharingSession *)session friendsDidUpdate:(NSArray *)friends {
// The friends array has the latest location sharing data for each friend.
}
- (void)sharingSession:(MRSharingSession *)session didFailWithError:(NSError *)error {
NSLog(@"Sharing session error: %@", error.localizedDescription);
}The MRInvite class is used to create, retrieve, and accept invitations.
Invitations expire after 7 days.
// Creates invitations.
[MRInvite createInviteWithSession:self.session completion:^(MRInvite * _Nullable invite, NSError * _Nullable error) {
if (error) {
NSLog(@"Something went wrong: %@", error.localizedDescription);
} else {
NSLog(@"Invitation URL: %@", invite.shareURL);
}
}];
// Retrieves invitations.
[MRInvite getAllInvitesWithSession:self.session completion:^(NSArray *invites, NSError *error){
if (error) {
NSLog(@"Something went wrong: %@", error.localizedDescription);
} else {
NSLog(@"Got %lu invitations", (unsigned long)invites.count);
}
}];
// Accepts another user's invitation.
NSURL *inviteURL = someValidShareURL;
[MRInvite acceptInviteWithURL:someValidShareURL session:self.session completion:^(MRFriend * _Nullable friend, NSError * _Nullable error) {
if (error) {
NSLog(@"Something went wrong: %@", error.localizedDescription);
} else {
NSLog(@"Now sharing locations with %@", friend.firstName);
}
}];Use the MRFriend class to load the details for a location sharing user, get a list of the user’s friends, and more.
// Gets a user's profile.
[MRFriend getFriendWithKey:self.session.key session:self.session completion:^(MRFriend * _Nullable friend, NSError * _Nullable error) {
if (error) {
NSLog(@"Something went wrong: %@", error.localizedDescription);
} else {
NSLog(@"Got data for %@", friend.firstName);
// Updates a user's profile.
[friend updateFirstName:@"Morgan" lastName:@"Smith" withSession:self.session completion:^(MRFriend * _Nullable friend, NSError * _Nullable error) {
if (error) {
NSLog(@"failed to update profile: %@", error);
} else {
NSLog(@"profile updated successfully");
}
}];
}
} // Gets a list of a user's friends.
[MRFriend getAllFriendsWithSession:self.session completion:^(NSArray * _Nullable friends, NSError * _Nullable error) {
if (error) {
NSLog(@"Something went wrong: %@", error.localizedDescription);
} else {
NSLog(@"Got %lu friends", (unsigned long)friends.count);
}
}];