保存解析通知 - iOS
Posted
技术标签:
【中文标题】保存解析通知 - iOS【英文标题】:Save Parse notification - iOS 【发布时间】:2015-10-31 00:05:44 【问题描述】:我希望在 UITableView 中发送所有通知。 因为用户可以在不启动应用程序的情况下删除通知(在通知中心),所以我必须将所有通知存储在 Parse 数据库中。
那么,如何以编程方式将发送的通知保存在数据库中。我不想发送通知,然后在数据库中手动输入通知。
希望很清楚。谢谢
【问题讨论】:
【参考方案1】:这是在发送推送通知之前将推送通知保存到解析类的代码。
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 than 5 seconds pass since we post a comment, stop waiting for the server to 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 the message is not saved to log, still send the message
//ideally should just add this text message activity to the log and the rest of the notification system should send out a notification but since we don't have a centralized place to insert to activity/log, we have to duplicate code here
// Create our Installation query
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"UserObjectId" equalTo:self.user.objectId];
// Send push notification to query
[PFPush sendPushMessageToQueryInBackground:pushQuery
withMessage:[[[@"From " stringByAppendingString:[[PFUser currentUser] objectForKey:@"displayName"]] stringByAppendingString:@": " ] stringByAppendingString:textField.text]
];
【讨论】:
但是我从解析网站发送通知 您如何看待创建 parse.com 云代码函数、parse.com 作业或以编程方式发送通知并保存通知的简单应用程序(类似于上面的代码)?以上是关于保存解析通知 - iOS的主要内容,如果未能解决你的问题,请参考以下文章