User list for pubnub-chat objective c

余生长醉 提交于 2019-12-13 02:26:46

问题


I have application where pubnub chat feature is been used. I want to perform below feature

1)register / login user in pubnub programatically for chat
2)Get list of the all the users
3)Make friend and send 1st message to the user

I am aware about how to create the channel. I had created channel by below code :

    PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"pub-c-XXXXXXXXXXXX-a2bf-XXXX-XXXX-XXXXXXXXXXXX"subscribeKey:@"sub-c-XXXXXXXXXXXX-02d0-XXXX-XXXX-XXXXXXXXXXXX"];
        self.client = [PubNub clientWithConfiguration:configuration];
        //[self.client addListener:self];
        [self.client subscribeToChannels: @[@"my_channel"] withPresence:YES];


I get the channel architecture by : http://pubnub.github.io/pubnub-design-patterns/2015/03/05/Inbound-Channel-Pattern.html
But how do i get the list of the users and their channel and send the message.


I  also found this : https://www.pubnub.com/docs/ios-objective-c/presence-sdk-v4
but this only show the friends status. whether they are online / offline by 

    Join
    leave 
    timeout

Please advice and help

Code to find the list of the users are below but still is show the ZERO users:

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"pub-c-XXXXXXXXXXXX-a2bf-XXXX-XXXX-XXXXXXXXXXXX"subscribeKey:@"sub-c-XXXXXXXXXXXX-02d0-XXXX-XXXX-XXXXXXXXXXXX"];
        self.client = [PubNub clientWithConfiguration:configuration];
        //Subscription process results arrive to listener which should adopt to PNObjectEventListener protocol and registered using:
        [self.client addListener:self];

        //Listeners callbacks:
        [self.client subscribeToChannels: @[@"XXX"] withPresence:YES];
        configuration.uuid = @"XXX";
        [self.client hereNowForChannel:@"XXX" withVerbosity:PNHereNowState
                            completion:^(PNPresenceChannelHereNowResult *result,
                                         PNErrorStatus *status) {

                                // Check whether request successfully completed or not.
                                if (!status.isError) {
                                    NSLog(@"list of users %@", result.data.uuids);
                                    NSLog(@"list of result.data.occupancy %@", result.data.occupancy);

                                    //   result.data.uuids - dictionary with active subscriber. Each entry will have next
                                    //                       fields: "uuid" - identifier and "state" if it has been provided.
                                    //   result.data.occupancy - total number of active subscribers.
                                }
                                // Request processing failed.
                                else {
                                    NSLog(@"FAIL");
                                    // Handle presence audit error. Check 'category' property to find
                                    // out possible issue because of which request did fail.
                                    //
                                    // Request can be resent using: [status retry];
                                }
                            }];

    }

回答1:


PubNub Here Now with State

You need to call hereNowForChannel with withVerbosity:PNHereNowState to get the user's state along with all the subscribed users.

The Objective-C SDK API Reference Docs for hereNowForChannel has more details.




回答2:


Looking at the code, if you always set the UUID to @"XXX" you will only ever have 1 user. The Presence add-on for PubNub uses the UUID property to track active users on a channel, and if you only use 1 UUID PubNub will treat every client as the same client.

Here is our knowledge base article on setting the UUID https://www.pubnub.com/knowledge-base/discussion/138/how-do-i-set-the-uuid

Also, the iOS PubNub SDK will create and reuse the UUID automatically. This is a new feature as of the 4.2 sdk. https://www.pubnub.com/docs/ios-objective-c/api-reference-sdk-v4#uuid_example_2



来源:https://stackoverflow.com/questions/36692906/user-list-for-pubnub-chat-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!