IOS

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

Contents

Download iOS SDK

Quickblox iOS SDK, version 1.9.1


Code samples

Learn how to enable Push Notifications, create a Chat room, authenticate users via Facebook, show users' locations and POIs, store and retrieve files from the cloud - these code samples are simple enough that even novice developers will be able to understand them.

Title APIs used Description
Simple iOS VideoChat (video/audio calling) code sample Chat, The VideoChat code sample allows you to easily add video calling features into your iOS app. Enable a video call function similar to FaceTime or Skype using this code sample as a basis.


Simple iOS Chat code sample Chat, Users The Chat sample connects and socializes your users with the chat module. Features include: Peer to Peer Chat; Group chat; Location based chat; Push notifications for offline users.


iOD Swift demo application Custom Objects, Swift This is a demo application written on Apple new programming language Swift and uses QuickBlox iOS SDK

Simple iOS Custom Objects (key value data store) code sample Custom Objects This Custom Objects sample allows you to create any server side data structure, utilise it for any purpose, create any logic and many other custom features.


Simple iOS Location code sample Location, Users The Location sample connects app users with each other and their environment. Using GPS locations, map integrations and local data, end users can literally 'see' each other on the map and communicate with other users.


Simple iOS Push Notifications (Messages) code sample Messages Push notifications to your user base — even when your app is not running! This sample enables you to send notifications and alerts to users at any time through an API or easy-to-use admin panel. You can filter who you send messages to through additional parameters.


Simple iOS Users authentication (Facebook, Twitter, OAuth integration) code sample Users The Users sample helps you manage and retain your user base across all platforms. It includes a simple authentication process with Single Sign-On and integration across all popular platforms, including social integration with Twitter/Facebook


Simple iOS leaderboard / high scores / star ratings code sample Ratings High scores, leaderboards and star ratings — all made easy with the Ratings sample. Introduce an interactive ranking element to your app with this sample, with the capability to highlight user results and show nearest competitors.


Simple iOS content storage and update code sample Content The Content sample allows you to send, stream, store, share and save content, so that you may update your app's content without having to republish.



How to: add SDK to Xcode and connect to the cloud

Read tutorial.


Oh, please, please show me the code

iOS SDK is really simple to use. In just a few minutes you can power up your mobile app with huge amount of awesome communication features & data services.

The common way to interact with QuickBlox can be presented with the following sequence of actions:

  1. Initialize framework with application credentials
  2. Create session
  3. Login with existing user or register new one
  4. Perform actions with QuickBlox communication services and any data entities (users, locations, files, custom objects, pushes etc.)

Initialize framework with application credentials

[QBSettings setApplicationID:92];
[QBSettings setAuthorizationKey:@"wJHdOcQSxXQGWx5"];
[QBSettings setAuthorizationSecret:@"BTFsj7Rtt27DAmT"];
[QBSettings setAccountKey:@"7yvNe17TnjNUqDoPwfqp"];

A couple of words about Authentication and Authorization

To be able to use QuickBlox API you have to create a session.

There are 2 types of session:

  • Application session. It provides only READ access to data.
  • User session. It provides CRUD(Create, Read, Update, Delete) access to data.

To create an application session use this code:

[QBAuth createSessionWithDelegate:self];
 
- (void)completedWithResult:(Result *)result{
    if(result.success && [result isKindOfClass:QBAAuthSessionCreationResult.class]){
        // Success, You have got Application session, now READ something.
    }
}

With an Application session you can READ any data you need and only have to do one Create operation - User Sign Up:

QBUUser *user = [QBUUser user];
user.login = @"garry";
user.password = @"garry5santos";
 
[QBUsers signUp:user delegate:self];
 
- (void)completedWithResult:(Result *)result{
    if(result.success && [result isKindOfClass:QBUUserResult.class]){
        // Success, do something
        QBUUserResult *userResult = (QBUUserResult *)result;
        NSLog(@"New user=%@", userResult.user);
    }
}

To update an Application session to a User session you have to login to QuickBlox:

[QBUsers logInWithUserLogin:@"garry" password:@"garry5santos"  delegate:self];
 
