Question

I am trying to setup a two person chat with PubNub. I am having trouble differentiating between the clients.

I signed up for Presence in the admin console and have enabled the feature like this:

[PubNub subscribeOnChannel:[PNChannel channelWithName:@"my_channel" shouldObservePresence:YES]];

I have an observer setup like this:

[[PNObservationCenter defaultCenter] addMessageReceiveObserver:self withBlock:^(PNMessage *message) {
           //identification code here
}];

I know the PNMessage contains the channel and message content but how do I get the clientIdentifier of the device that sent a message received?

Was it helpful?

Solution

According their docs and iOS SDK repo which is here: https://github.com/pubnub/objective-c/tree/master/iOS#publishing-messages

Messages can be an instance of one of the following classed: NSString, NSNumber, NSArray, NSDictionary, or NSNull.

You can send other object types as the message (rather than just a string as you are doing). You can simply send a dictionary object with a senderID key that the subscribers can then read.

OTHER TIPS

If you want to use an observer for Presence events, here is an example of using addPresenceEventObserver:withBlock:

https://github.com/pubnub/objective-c/blob/master/iOS/HOWTO/SimpleSubscribe/PubNubDemo/ViewController.m#L39

to log UUIDs, (also know as the client identifier):

https://github.com/pubnub/objective-c/blob/master/iOS/HOWTO/SimpleSubscribe/PubNubDemo/ViewController.m#L52

Is this what you are trying to do?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top