SimpleSample-location users-ios

Ask tech team
From QuickBlox Developers (API docs, code samples, SDK)
Jump to: navigation, search

Contents

Sources

Project homepage on GIT — https://github.com/QuickBlox/quickblox-ios-sdk/tree/master/sample-location

Download ZIP - https://github.com/QuickBlox/quickblox-ios-sdk/archive/master.zip


Overview

This sample demonstrates how to work with the QuickBlox Location API.
It allows you to see other users on the Map and share your own position.

It shows you how to:

  1. Retrieve all users' points & add them to the Map
  2. Share your own location



Guide: Getting Started with Location API

Getting a QuickBlox account

http://admin.quickblox.com/register

Creating an application on the Admin panel

http://admin.quickblox.com/apps/new

For further reading there is also this 5 minute guide.

Connecting QuickBlox to your application

To get the information on how to connect to the QuickBlox.framework, please, refer to the IOS-how-to-connect-Quickblox-framework page.

Adding Location features to your application

Check-in

In order to check-in you must be logged in to act on the user's behalf - please refer to iOS Users API documentation.

Just use this code snippet below if you want to check-in to somewhere:

QBLGeoData *geodata = [QBLGeoData geoData];
 
// place coordinates
geodata.latitude = 23.2344;
geodata.longitude = -12.23523;
geodata.status = @"I'am at QuickBlox house!";
 
[QBRequest createGeoData:currentGeoData
            successBlock:^(QBResponse *response, QBLGeoData *geoData) {
                // Geodata created successfully
            } errorBlock:^(QBResponse *response) {
                // Handle error
            }];

After that other users will be able to see your position.

Check-in with push to near users

You can checkin and notify all users who are near you with push notification:

QBLGeoData *geodata = [QBLGeoData geoData];
geodata.latitude = 23.2344;
geodata.longitude = -12.23523;
geodata.status = @"I'am at QuickBlox house!";
 
[QBLocation createGeoData:geodata andSendPushWithText:@"User Bob is near you" toAllUsersWithinRadius:100 delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Check-in result
    if(result.success && [result isKindOfClass:QBLGeoDataResult.class]){
        QBLGeoDataResult *checkinResult = (QBLGeoDataResult *)result;
        NSLog(@"Your checkin: %@", checkinResult.geoData);
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}

After that other users will be able to see your position.

Retrieving checkins

Through filters

There are lots of filters & options that you can use to retrieve checkins. Follow QBLGeoDataGetRequest class documentation, which describes all posible options.

For example, let's retrieve the last 100 checkins, only the last user's checkin, with statuses, sorted by the createdAt field:

[QBRequest geoDataWithFilter:filter page:[QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:70]
                successBlock:^(QBResponse *response, NSArray *objects, QBGeneralResponsePage *page) {
    // Successful response with page information and geodata array
} errorBlock:^(QBResponse *response) {
    // Handle error
}];

Through ID

You can also retrieve particular checkins through their ID:

[QBRequest geoDataWithId:543 successBlock:^(QBResponse *response, QBLGeoData *geoData) {
    // Successful response with geodata
} errorBlock:^(QBResponse *response) {
    // Handle error
}];

Update checkin

If you want to update one of your checkins - just use this code snippet below:

QBLGeoData *geodata = [QBLGeoData geoData];
geodata.ID = 34638;
geodata.latitude = 13.2344;
geodata.longitude = -42.23523;
geodata.status = @"I'am at Pizzzza house!";
 
[QBRequest updateGeoData:geodata successBlock:^(QBResponse *response, QBLGeoData *geoData) {
    // Successful response with page information and geodata array
} errorBlock:^(QBResponse *response) {
    // Handle error
}];

Delete checkin

There are 2 ways to delete checkins:

  • Deleting a particular checkin by ID
  • Deleting checkins that were created in a period of the last n days

Through ID

[QBRequest deleteGeoDataWithID:11300 successBlock:^(QBResponse *response) {
    // Successful response
} errorBlock:^(QBResponse *response) {
    // Handle error
}];

Mass delete

[QBRequest deleteGeoDataWithID:5 successBlock:^(QBResponse *response) {
    // Successful response
} errorBlock:^(QBResponse *response) {
    // Handle error
}];

Comments

Feel free to comment on this page using the form below.

blog comments powered by Disqus