- (void)completedWithResult:(Result *)result{
    if(result.success && [result isKindOfClass:QBUUserLogInResult.class]){
        // Success, do something
        QBUUserLogInResult *userResult = (QBUUserLogInResult *)result;
        NSLog(@"Logged In user=%@", userResult.user);
    }
}

Login to Chat

QBUUser *currentUser = [QBUUser user];
currentUser.ID = 2569; // your current user's ID
currentUser.password = @"garrySant88"; // your current user's password   
 
// set Chat delegate
[QBChat instance].delegate = self;
 
// login to Chat
[[QBChat instance] loginWithUser:currentUser];
 
#pragma mark -
#pragma mark QBChatDelegate
 
// Chat delegate
-(void) chatDidLogin{
    // You have successfully signed in to QuickBlox Chat
}


You can create a User session in single query as well:

QBASessionCreationRequest *extendedAuthRequest = [QBASessionCreationRequest request];
extendedAuthRequest.userLogin = @"igor.quickblox"; // ID: 218651
extendedAuthRequest.userPassword = @"qbpass22";
[QBAuth createSessionWithExtendedRequest:extendedAuthRequest delegate:self];
 
- (void)completedWithResult:(Result *)result{
    if(result.success && [result isKindOfClass:QBAAuthSessionCreationResult.class]){
        // Success, You have got User session
    }
}

A session will remain valid for 2 hours after the last request to QuickBlox was performed. To check a session's expiration date use this next snippet of code:

NSDate *sessionExpiratioDate = [QBBaseModule sharedModule].tokenExpirationDate;
NSDate *currentDate = [NSDate date];
NSTimeInterval interval = [currentDate timeIntervalSinceDate:tokenExpirationDate];
if(interval > 0){
   // recreate session here
}


Performing actions

Send Chat message

// send message
QBChatMessage *message = [QBChatMessage message];
message.recipientID = 546; // opponent's id
message.text = @"Hi mate!";
 
[[QBChat instance] sendMessage:message];
 
 
#pragma mark -
#pragma mark QBChatDelegate
 
- (void)chatDidReceiveMessage:(QBChatMessage *)message{
    NSLog(@"New message: %@", message);
}

Creating a new location for Indiana Jones

QBLGeoData *location = [QBLGeoData geoData];
location.latitude = 23.2344;
location.longitude = -12.23523;
location.status = @"Hello, world, I'm Indiana Jones, I'm at London right now!";
 
[QBLocation createGeoData:location delegate:self];
 
- (void)completedWithResult:(Result *)result{
    if(result.success && [result isKindOfClass:QBLGeoDataResult.class]){
        // Success, do something
        QBLGeoDataResult *locationResult = (QBLGeoDataResult *)result;
        NSLog(@"New location=%@", locationResult.geoData);
    }
}

To put an Image into storage

NSData *file = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"YellowStar" ofType:@"png"]];
 
[QBContent TUploadFile:file fileName:@"Great Image" contentType:@"image/png" isPublic:YES delegate:self];
 
- (void)completedWithResult:(Result *)result{
    if(result.success && [result isKindOfClass:QBCFileUploadTaskResult.class]){
        // Success, do something
    }
}
 
-(void)setProgress:(float)progress{
    NSLog(@"progress: %f", progress);
}

iOS Framework provides the following classes to interact with QuickBlox API (each class has suite of static methods):

  1. QBAuth
  2. QBUsers
  3. QBChat
  4. QBCustomObjects
  5. QBLocation
  6. QBContent
  7. QBRatings
  8. QBMessages

Performing actions with context

It's possible to perform any request to REST API with some context. Context helps you to detect a result's source.

For example, let's create 2 location checkins and detect each result:

// 1st checkin
QBLGeoData *location = [QBLGeoData geoData];
location.latitude = 23.2344;
location.longitude = -12.23523;
location.status = @"Hello, world, This is checkin number 1";
 
[QBLocation createGeoData:location delegate:self context:@"checkin1"];
 
