第二个TEST LOG写出了我从iPhone发送的整个消息(我已经使用开发控制台尝试过了),但在此之后应用程序崩溃了.
[__NSCFDictionary length]: unrecognized selector sent to instance
我知道字典有问题,但我无法弄清楚.我只使用一个NSDictionary作为我通过PubNub发送的消息,它“到达”控制台,因此我认为它正常工作.正如你在代码中看到的那样,我尝试了一些变化,但没有任何成功.
UPDATE
如果我发送Nsstring而不是NSDictionary,它会工作.
@interface VIEwController ()@property (nonatomic,strong) Nsstring *myIncomeMessage;@property (nonatomic,strong) Nsstring *messageFromDict;@property (nonatomic,strong) NSArray *twoChannels;@property (nonatomic,strong) NSDictionary *messagePbnb;//@property (nonatomic,strong) PNMessage *messageNew;@end@implementation VIEwController- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; PNChannel *channel_2 = [PNChannel channelWithname:current.username shouldobservePresence:NO]; PNChannel *channel_1 = [PNChannel channelWithname:self.messageRecipIEnt shouldobservePresence:NO]; [PubNub subscribeOnChannels:self.twoChannels]; [PubNub requestHistoryForChannel:channel_1 from:nil to:nil limit:100 reverseHistory:YES]; [PubNub requestHistoryForChannel:channel_2 from:nil to:nil limit:100 reverseHistory:YES]; [[PNObservationCenter defaultCenter] addMessageReceiveObserver:self withBlock:^(PNMessage *message) { NSLog(@"OBSERVER: Channel: %@,Message: %@",message.channel.name,message.message); NSLog(@"Sample TEST LOG %@",message.message); self.myIncomeMessage = message.message; NSLog(@"Second TEST LOG %@",self.myIncomeMessage); // self.messageFromDict = [Nsstring stringWithFormat:keyMessage,self.messagePbnb]; // self.messageFromDict = [Nsstring stringWithFormat:keyMessage,message]; }]; [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(reloadtable) userInfo:nil repeats:YES]; [self setupUIForinput];}- (IBAction) inputContent { Nsstring *messageContent = self.textVIEw.text; PNChannel *channel_1 = [PNChannel channelWithname:self.messageRecipIEnt shouldobservePresence:NO]; PNChannel *channel_2 = [PNChannel channelWithname:senderUser.username shouldobservePresence:NO]; self.twoChannels = @[channel_1,channel_2]; [PubNub subscribeOnChannels: self.twoChannels]; self.messagePbnb = @{ @"keyMessage": messageContent,@"keySenderUser": self.senderUser.username,@"keyRecIEverChannel": self.messageRecipIEnt} ; [PubNub sendMessage: self.messagePbnb tochannel:channel_1]; [PubNub sendMessage: self.messagePbnb tochannel:channel_2]; [self.textVIEw resignFirstResponder]; [self reloadinputVIEws];}-(NSInteger) tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section { return 10;}-(UItableVIEwCell *) tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath { OutputtableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:@"cellThree"]; cell.textoutput.text = self.myIncomeMessage;-(voID)reloadtable{ [tableVIEwThree reloadData];}解决方法 @sabin,这是一个例子,使用观察者 – 你可以通过委托做类似的事情:
[[PNObservationCenter defaultCenter] addMessageReceiveObserver:self withBlock:^(PNMessage *message) { ID messageData = message.message; if ([messageData isKindOfClass:[NSDictionary class]]) { Nsstring *messageString = [Nsstring stringWithFormat:@"foo: %@,and bar: <%@>",[(NSDictionary *)messageData valueForKey:@"foo"],[(NSDictionary *)messageData valueForKey:@"bar"]]; } }];
如果您随后从Web控制台(pubnub.com/console)发布了此内容:
{"foo":"hey","bar":"you!"}
您将能够从上面的代码(通过messageString)呈现一个字符串,如下所示:
foo: hey,and bar: you!
如果有帮助,请告诉我!
总结以上是内存溢出为你收集整理的ios – 从PubNub消息中检索内容全部内容,希望文章能够帮你解决ios – 从PubNub消息中检索内容所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)