SuperSample iOS

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

IOS-SS4.png

This is a complex sample of an iOS application using QuickBlox. The application uses the modules Chat, Content, Location, Users and Messages. Using this application, the user can see other users on the map. Users can use Chat to communicate with each other.

Contents

Start

At start user can see the splash screen.

IOS-SS-Splash-screen-5.22.40-PM.png

Map

After splash screen, the user can see a Map screen. The red marker shows your current location, the blue marker represents other users of the application.

Tapping on a marker — creates a popup with additional information displayed on the screen.

IOS-Simulator-Screen-shot-Dec-17-2011-3.24.16-PM.png  IOS-SS-User-Map-info.png

Chat

Users can communicate with other users through Chat (Chat over Map). The last user's message is displayed as a popup on the Map.

IOS-Simulator-Screen-shot-Dec-17-2011-3.231.png  IOS-Simulator-Screen-shot-Dec-17-2011-3.271.png

Messages

User can send push message to other users using Messages module.

IOS-SS-User-Map-info.pngIOS-SS-Messages.pngIOS-SS-Push.png

Settings

From Settings screen user can sign up and sign in using Users module.

IOS-SS-Sign-up.png  IOS-SS-FB-auth.png

User can set own avatar using Content module. All the avatars are stored on QuickBlox servers.

IOS-Simulator-Screen-shot-Dec-17-2011-3.24.png  IOS-Simulator-Screen-shot-Dec-17-2011-3.28.png

For developers

Code structure

Project contains the following groups:

  • Business

This group contains all the logic and models for working with data in application. It contains Data Model, Data Providers, Data Source, Data Storage, Models group.
We use iOS Core Data to store all the data (Users, Chat Messages, Avatars...) in application.

  • Definitions

This group contains all the constants (constants, enums, 'define' directives)

  • GUI

This group contains all the controllers and views.

  • Helpers

This group contains helper classes.

Project setup

First, if you want to develop your own application, You must do these steps:

  1. register account in admin.quickblox.com
  2. create application in admin panel (admin.quickblox.com) on your account. In application you can see:
    1. Authorization key
    2. Authorization secret
    3. Application id
  3. create empty iOS application.
  4. download and connect QuickBlox iOS framework
  5. put to AppDelegate next lines (get those params form step 2):
    1. [QBSettings setApplicationID:applicationID];
    2. [QBSettings setAuthorizationKey:authorizationKey];
    3. [QBSettings setAuthorizationSecret:authorizationSecret];
  6. then you can start developing your own application!
  7. Note: if you want to use Messages module, you must:
    1. create APNS certificates and upload them to admin panel - please use this tutorial
    2. use valid Provisioning Profiles for your project

Basic usage

Basic setup

In QuickBlox iOS framework there are some main classes:

  1. QBSettings - main class for setup framework.
  2. QBUsers - main class to interact with Users module
  3. QBLocation - main class to interact with Location module
  4. QBMessages - main class to interact with Messages module
  5. QBContent - main class to interact with Content module

Before using QuickBlox iOS framework you must do the following:

  • Application Authorization

First, before work with QuickBlox you must authorize your application:

[QBAuth createSessionWithDelegate:self];

Perform query

All the queries are performed asynchronously.

For perform queries you must realize QBActionStatusDelegate protocol in your class:

@interface RegistrationViewController <QBActionStatusDelegate> {
     ...
}
 
 
...
 
 
-(void)completedWithResult:(Result*)result{
     // do something with result
}

Introduction to QuickBlox modules. How to use it.

Users module

In SuperSample we use 4 main operations within the Users module:

  • Create new User (registration).
QBUUser *user = [QBUUser user];   
user.password = password.text;
user.login = userName.text;
 
[QBUsers signUp delegate:self context:nil];
 
...
 
 
-(void)completedWithResult:(Result*)result{
	if([result isKindOfClass:[QBUUserResult class]]){
		QBUUserResult *res = (QBUUserResult *)result;
 
		if(res.success){
		    NSLog(@"Registration successful.");
		}else{
	            NSLog(@"errors=%@", result.errors);
		}
	}	
}
  • User authentication.
// Authenticate user
[QBUsers logInWithUserLogin:login.text password:password.text delegate:self];
 
...
 
 
-(void)completedWithResult:(Result*)result{
	if([result isKindOfClass:[QBUUserLogInResult class]]){
		QBUUserLogInResult *res = (QBUUserLogInResult *)result;
		if(res.success){
                      NSLog(@"Authentication successful");
		}else if(401 == result.status){
		    NSLog(@"Not registered!");
		}else{
	            NSLog(@"errors=%@", result.errors);
		}
	}
}
  • Editing User.
QBUUser *user = [QBUUser user];
user.ID = currentUserID;
user.fullName = fullName.text;
 
