SuperSample iOS
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.
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.
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.
Messages
User can send push message to other users using Messages module.
Settings
From Settings screen user can sign up and sign in using Users module.
User can set own avatar using Content module. All the avatars are stored on QuickBlox servers.
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:
- register account in admin.quickblox.com
- create application in admin panel (admin.quickblox.com) on your account. In application you can see:
- Auth key
- Auth secret
- Application id
- Account owner id
- create empty iOS application.
- download and connect QuickBlox iOS framework
- copy or create file QBConsts.h to your project
- import QBConsts.h file in any other files
- in file QBConsts.h paste to field appID, ownerID, appKey, appSecret your values from step 2
- then you can start developing your own application!
- Note: if you want to use Messages module, you must:
- create APNS certificates and upload them to admin panel - please use this tutorial
- use valid Provisioning Profiles for your project
Basic usage
Basic setup
In QuickBlox iOS framework there are some main classes:
- QBSettings - main class for setup framework.
- QBUsersService - main class to interact with Users module
- QBLocationService - main class to interact with Location module
- QBMessagesService - main class to interact with Messages module
- QBBlobsService - 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:
[QBAuthService authorizeAppId:appID key:authKey secret:authSecret delegate:self];
Perform query
All the queries are performed asynchronously.
For perform queries you must realize ActionStatusDelegate protocol in your class:
@interface RegistrationViewController <ActionStatusDelegate> { ... } ... -(void)completedWithResult:(Result*)result{ [self completedWithResult:result context:nil]; } -(void)completedWithResult:(Result*)result context:(void*)contextInfo{ // 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 alloc] init]; user.ownerID = ownerID; user.password = password.text; user.login = userName.text; [QBUsersService createUser:user delegate:self context:nil]; [user release]; ... -(void)completedWithResult:(Result*)result{ [self completedWithResult:result context:nil]; } -(void)completedWithResult:(Result *)result context:(void *)contextInfo{ if([result isKindOfClass:[QBUUserResult class]]){ QBUUserResult *res = (QBUUserResult *)result; if(res.success){ NSLog(@"Registration successful."); }else{ NSLog(@"errors=%@", result.errors); } } }
- User authentication.
QBUUser *qbUser = [[QBUUser alloc] init]; qbUser.ownerID = ownerID; qbUser.login = login.text; qbUser.password = password.text; // authenticate [QBUsersService authenticateUser:qbUser delegate:self context:nil]; [qbUser release]; ... -(void)completedWithResult:(Result*)result{ [self completedWithResult:result context:nil]; } -(void)completedWithResult:(Result *)result context:(void*)contextInfo{ if([result isKindOfClass:[QBUUserAuthenticateResult class]]){ QBUUserAuthenticateResult *res = (QBUUserAuthenticateResult *)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 alloc] init]; user.ID = currentUserID; user.fullName = fullName.text; [QBUsersService editUser:user delegate:self]; [user release]; .. - (void)completedWithResult:(Result*)result{ if([result isKindOfClass:[QBUUserResult class]]){ QBUUserResult* res = (QBUUserResult*)result; if(res.success){ NSLog(@"Edit user successful"); }else{ NSLog(@"errors=%@", result.answer.errors); } } }
- Remove User's session (logout).
[QBUsersService logoutUser:nil];
Location module
In SuperSample we use 2 main operations within the Location module:
- Post your current location
- (void)startTrackOwnLocation{ [[QBLocationDataSource instance] setCallbackSelectorForLocationUpdate:@selector(didUpdateToLocation:fromLocation:) forTarget:self]; [[[QBLocationDataSource instance] locationManager] startUpdatingLocation]; } - (void)stopTrackOwnLocation{ [[QBLocationDataSource instance] setCallbackSelectorForLocationUpdate:nil forTarget:nil]; [[[QBLocationDataSource instance] locationManager] stopUpdatingLocation]; } - (void)didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ NSLog(@"Location didUpdate from %@ to %@", oldLocation, newLocation); QBLGeoData *geoData = [[QBLGeoData alloc] init]; geoData.status = @"I'm here!"; geoData.latitude = newLocation.coordinate.latitude; geoData.longitude = newLocation.coordinate.longitude; [QBLocationService postGeoData:geoData delegate:self]; [geoData release]; }
- Get current & previous own location and location of other users
QBLGeoDataSearchRequest *searchRequest = [[QBLGeoDataSearchRequest alloc] init]; searchRequest.last_only = YES; // only last point of each user searchRequest.perPage = 15; [QBLocationService findGeoData:searchRequest delegate:self]; [searchRequest release]; ... - (void)completedWithResult:(Result *)result{ if(result.success){ if([result isKindOfClass:[QBLGeoDataSearchResult class]]){ QBLGeoDataSearchResult *geoDataSearchRes = (QBLGeoDataSearchResult *)result; NSLog(@"deodata=%@", geoDataSearchRes.geodatas); } } }
Messages module
In SuperSample we use 2 main operations within the Messages module:
- Register user as subscriber
QBUUser *user = [[QBUUser alloc] init]; user.ID = 123; QBCDevice *device = [[QBCDevice alloc] initWithCurrentDevice]; [QBMessagesService TRegisterSubscriberForUser:user device:device delegate:self];
- 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 [QBMessagesService TSendPush:message toUser:435 delegate:self]; [message release]; ... - (void)completedWithResult:(Result*)result{ // Edit User result if([result isKindOfClass:[QBMSendPushTaskResult class]]){ if(result.success){
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











