swift - Save Parse notification - iOS -
i want have notification sent in uitableview. because user can delete notification (in notification center) without launching app, have store notification in parse database.
so how can programmatically save notification i'm sending in database. don't want send notification , enter manually notification in database.
hope it's clear. thanks
this code save push notification parse class before sending push notification.
pfobject *messageactivity = [pfobject objectwithclassname:kpapactivityclasskey]; [messageactivity setobject:kpapactivitytypereceivedmessage forkey:kpapactivitytypekey]; [messageactivity setobject:[pfuser currentuser] forkey:kpapactivityfromuserkey]; [messageactivity setobject:self.user forkey:kpapactivitytouserkey]; [messageactivity setobject:textfield.text forkey:kpapactivitycontentkey]; pfacl *messageacl = [pfacl aclwithuser:[pfuser currentuser]]; [messageacl setpublicreadaccess:yes]; [messageacl setwriteaccess:yes foruser:self.user]; messageactivity.acl = messageacl; // if more 5 seconds pass since post comment, stop waiting server respond nstimer *timer = [nstimer scheduledtimerwithtimeinterval:5.0f target:self selector:@selector(handlecommenttimeout:) userinfo:@{@"message": messageactivity} repeats:no]; [messageactivity save]; [timer invalidate]; pfobject *sentmessageactivity = [pfobject objectwithclassname:kpapactivityclasskey]; [sentmessageactivity setobject:kpapactivitytypesentmessage forkey:kpapactivitytypekey]; [sentmessageactivity setobject:self.user forkey:kpapactivityfromuserkey]; [sentmessageactivity setobject:[pfuser currentuser] forkey:kpapactivitytouserkey]; [sentmessageactivity setobject:textfield.text forkey:kpapactivitycontentkey]; pfacl *sentmessageacl = [pfacl aclwithuser:[pfuser currentuser]]; [sentmessageacl setpublicreadaccess:yes]; [sentmessageacl setwriteaccess:yes foruser:[pfuser currentuser]]; sentmessageactivity.acl = sentmessageacl; [sentmessageactivity save]; //even if message not saved log, still send message //ideally should add text message activity log , rest of notification system should send out notification since don't have centralized place insert activity/log, have duplicate code here // create our installation query pfquery *pushquery = [pfinstallation query]; [pushquery wherekey:@"userobjectid" equalto:self.user.objectid]; // send push notification query [pfpush sendpushmessagetoqueryinbackground:pushquery withmessage:[[[@"from " stringbyappendingstring:[[pfuser currentuser] objectforkey:@"displayname"]] stringbyappendingstring:@": " ] stringbyappendingstring:textfield.text] ];
Comments
Post a Comment