ios - Retrieve content from PubNub messages -


i can send , receive messages pubnub, problem comes when try display content message , load uitableviewcell's uitextview.

the second test log writes out whole message, send iphone (i've tried dev console), after app crashes.

[__nscfdictionary length]: unrecognized selector sent instance 

i know there wrong dictionary, can't figure out. i'm using 1 nsdictionary message send via pubnub , "arrives" console, therefore think works properly. can see in code i've tried variations, without success.

update

it's working if send nsstring instead of 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, here example, using observer -- similar thing via delegate:

[[pnobservationcenter defaultcenter] addmessagereceiveobserver:self                                                      withblock:^(pnmessage *message) {       id messagedata = message.message;      if ([messagedata iskindofclass:[nsdictionary class]]) {       nsstring *messagestring = [nsstring stringwithformat:@"foo: %@, , bar: <%@>",              [(nsdictionary *)messagedata valueforkey:@"foo"],              [(nsdictionary *)messagedata valueforkey:@"bar"]];      }  }]; 

if published web console (pubnub.com/console):

{"foo":"hey", "bar":"you!"} 

you able render string above code (via messagestring) looked this:

foo: hey, , bar: you! 

let me know if helped!


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -