iOS Small Talks: PubNub – Solution for the Real-time Communication

iOS Small Talks: PubNub – Solution for the Real-time Communication
We encounter applications running in real time pretty much everywhere. Any chat or a game uses this technology. Creating communication that is based on the assumption that what is happening in reality should be immediately reflected in the application, is unfortunately neither easy nor cheap. However for small applications we don't need to spend huge money on dedicated infrastructure. PubNub can help us.

How to use PubNub?

We encounter applications running in real time pretty much everywhere. Any chat or a game uses this technology. Creating communication that is based on the assumption that what is happening in reality should be immediately reflected in the application, it is unfortunately neither easy nor cheap. However for small applications we don’t need to spend huge money on dedicated infrastructure. PubNub can help us.

PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"holdapp_demo" subscribeKey:@"holdapp_demo"];
self.client = [PubNub clientWithConfiguration:configuration];
[self.client addListener:self];

where:

@interface ViewController () <PNObjectEventListener>
@property (strong, nonatomic) PubNub *client;
@end

To receive messages incoming to a given channel, we need to subscribe to it, first.

[self.client subscribeToChannels: @[@”holdapp_test_channel”] withPresence:YES];

Now we can go to sending messages. Any valid JSON with a maximum size of 32Kb can be a message.

NSString *message = [NSString stringWithFormat: @"Message:%@" ,self.messageTextField.text];
[self.client publish: @{@"message": message} toChannel:@”holdapp_test_channel” withCompletion:^(PNPublishStatus *status) {}];

Receiving messages is possible after implementing methods of the PNObjectEventListener protocol, as presented in the example project.

The whole process of posting and receiving messages is very simple.

We don’t need to create a specific channel. Sending messages to a given channel is all we have to do. All devices that subscribed to a particular channel will receive our message.

In addition to basic sending and receiving messages, we have access to many other interesting functions, such as:

  • keeping track of online statuses of specific users,
  • accessing history of posted messages,
  • Access Manager, which provides security of data exchange,
  • sending push notifications,
  • Stream Controller, facilitating managing thousands of channels,
  • Analytics.

PubNub provides SDK for dozens of platforms, including iOS and Android. For those interested in creating an application, there was published a series of tutorials named University of PubNub. They are useful to both beginner developers and those who want to build a complex application.

The advantage of PubNub is that if our application doesn’t exceed 100 users per day or 100 million sent messages per month, we can access all extras for free. Unfortunately, this condition is met only by small applications and exceeding these numbers posts substantial costs.

 

Integrating PubNub with an application is totally simple. Having written a few lines of code, we can send and receive messages in real time, and communication process is being performed really fast. If you want to try to create an application running in real time, PubNub is an option worth considering.

Learn more

Bitrise Tests Made Easier: Update JIRA Issues with Build Number and Forget About Delays in QA Testing

When you trigger Bitrise build with changes and forget to tell QA specialists some essential information, there are two likely scenarios. You waste time waiting for the update from the tester, only you don’t know it’s never coming. Or you get so many questions about builds that you can’t keep up. Sounds familiar? If so, let us tell you about the JIRA issue update that keeps workflow in order.
Read more

How to Send iOS Notifications in Different Languages? Guide to Dynamic Localization

The best way to set a connection between a user, provider, and an app? System notifications. They allow users to get the latest news in no time. This solution is easy to implement in apps dedicated to one market. But it gets complicated when the messages must be displayed in many languages. In such cases, the dynamic localization of remote notifications can be a real game-changer.
Read more

WebSockets on iOS – Real-time Communication That Doesn’t Slow Down the App

When you want to download data for the app, you probably use API RESTful interface. All it takes is to ask the server for the data and that's it! This method works well when the app doesn't need permanent access to new information. But what to do if the content has to be updated in real-time? A delay can make it impossible for the user to buy an item or make a sports bet, for example. But there’s a solution – WebSockets on iOS. Check out why you should implement them, and how to do it.
Read more

Project estimation

Check out how we use our knowledge in practice, and make your project with us.

Why choose us?

Logo Mobile Trends Awards

Mobile Trends Awards 2017

Nomination in
M-COMMERCE category

17

client reviews

Clutch logo
Logo Legalni bukmacherzy

Legal Bookmakers Award 2019

Best Mobile App

60+

projects in portfolio