Search code examples
objective-cpubnub

Get list of online users PubNub always nil Objective C


My question is same of User list for pubnub-chat objective c but it seem has no helpful answers.

  1. I registed client with Pub & Sub key with Presence = YES
  2. I subsrcibed to "My channel" and could send msg to it
  3. I used debug console in PubNub admin to create 2 others clients, I could send msg together
  4. I enable Presence in Admin (http://prntscr.com/iyv7b1)
  5. I get list user that subscribe "My channel" by function:
[client hereNowForChannel:@"My channel" withVerbosity:PNHereNowState completion:^(PNPresenceChannelHereNowResult *result, PNErrorStatus *status)
 {
     if (!status) {

     }
     else {
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Couldn't get list of user." delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];

         [alert show];
     }
 }];

I tried to change

PNHereNowState -> PNHereNowUUID -> PNHereNowOccupancy

But my result is always NIL.

Anybode help me, pls


Solution

  • I found the answer for my question, hope it helps for who need

    [client hereNowForChannel:client.globalChannel withCompletion:^(PNPresenceChannelHereNowResult *result, PNErrorStatus *status)
     {
         if (!status) {
             PNPresenceChannelHereNowData *data = result.data;
             if (data) {
                 NSArray *list = [data uuids];
    
             }
         }
         else {
    
         }
     }];
    

    The property data, it won't be set value if has no access to it yet, so I did call PNPresenceChannelHereNowData *data = result.data; and it had data.