iOS API

The iOS API allows user to send and receive real-time messages via the PushFYI server. The iOS API use NSInputStream and NSOutputStream to connect to PushFYI and exchange real-time messages.

The iOS API has three main functions in addition to one helper function. In this documentation we will examine the API usage and some of the best practices.

init()

The init method allows user to connect with PushFYI to send and receive real-time messages. It is important for a user application to first connect to PushFYI prior to sending or receiving any real-time messages. Hence, this must be the first method that your client application will call in order to use PushFYI real-time transport.

This PushFYI init method is invoked by calling the PushFYI class interface.

Parameter List:

SN parameters note
1 appsecret This parameter identifies your App when it connects to PushFYI. Since PushFYI can serve real-time messages to many apps simultaneously. This field allows PushFYI to distinguish between Apps, so that real-time messages from one App do not mix up with another App. The value of appsecret parameter is in UUID format. e.g. 123e4567-e89b-12d3-a456-426655440000
2 address URL of your pushfyi instance. e.g. ws://10.0.0.101 for plain text connection and wss://10.0.0.101 for secure connection.
3 secure This parameter identifies your connection with PushFYI to check if it's secure.

Code Sample:


mPushFyi =[PushFYI alloc];
mPushFyi init:<your secret key> address: "ws://<your pushfyi ip address>" issecure:<true/false>];

subscribe

The subscribe method allows user to register their interest in a given data channel. PushFYI data channels are logical names to which real-time messages are sent and received. Once the connection is established using the init method, your application can make a call to subscribe method to show interest in a specified data channel.

Parameter List:

SN parameters note
1 channel The logical name of the data channel associated with an event.
2 callback A callback function to call when the API receives an event with a given data channel. It returns channel name and data in payload.

Code Sample:


MessageChannel *msg = [[MessageChannel alloc] init];
id <Subscription> channeMSG=[mPushFyi subscribe:subscribeChannelName];
[channeMSG bind:msg]; callback function -(void)onSubscriptionEvent:(NSString *)channel payload:(NSString*) payload { }

publish

The publish method allows user to publish a real-time message on a given data channel. PushFYI data channels are logical names to which real-time messages are sent and received. Once the connection is established using the init method, your application can make a call to publish method to send a real-time message on the specified data channel.

Parameter List:

SN parameters note
1 channel The logical name of the data channel associated with an event.
2 payload json string as template argument.

Code Sample:


NSString *payload =[NSString stringWithFormat:@"[{\"username\":\"Henry\",\"message\":\"Hi, how are you ?\"}]"];

[mPushFyi publish:payload channel:@"my_data_channel"];

on()

The PushFYI iOS on method allows you to receive connection callbacks from the API.

Parameter List:

SN parameters note
1 callbacks The internal connection event that may occur. This Parameter can have 3 values "connecting","connected" or "disconnected".

Code Sample:


mConnectionEvents= [[PushFYIEventsViewController alloc]init];

[mPushFyi on:mConnectionEvents];