// 2nd checkin
QBLGeoData *location = [QBLGeoData geoData];
location.latitude = 3.2344;
location.longitude = 22.23523;
location.status = @"Hello, world, This is checkin number 2";
 
[QBLocation createGeoData:location delegate:self context:@"checkin2"];
 
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result context:(void *)contextInfo{
    if(result.success && [result isKindOfClass:QBLGeoDataResult.class]){
        // Success, do something
        QBLGeoDataResult *locationResult = (QBLGeoDataResult *)result;
 
        NSString *_context = (NSString *)contextInfo;
        if([_context isEqualToString:@"checkin1"]){
            NSLog(@"This is checkin 1 %@", locationResult.geoData);
        }else{
            NSLog(@"This is checkin 2 %@", locationResult.geoData);
        }
    }
}


Read on: iOS SDK documentation (Apple style)

Full reference on classes and protocols used in QuickBlox iOS SDK:
Quickblox iOS SDK framework documentation


Framework changelog:

v1.9.1 — Jul 18, 2014

  • Remove senderID from QBChatMessage for group chat


v1.9 — Jul 17, 2014

  • Chat 2.0 API added
  • added customData field to QBUUser


v1.8.6 — May 29, 2014

  • Fixes for session recreation


v1.8.5 — May 22, 2014

  • Custom Objects:
    • fixed an issue with parser that prevented name array field in singular form
  • Content:
    • implemented upload/download file progress delegate
    • translated Blob public url to new format
  • Users:
    • added method [QBUsers usersWithExtendedRequest:filters delegate:self]
  • General:
    • Added new required settings method [QBSettings setAccountKey:@"..."]
    • integrated Endpoints API http://quickblox.com/developers/Overview#Endpoints
    • fixed social login urls for custom servers
    • removed some deprecated methods
    • removed setZone and setServerDomain methods from QBSettings
    • removed kQBVideoChatTURNServerEndPoint key from video chat settings. Added a method to QBSettings to set TURN server endpoint.


v1.8.4 — April 10, 2014
  • Location:
    • added location push notifications
v1.8.3 — April 5, 2014
  • VideoChat:
    • added Cancel call handler
    • fixes for iOS7.1
  • Users:
    • QBUUser. blobID type changed to NSInteger. Now you can unset blob_id field of user - pass blob_id=-1
  • Chat:
    • added [QBChat instance].useMutualSubscriptionForContactList to manage subscriptions mode of chat contact list
    • QBContactListItem: added subscriptionState property
    • added ability to use secureTLS connection for chat: [QBSettings useTLSForChat:YES];
  • General:
    • fixes for QBToken header when use different API domains
v1.8.2 — January 28, 2014
  • enabled HTTPS by default
  • fixed some conflicts with AFNetworking
  • changed type of property QBLGeoDataGetRequest.radius from NSUInteger to CGFloat
v1.8.1 — January 15, 2014
  • VideoChat:
    • integrated iLBC audio codec
    • updated low level audio API
v1.8 — November 27, 2013
  • VideoChat:
    • updated VideoChat API
    • added ability to manage audio route
    • fixes for iOS7, iPhone5C, iPhone5S
  • Chat:
    • added Chat-history-to-CusomObjects plugin: [message saveWhenDeliveredToCustomObjectsWithClassName:@"ChatMessage" additionalParameters:@{@"age": @22, @"type": @"actor"}];
  • Enterprise:
    • added ability to manage S3 bucket: [QBSettings setContentBucket:@"name_of_S3_bucket"]
  • Messages:
    • updated device udid in iOS7
  • General:
    • fixed social login dialog in landscape mode
    • added arm64 support
    • set iOS 5.1.1 as min version
    • renamed BaseService class to QBBaseModule, static method sharedService to sharedModule
    • replaced core network library ASIHTTPRequest with AFNetworking
    • added access to token expiration date [QBBaseModule sharedModule].tokenExpirationDate
  • Custom Objects:
    • added Files API
    • added output parameter to manage records' output fields
    • added ctn, or filters
    • added ability to delete multiple records in single query [QBCustomObjects deleteObjectsWithIDs:@[345,678] className:@"Movie" delegate:self]
    • added ability to create multiple records in single query [QBCustomObjects createObjects:@[object1, object2] className:@"Movie" delegate:self];
    • added ability to update multiple records in single query [QBCustomObjects updateObjects:@[object1, object2] className:@"Movie" delegate:self];
  • Content:
    • added ability to update blob's file [QBContent TUpdateFileWithData:file file:blob delegate:self];
