Location Sharing (iOS SDK) Follow
This article describes how to implement location sharing using the iOS SDK.
Location Sharing
Location sharing is a new Meridian feature that lets users share their location with each other.
Prerequisites
Location Sharing needs to be enabled by an admin in the Meridian Editor before you can use it in the SDK. If you’d like to enable Location Sharing, please email hpe-aruba-meridian@hpe.com.
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];
MRSharingSession
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.
Create an Account
// 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 In
// 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); } }];
Start and Stop Location Sharing
// 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); }
MRInvite
The MRInvite
class is used to create, retrieve, and accept invitations.
Invitations expire after 7 days.
Create and Retrieve Invitations
// 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); } }];
MRFriend
Use the MRFriend
class to load the details for a location sharing user, get a list of the user’s friends, and more.
Get a User’s Profile
// 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"); } }]; } }
Get a List of Friends
// 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); } }];
Comments
0 comments
Please sign in to leave a comment.