【问题标题】:How do I decrement the PFInstallation for Parse in my iOS app?如何在我的 iOS 应用程序中减少 Parse 的 PFInstallation?
【发布时间】:2015-12-23 19:44:23
【问题描述】:

我正在使用 Parse 和 PFInstallation 根据来自 Parse 的通知增加我的应用程序的徽章计数。我还需要能够减少这个数字——不仅仅是重置它;我正在寻找与 iOS 消息或邮件应用程序标记相同的行为。每次您阅读邮件或消息时,该应用的标记会根据您查看的项目数递减。

如何在我的 iOS 应用中使用 Parse 和 PFInstallation 实现这一点? PFInstallation有递增的概念,那么递减呢?

【问题讨论】:

    标签: ios parse-platform push-notification badge pfinstallation


    【解决方案1】:

    很遗憾,您不能像使用Increment 那样使用Decrement。但是,您可以通过两种不同的方式将徽章编号设置为特定值。

    更新安装

    PFInstallation *currentInstallation = [PFInstallation          currentInstallation];
    if (currentInstallation.badge != 0) {
        currentInstallation.badge -= 1;
        [currentInstallation saveEventually];
    }
    

    通过推送更新

    在创建推送之前,查看数据库中当前的徽章编号,并发送值 - 1。

    NSDictionary *data = @{
         @"alert" : @"Your message",
         @"badge" : @<Decremented Value>,
    };
    PFPush *push = [[PFPush alloc] init];
    [push setChannels:@[ @"Your Channel" ]];
    [push setData:data];
    [push sendPushInBackground];
    

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      • 2021-07-03
      相关资源
      最近更新 更多