【问题标题】:User list for pubnub-chat objective cpubnub-chat 目标 c 的用户列表
【发布时间】:2016-08-10 03:03:48
【问题描述】:

我有使用 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];
                                }
                            }];

    }

【问题讨论】:

    标签: ios objective-c ios9 chat pubnub


    【解决方案1】:

    PubNub 现在在此处显示状态

    您需要使用withVerbosity:PNHereNowState 调用hereNowForChannel 以获取用户的状态以及所有订阅用户。

    Objective-C SDK API Reference Docs for hereNowForChannel 有更多详细信息。

    【讨论】:

    • 感谢您的回复。我曾尝试在模拟中通过代码执行。 1)我订阅频道:XXX 并执行它给我 result.data.uuids = 0 列表的代码 2)我订阅频道:YYY 并执行它给我 result.data.uuids 列表的代码= 0. 我必须在设备中执行代码吗?这个计数是否只给我处于 PRESENCE 模式的用户?请解释
    • 您是否在 PubNub 帐户仪表板中为您的密钥启用了状态?
    • [self.client subscribeToChannels: @[@"XXX"] withPresence:YES];和 [self.client subscribeToChannels: @[@"YYY"] withPresence:YES]; :- 我在代码中添加了这一行此外,订阅密钥和公钥对于整个项目将始终是唯一的?
    • 您的 PubNub 帐户中的 Presence 插件必须启用。 pubnub.com/knowledge-base/discussion/644/…你为你的钥匙做了这个吗?
    • [self.client subscribeToChannels: @[@"XXX"] withPresence:YES];和 [self.client subscribeToChannels: @[@"YYY"] withPresence:YES]; :- 我在代码中添加了这些行。此外 Presence:YES 在仪表板中启用,并且仪表板显示相同键的 2 个设备。所以这两个设备意味着会有两个通道,但“herenowforchannel”显示 0 个计数
    【解决方案2】:

    查看代码,如果您始终将 UUID 设置为 @"XXX",您将永远只有 1 个用户。 PubNub 的 Presence 插件使用 UUID 属性来跟踪频道上的活跃用户,如果您只使用 1 个 UUID,PubNub 会将每个客户端视为同一个客户端。

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

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

    【讨论】:

    • 这意味着我们总是必须将 UUID 保存在设备本地存储中,而不是每次都分配 UUID?
    • 但是我怎样才能获得不同的 UUID 并获得所有其他 UUID 的列表和频道名称?通过使用“hereNowForChannel”,我没有得到任何 UUID 列表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    相关资源
    最近更新 更多