In my chatting application, I'm using Parse for a user table, getting ID's, images, etc. I recently added this functionality, and I have encountered a problem. When I send a message, I create an NSDictionary
with information about the message such as time, message, sender, sender objectId, etc. But, when I try to add the PFFile (image file) associated with the user, I get an error saying that PFFile cannot be converted to JSON (PubNub message format). How can I add PFFile as part of the NSDictionary
used in the message to be compatible with JSON, or there might be another way.
I'm not familiar with asynchronous tasks, but in my code, I have a method - (NSDictionary *)parseMessageToDisplay:(NSDictionary *)message {}
where the input would be message received from PubNub, and it would return a format better united to be displayed in a UITableView
. If I added the ID of the file or user to my dictionary, how could I get my image in UIImage
or NSData
, and return it from my method in an NSDictionary
. Sorry if this post seems long, just trying to provide a lot of information.
Thanks to @danh for this suggestion, but you really saved me. Apparently Parse creates a URL for all PFFile
s and I can just send that URL (NSString *
) with my NSDictionary
to PubNub, and then in my - (NSDictionary *)parseMessageToDisplay:(NSDictionary *)message
method just use [NSData dataWithContentsOfURL:[NSURL URLWithString:imageURLString]];
and get data from that. YAY! No long running confusing asynchronous tasks to made my day terrible!