-->

用户列表pubnub聊天目标C(User list for pubnub-chat objectiv

2019-09-29 17:36发布

我有应用程序,其中被使用了pubnub聊天功能。 我想下面的功能执行

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

我知道如何创建的通道。 我创造通过下面的代码信道:

    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

代码找到用户低于列表中,但仍然显示零个用户:

(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];
                                }
                            }];

    }

Answer 1:

PubNub这里现在与国

你需要调用hereNowForChannelwithVerbosity:PNHereNowState与所有预订用户一起获得用户的状态。

在Objective-C的SDK API参考文档,以便hereNowForChannel有更多的细节。



Answer 2:

看代码,如果你总是设置UUID来@“XXX”,你将只拥有1个用户。 存在添加为PubNub使用UUID属性以跟踪活跃用户的频道上,如果你只使用1个UUID PubNub会对待每一个客户端为同一个客户端。

这是我们在设置UUID知识库文章https://www.pubnub.com/knowledge-base/discussion/138/how-do-i-set-the-uuid

此外,iOS的SDK PubNub会自动创建和重用UUID。 这是一项新功能为4.2 SDK的。 https://www.pubnub.com/docs/ios-objective-c/api-reference-sdk-v4#uuid_example_2



文章来源: User list for pubnub-chat objective c