Question

i'm making my first app with pubnub for iOS. I am able to send a message and is working fine. However im having problems to know which user is the one that send the message.

I am receiving the message with this code

- (void)pubnubClient:(PubNub *)client didReceiveMessage:(PNMessage *)message {
NSLog( @"Mensaje:%@ Canal:%@ %@", message.message, message.channel.name, message.description);

But i dont know how to retrieve from this method the UUID or client identifier who send the message.

Any ideas?

Thanks in advance. Sorry for my bad english

Was it helpful?

Solution

Had the same problem yesterday, what I did was to send in the message a dictionary and not as a single string. For example :

NSDictionary *message = @{kSenderName:user.username,kSenderId:user.objectId,kReciverId:objectId,kReciver:recover.username, kMessage:@"here goes the message itself"};

and then send -

[PubNub sendMessage: message toChannel:self.groupChannel withCompletionBlock:^(PNMessageState state, id obj) {

    }];

And on the receiving side -

    NSString *senderId = message.message[kSenderId];
    NSString *senderName = message.message[kSenderName];
    NSString *messageText = message.message[kMessage];

BTW, this way you can add important Meta-Data to your messages for more complicated scenarios.

Good Luck

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