v1.7.2 — September 22, 2013
  • Updates for iOS7
v1.7.1 — August 16, 2013
  • Added ability to set custom API & Chat endpoints (usually these features need for Enterprise clients): [QBSettings setServerApiDomain:@"http://api-mydomain.quickblox.com"];[QBSettings setServerChatDomain:@"chat-mydomain.quickblox.com"];
v1.7 — July 19, 2013
  • Custom Objects:
    • Permissions API
    • Added method [QBCustomObjects objectsWithClassName: IDs:] to retrieve records by ids
  • Content:
    • Improved file upload query in case with 3G connection
  • Chat:
    • Removed deprecated methods createRoomWithName: and createPrivateRoomWithName: from QBChat class
    • Added ability to join room with custom nickname: [[QBChat instance] createOrJoinRoomWithName:testRoomName nickname:@"GarryGilbert" membersOnly:NO persistent:NO];
    • Updated QBChatRoomOccupant class: replaced NSUInteger userID field with NSString *nickname
    • Added method to send presense with all it's parameters [[QBChat instance] sendPresenceWithStatus:@"PC" show:QBPresenseShowDND priority:0 customParameters:@{@"job": @"manager", @"age": @"25"} toRoom:testRoom];
  • Users:
    • added method [QBUsers usersWithTwitterIDs:] to retrieve users with twitter ids
    • added method [QBUsers usersWithFacebookIDs:] to retrieve users with facebook ids
v1.6 — July 7, 2013
  • Contact list:
    • Added ContactList API
    • Added ‘sendPresenceWithStatus’ method to QBChat to send presence with additional text
    • Added ‘sendDirectPresenceWithStatus:toUser:’ method to QBChat to send direct presence inside contact list
  • QBChatMessage model:
    • Added convenience constructor to QBChatMessage: [QBChatMessage message]
    • Changed type of QBChatMessage ID field to NSString
    • Added ability to set custom parameters to QBChatMessage
  • Group chat:
    • Added ‘sendPresenceWithParameters:toRoom:’ method to QBChat to send presence to room
    • Auto add appID to room name – http://quickblox.com/developers/Chat#Room_naming_convention
    • Updated QBChatDelegate method ‘chatRoomDidChangeOnlineUsers:room:’. Now, each object from ‘onlineUsers’ array is an instance of QBChatRoomOccupant class
  • Video chat:
    • Updated VideoChat API: now you should work with QBVideoChat object instead of QBChat
    • Added ability to make audio calls (without video)
    • Added ability to set custom AVCaptureSession for video chat
    • Added ability to set kQBVideoChatP2PTimeout
    • Added ability to manage torch during call
    • Added ability to switch camera(back, face) during call
    • Added ability to set video capture preset
    • Added ‘cancelCall’ method to QBVideoChat to cancel ‘callUser:’ method
    • Added custom parameters to methods ‘callUser:’ & ‘acceptCall’
v1.5.2 — May 11, 2013
  • removed internal access to UDID
  • Users: added method to QBUsers usersWithPhoneNumbers: - allows to retrieve users by phone numbers
  • fixed 12h datetime format issue
v1.5.1 — March 12, 2013
  • Chat: added method to QBChat requestRoomOnlineUsers: – allows to retrieve room online users
  • Chat: added isJoined property to QBChatRoom
  • Chat: Unsupported symbols now will be removed from room name. You can validate room name using [QBChat roomNameToValidRoomName:roomName]
  • Chat: added method to QBChat destroyRoom: – allows to delete room
  • VideoChat: added muteVideoChat property to QBChat - allows to mute microphone during video conference.
  • Users: added method to QBUsers usersWithLogins: - allows to retrieve users by logins
  • Users: added method to QBUsers usersWithEmails: - allows to retrieve users by emails
  • Now you can manage timeout for queries [QBSettings setTimeOutSeconds:10]
