ios - firebase observeeventtype jsqmessagecollectionview avatar -
i'm going show avatar image of users within conversation. used jsqmessageviewcontroller, function below should used achieve goal. however, observeeventtype seems out function , not being called, , there nil(myuserimage or otheruserimage) in return. crash appear. how can photo url of different users in firebase , return expected avatar image? thank you!
- (id<jsqmessageavatarimagedatasource>)collectionview:(jsqmessagescollectionview *)collectionview avatarimagedataforitematindexpath:(nsindexpath *)indexpath { jsqmessage *message = [self.msgarray objectatindex:indexpath.item]; if([message.senderid isequaltostring:self.senderid]){ nsstring *myuserid = [firauth auth].currentuser.uid; __block nsstring *myuserimage; nslog(@"uid : %@",myuserid); [[_photoref child:@"users"] observeeventtype:firdataeventtypevalue withblock:^(firdatasnapshot *snapshot) { nslog(@"my key : %@",snapshot.key); if([snapshot.key isequaltostring:myuserid]){ nslog(@"snapshot value : %@", snapshot.value); myuserimage = snapshot.value[@"photo"]; } }]; nsurl *url = [nsurl urlwithstring:myuserimage]; nsdata *data = [nsdata datawithcontentsofurl:url]; self.myuserimage= [[uiimage alloc] initwithdata:data]; return [jsqmessagesavatarimagefactory avatarimagewithimage:self.myuserimage diameter:15]; } else{ nsstring *otheruserid = message.senderid; __block nsstring *otheruserimage; nslog(@"other userid is: %@",otheruserid); [[_photoref child:@"users"]observeeventtype:firdataeventtypevalue withblock:^(firdatasnapshot *snapshot) { nslog(@"other user's key is: %@", snapshot.key); if([snapshot.key isequaltostring:otheruserid]){ nslog(@"snapshot value is: %@", snapshot.value); otheruserimage = snapshot.value[@"photo"]; } }]; nsurl *url = [nsurl urlwithstring:otheruserimage]; nsdata *data = [nsdata datawithcontentsofurl:url]; self.otheruserimage= [[uiimage alloc] initwithdata:data]; return [jsqmessagesavatarimagefactory avatarimagewithimage:self.otheruserimage diameter:15]; } }
from best can tell looks need pulling data firebase before method gets called. creating struct matches data structure , being able pull information datasource presumably array of these structs you've created.
an implementation i'd recommend exploring use library sdwebimage manage async call , let set default avatar while network request , image rendering happen. still need url fetched database before method gets called.
Comments
Post a Comment