【发布时间】: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