v1.5 — February 20, 2013
  • Added VideoChat API
  • QBChat: replaced method – (void)chatRoomDidEnter:(NSString *)room with – (void)chatRoomDidEnter:(QBChatRoom *)room
  • QBChatDelegate: Now you dont need to use – (void)chatRoomDidCreate:(QBChatRoom*)room. In all cases (create or join room) chatRoomDidEnter method will be called
  • QBChat: Added new method for room creation: – (void)createOrJoinRoomWithName:(NSString *)name membersOnly:(BOOL)isMembersOnly persistent:(BOOL)isPersistent. Old methods marked as deprecated.
v1.4.1 — January 9, 2013
  • Added notification when social login dialog was closed – QuickbloxSocialDialogDidCloseNotification
  • QBChatDelegate now is retained
  • Added [QBSettings useProductionEnvironmentForPushNotifications:YES] to manage Push Notifications environment
v1.4 — December 11, 2012
  • CustomObjects: added method 'objectWithClassName:ID:' to QBCustomObjects class – allows to retrieve single object
  • CustomObjects: added Array type
  • CustomObjects: added special update operators
  • CustomObjects: added relations API
  • Social API: added 'scope' param: replaced QBUsers’s method 'logInWithSocialProvider:delegate:' with 'logInWithSocialProvider:scope:delegate:'
  • Social API: now you can auth using Social provider access token
  • Chat: added method to QBChatDelegate 'chatRoomDidChangeOnlineUsers:room:'
  • Chat: added method to QBChat 'requestRoomUsers' – allows to retrieve room members
  • Users: added to QBUsers method 'usersWithIDs' – allows to retrieve users by ids
  • Users: QBUUser.tags – property type changed from NSArray to NSMutableArray
  • Messages: added methods to send push notification without environment
  • Messages: added method to class QBMessages 'TSendPushWithText' – simple way to send push – just write text & send
  • Auth: Create session with device parameters is deprecated. Now you don’t need to create session with device parameters in order to use Push Notifications
v1.3.1 — October 26, 2012
  • Now delegate is retained
  • Allow to pass any object (not only NSString) to custom object’s fields
  • New great design for the Facebook login dialog
  • Added a new method ‘createPrivateRoomWithName:(NSString *)name’ to QBChat class. It allows to create only members rooms.
v1.3.0 — October 2, 2012
  • New Chat JID format (without user's login) (http://quickblox.com/developers/Chat)
  • NSCopying, NSCoding protocols for all models are implemented
  • isEqual method for all models is implemented
  • Added a convenient constructor to class Request and all inherited classes ([Request request])
  • Added a method to Messages API for stop receive Push Notifications - [QBMessages TUnregisterSubscriptionWithDelegate:self];
  • Added a method to Messages API for sending Push Notifications to users with tags - [QBMessages TSendPush:message toUsersWithAnyOfTheseTags:@"man, car" isDevelopmentEnvironment:YES delegate:self];
  • Added a property 'enableSessionExpirationAutoHandler' to QBSettings class for enable auto handling session expiration
  • C2DM enum was renamed to GCM
  • QBMPushEvent class was renamed to QBMApplePushEvent
  • Chat API was refactored
  • SBJSON was hidden
  • Updated Content Tags API
  • iOS 6 compatibility
v1.2.0 — August 27, 2012
  • Added Custom Objects API
  • Added Content tags API
  • Social API now returns social provider's access token & token's expiration date. No you can work with FB/Twitter API without fb/twitter sdk!
v1.1.0 — August 09, 2012
  • Added Social API. Now you can authenticate through QuickBlox Users module using your Facebook/Twitter account.
  • Added 'lastRequestAt' field to QBUUser
  • Added 'blob' field to QBCFileDownloadTaskResult
  • Added Chat module snippets
v1.0.0 — July 24, 2012
  • SDK stable version
  • All API calls are covered


Comments

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

blog comments powered by Disqus