iphone - iOS and Parse.com backend -
how go designing , managing data messaging application on ios using parse?
i've been thinking while , i'm @ loss... how have efficient , fast access data!? know way around in sql , stuff, not sql... need advice how tie things , connect app user his/her sent messages received messages other users using parse backend. create class each user? each conversation? or through sender , receiver id in 1 class? going still fast when class have 200,000 entries? main issue... how manage part of app!!
i working on app when started few month ago, didn't take consideration wanted start , not create obstacles don't know begin with.
just clear things up, started learning ios same time started project... computer engineer strong c/assembly background , iphone stuff been little annoying getting used it.
edit----------------------------------------------------------------------
so have code in viewwillappear in messageviewcontroller load messages in conversation.
pfquery *conversations = [pfquery querywithclassname:@"conversations"]; [conversations wherekey:@"recipientsids" containedin:self.recipients]; [conversations findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) { if (error) { nslog(@"error loading conversations"); }else{ // if no conversations found, create 1 , set conv. id if (objects.count == 0) { pfobject *conversation = [pfobject objectwithclassname:@"conversations"]; [conversation setobject:self.recipients forkey:@"recipientsids"]; [conversation setobject:@"" forkey:@"messageids"]; [conversation saveinbackgroundwithblock:^(bool succeeded, nserror *error) { if (error) { nslog(@"failed creating conversatin in bkgd"); }else{ self.conversationid = [conversation objectid]; } }]; }else{ pfquery *messages = [pfquery querywithclassname:@"messages"]; messages.cachepolicy = kpfcachepolicycachethennetwork; //sender id phone operator //[messages wherekey:@"senderid" equalto:[[pfuser currentuser] objectid]]; //receiver id other user in chat [messages wherekey:@"objectid" containedin:[objects valueforkey:@"messageids"]]; [messages orderbyascending:@"createdat"]; [messages findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) { if (error){ nslog(@"debug %@, %@", error, [error description]); }else{ // messages found , passed thru objects paramter. self.messages = objects; //nslog(@"messages: %@", self.messages); [self.tableview reloaddata]; // scroll table view [self.tableview setcontentoffset:cgpointmake(0, self.tableview.contentsize.height - self.tableview.frame.size.height)]; //nslog(@"number %lu", (unsigned long)[self.messages count]); } }]; } } }];
this if there conversation recipients id's. phone operator id added recipients id's before view loads. code above inserts conversation record if doesn't exit.
for saving the message after user types message, have code:
//[self hideshowkeyboard]; pfobject *webmessage = [pfobject objectwithclassname:@"messages"]; nsstring *timestamp = [nsdateformatter localizedstringfromdate:[nsdate date] datestyle:nsdateformattershortstyle timestyle:nsdateformattershortstyle]; //pfobject *sender = [pfobject objectwithclassname:@"sender"]; //[sender setobject:self.recipients forkey:@"recipientids"]; //[sender setobject:[[pfuser currentuser] objectid] forkey:@"senderid"]; //[sender setobject:[[pfuser currentuser] username] forkey:@"sendername"]; //[webmessage setobject:file forkey:@"file"]; //[webmessage setobject:filetype forkey:@"filetype"]; //[webmessage setobject:self.recipients forkey:@"recipientids"]; [webmessage setobject:[[pfuser currentuser] objectid] forkey:@"senderid"]; [webmessage setobject:[[pfuser currentuser] username] forkey:@"sendername"]; //[webmessage setobject:[pfuser currentuser] [@"phone"] forkey:@"senderphonenumber"]; [webmessage setobject:timestamp forkey:@"timestamp"]; [webmessage setobject:self.inputtext.text forkey:@"messagecontent"]; //[webmessage setobject:self.sendername forkey:@"receivername"]; //[webmessage setobject:self.senderid forkey:@"receiverid"]; [webmessage setobject:@"text" forkey:@"messagetype"]; //[webmessage setobject:@"jon" forkey:@"receivername"]; //[webmessage setobject:@"1234" forkey:@"receiverid"]; //[webmessage setobject:@"true" forkey:@"me"]; // store recip. ids in camera view. nest query call update //the conversation class message id recipids equal have... //recipids same coz in 1 coversation between 2 or group of users... pfobject *conversation = [pfobject objectwithclassname:@"conversations"]; [conversation setobject:self.recipients forkey:@"recipientsids"]; [conversation setobject:[[pfuser currentuser] username] forkey:@"sendername"]; [conversation setobject:[[pfuser currentuser] objectid] forkey:@"senderid"]; // [sender saveinbackgroundwithblock:^(bool succeeded, nserror *error) { // if (error) { // // show error // } // // else save good. // }]; self.inputtext.text = @""; [webmessage saveinbackgroundwithblock:^(bool succeeded, nserror *error) { if (error) { uialertview *alertview = [[uialertview alloc] initwithtitle:@"error" message:@"an error occured while uploading file. please try again." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alertview show]; }else{ // success! // create pfquery pfquery *query = [pfquery querywithclassname:@"conversations"]; // retrieve conversation id [query getobjectinbackgroundwithid:self.conversationid block:^(pfobject *pfobject, nserror *error) { // let's update [pfobject setobject:[webmessage objectid] forkey:@"messageids"]; [pfobject saveinbackground]; }]; [self viewwillappear:false]; } }];
please ignore commented code... have bad habit of commenting , trying things go clean code when done.
the problem is, process created 3 entries in conversation class... think because trying update same record in conversations class message id , in database conversations class has 3 entries , 1 of them has message id... attached picture.. don't know why not comprehending thing correctly... i'm sure simpler thinking...
also, how go loading conversations in inbox view show sender names? started writing process not complete yet... need conversation , message stuff correctly first...
can please point me in right direction? think insertion of conversation isn't correct... why recipientids contains [] nothing in them? set self.recipients before making segue... right dealing create new message process... inbox view should contain names of senders , i'm not sure how go yet...
thank help.
edit-------------------------------------------------------------------- fixed conversation class issue... turned out recipients id coming empty...
the issue when updating conversation record add new message ids updates last one... string type column instead of array type... should do? update process in second code block above.
omg thing won't let me post images until have 10 reputation... sheesh.
edit---------------------------------------------------------------------
so fixed other issue have issue piece of code when try update conversation record:
[query getobjectinbackgroundwithid:self.conversationid block:^(pfobject *pfobject, nserror *error) { if(error){ nslog(@"error occured while getting conversation object"); }else{ // let's update new data. [pfobject setobject:self.messageids forkey:@"messageids"]; [pfobject saveinbackground]; } }];
as enters first line, throws error:
terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'cannot comparison query type: __nsarrayi'
self.conversationid string type!! not array... array complaining about!! don't understand...
in .h: @property (nonatomic, strong) nsstring *conversationid; @property (nonatomic, strong) nsmutablearray *messageids;
any ideas?
edit---------------------------------------------------------------------------
i'm trying update conversation record add new message messageids column...
[webmessage saveinbackgroundwithblock:^(bool succeeded, nserror *error) { if (error) { uialertview *alertview = [[uialertview alloc] initwithtitle:@"error" message:@"an error occured while uploading file. please try again." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alertview show]; }else{ // success! // create pfquery pfquery *query = [pfquery querywithclassname:@"conversations"]; // retrieve conversation id [query getobjectinbackgroundwithid:self.conversationid block:^(pfobject *pfobject, nserror *error) { if(error){ nslog(@"error occured while getting conversation object"); }else{ // let's update new data. [pfobject setobject:self.messageids forkey:@"messageids"]; [pfobject saveinbackground]; } }]; [self viewwillappear:false]; }
}];
edit-----------------------------------------------------------------------------
i dropped conversations class since thought because messageids column string type , not array. error:
error domain=parse code=120 "the operation couldn’t completed. (parse error 120.)" userinfo=0x110023400 {error=cache miss, code=120}
i don't know what's wrong this... want update conversation record new message object id. saw online many people doing don't why getting error...the saving not taking place... there way update row in parse?
even though quite old now, tutorial should started: http://attila.tumblr.com/post/21180235691/ios-tutorial-creating-a-chat-room-using-parse-com
i recommend creating conversation class contains object each , every conversation. also, messsage class every message. conversation class contains column array pointers every message in conversation. way, super fast messages in conversation, single query, using includekey on messages column.
Comments
Post a Comment