【问题标题】:PNAccessDeniedCategory for sending the message in pubnub objective cPNAccessDeniedCategory 用于在 pubnub 目标 c 中发送消息
【发布时间】:2016-04-20 11:34:02
【问题描述】:

我正在尝试使用 pubnub 发送消息。 但它给了我错误:PNAccessDeniedCategory 我没有找到任何解决方案。

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

    PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"pub-c-..."subscribeKey:@"sub-c-..."];
    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: @[@"test123"] withPresence:YES];
    NSLog(@"channel-->%@",self.client.channels);
    configuration.uuid = @"test123";

}
- (void)client:(PubNub *)client didReceiveStatus:(PNSubscribeStatus *)status {

    if (status.category == PNUnexpectedDisconnectCategory) {
        // This event happens when radio / connectivity is lost
    }

    else if (status.category == PNConnectedCategory) {

        // Connect event. You can do stuff like publish, and know you'll get it.
        // Or just use the connected event to confirm you are subscribed for
        // UI / internal notifications, etc

    }
    else if (status.category == PNReconnectedCategory) {

        // Happens as part of our regular operation. This event happens when
        // radio / connectivity is lost, then regained.
    }
    else if (status.category == PNDecryptionErrorCategory) {

        // Handle messsage decryption error. Probably client configured to
        // encrypt messages and on live data feed it received plain text.
    }else if (status.category == PNAccessDeniedCategory) {
     Nslog(@"It gives me this error");

  }
}

请指教。此错误是否是因为我的帐户已过期而这就是它不允许我访问的原因? 我必须创建另一个免费帐户吗?还是必须创建新密钥? 请帮忙。

【问题讨论】:

  • 您需要使用有关错误的详细信息更新您的问题,并指出是哪一行导致它。
  • 在下面回答。我还编辑了您的代码以删除完整的 pub 和 sub 键值。你不应该向全世界广播这些。具有讽刺意味的是,除非您启用 Access Manager 并向每个用户授予显式访问权限 :) 但很可能,您需要禁用 Access Manager,直到您拥有适当的授予逻辑(见下文)。我建议禁用此密钥集并创建一个新密钥集。

标签: objective-c pubnub


【解决方案1】:

PubNub 访问管理器

你有Access Manager add-on enabled on your keys,所以它只是在做它的工作——拒绝未经授权的访问你的密钥。一旦启用,您必须grant all access to use your keys。当您启用 Access Manager 时,会弹出一个带有警告的对话框:

警告:此操作将在您的密钥集上启用 Access Manager。如果你 已在生产应用程序中使用此密钥集,请 意识到您需要授予对所有现有频道的访问权限才能 继续使用而不会中断。

这是该对话框的快照:

您可以禁用 Access Manager,直到您准备好在您的服务器上实施正确的授权逻辑并且您将不再收到此错误

在您的应用上线之前,您应该实施必要的授权逻辑并启用 Access Manager 以防止您的密钥被错误地使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多