[QBUsers updateUser:user delegate:self];
 
..
 
 
- (void)completedWithResult:(Result*)result{
    if([result isKindOfClass:[QBUUserResult class]]){
        QBUUserResult* res = (QBUUserResult*)result;
        if(res.success){
            NSLog(@"Edit user successful");
        }else{
            NSLog(@"errors=%@", result.errors);
        }
    }
}
  • Remove User's session (logout).
[QBUsers logOutWithDelegate:self];
 
...
 
 
-(void)completedWithResult:(Result*)result{
	if([result isKindOfClass:[QBUUserLogOutResult class]]){
		QBUUserLogOutResult *res = (QBUUserLogOutResult *)result;
 
		if(res.success){
		    NSLog(@"LogOut successful.");
		}else{
	            NSLog(@"errors=%@", result.errors);
		}
	}	
}

Location module

In SuperSample we use 2 main operations within the Location module:

  • Post your current location
QBLGeoData *geoData = [QBLGeoData geoData];
geoData.status = @"I'm here!";
geoData.latitude = 34.34342343;
geoData.longitude = 12.78234749;
 
[QBLocation createGeoData:geoData delegate:self];
 
...
 
- (void)completedWithResult:(Result *)result{
    if(result.success){
        if([result isKindOfClass:[QBLGeoDataResult class]]){
	    QBLGeoDataResult *geoDataRes = (QBLGeoDataResult *)result;
            NSLog(@"Created geodata=%@", geoDataRes.geodata);
        }
    }
}
  • Get current & previous own location and location of other users
QBLGeoDataGetRequest *getRequest = [[QBLGeoDataGetRequest alloc] init];
searchRequest.lastOnly = YES; // only last point of each user
searchRequest.perPage = 15; // last 15 points
 
[QBLocation geoDataWithRequest:getRequest delegate:self];
 
[getRequest release];
 
 
...
 
 
- (void)completedWithResult:(Result *)result{
    if(result.success){
        if([result isKindOfClass:[QBLGeoDataPagedResult class]]){
	    QBLGeoDataPagedResult *geoDataRes = (QBLGeoDataPagedResult *)result;
            NSLog(@"Array of geodata=%@", geoDataRes.geodata);
        }
    }
}

Messages module

In SuperSample we use 2 main operations within the Messages module:

  • Register user for receive push notifications
[QBMessages TRegisterSubscriptionWithDelegate:self];
 
...
 
 
- (void)completedWithResult:(Result*)result{
 
    // Register user as subscriber result
    if([result isKindOfClass:[QBMRegisterSubscriptionTaskResult class]]){
        if(result.success){
           // do something
        }
    }
}
  • Send push message
NSString *mesage = @"QB SuperSample. Message from Garry: Hello man!"];
 
NSMutableDictionary *payload = [NSMutableDictionary dictionary];
NSMutableDictionary *aps = [NSMutableDictionary dictionary];
[aps setObject:@"default" forKey:QBMPushMessageSoundKey];
[aps setObject:mesage forKey:QBMPushMessageAlertKey];
[payload setObject:aps forKey:QBMPushMessageApsKey];
 
QBMPushMessage *message = [[QBMPushMessage alloc] initWithPayload:payload];
 
// Send push
[QBMessages TSendPush:message toUsers:@"234,567" isDevelopmentEnvironment:YES delegate:self];
 
[message release];
 
 
...
 
 
- (void)completedWithResult:(Result*)result{
 
    // Send Push result
    if([result isKindOfClass:[QBMSendPushTaskResult class]]){
        if(result.success){
           // do something
        }
    }
}

Content module

In SuperSample we use 2 main operations within the Content module:

  • Download file
[QBContent TDownloadFileWithBlobID:12 delegate:self];
 
...
 
- (void)completedWithResult:(Result*)result{
 
    // Download file result
    if([result isKindOfClass:[QBCFileDownloadTaskResult class]]){
        if(result.success){
           QBCFileDownloadTaskResult *res = (QBCFileDownloadTaskResult *)result;
           NSData *file = res.file;
        }
    }
}
  • Upload file
NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"arrow.png"]);
[QBContent TUploadFile:imageData fileName:@"arrow.png" contentType:@"image/png" isPublic:NO delegate:self];
 
...
 
 
- (void)completedWithResult:(Result*)result{
 
    //Upload file result
    if([result isKindOfClass:[QBCFileUploadTaskResult class]]){
        if(result.success){
           // do something
        }
    }
}

Sources

Download ZIP for stable version — https://github.com/QuickBlox/SuperSample-ios/zipball/master

Project homepage on GIT — https://github.com/QuickBlox/SuperSample-ios

Clone from GIT dev version — git@github.com:QuickBlox/SuperSample-ios.git