简体   繁体   English

如何在解析iOS应用中阻止特定的用户推送通知?

[英]How to block specific user push notification in parse iOS app?

I am working on a iOS chatting app by use parse as backend service. 我正在使用parse作为后端服务来开发iOS聊天应用程序。 If user blocks another user, how to prevent the push notifications? 如果用户阻止了另一个用户,如何防止推送通知? Is that possible to filter this push notification in parse side? 是否可以在解析端过滤此推送通知?

Really appreciate in advance. 真的很感谢。

There are several different ways to block a push notification from being sent to a user that blocked the sender. 有几种不同的方法可以阻止将推送通知发送给阻止发件人的用户。 It really depends on how you handle the blocking of the user. 这实际上取决于您如何处理对用户的阻止。

You could, for instance, add a blockedUsernames array to each user. 例如,您可以向每个用户添加一个blockedUsernames数组。 If you did this, you could block the push notification from being sent in the first place, by cross checking this blocked users array against the users it is being sent to. 如果这样做,则可以通过与发送给它的用户进行交叉检查来阻止发送推送通知。

// CHECK FOR BLOCKED USERS

    PFUser *currentUser = [PFUser currentUser]; // user sending push
    PFUser *sendPushToUser = //user receiving the push

// Get array of blocked users
    NSMutableArray *blockedUsersArray = sendPushToUser[@"blockedUsers"];

    BOOL blocked = false;
    for (NSString *username in blockedUsersArray) {
        if ([username isEqualToString:currentUser.username]) {
            blocked = true;
        }
    }

     // If the user isn't blocked, send push
    if (blocked == false) {

    [PFCloud callFunctionInBackground:@"sendPushToUser" 
    // more cloud code to handle the notification...

You could also block the push notification in the Parse Cloud Code, with some JS. 您也可以使用一些JS在Parse Cloud Code中阻止推送通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM