iOS Components and Frameworks: Understanding the Advanced Features of the iOS SDK
by Kyle Richter, Joe Keeley
Sending Data in the Sample App
Take a look at how sending data is implemented in the sample app; everything is handled directly in the sendMessage: method. Because the app will need to send more data than just the message string, a new dictionary is created to also store information about who the message came from. For the purposes of the sample app, there is a mutable array that will hold onto all the incoming and outgoing data called chatObjectArray. Because we are sending a message, a local copy is inserted into that array.
Earlier, you learned that you can send only NSData. However, you do not want to send the dictionary since the sender key is set to "myself"; when the other peer receives a message, the sender should not be set to "myself" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access