繁体   English   中英

Parse.com和ios的安装和徽章问题

[英]Installation and badge issue with Parse.com and ios

我在我的ios应用程序(parse.com sdk 1.7.2.2)上使用安装,推送和徽章,我几天前发现了一些内容,将徽章重置为0的代码,如博客文章中所述(旧版本http:// blog .parse.com / announcements / badge-management-for-ios /

// Clear badge if needed
PFInstallation *currentInstallation = [PFInstallation currentInstallation];

if (currentInstallation.badge != 0) {
    currentInstallation.badge = 0;
    [currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (!succeeded) [ErrorHandler handle:@"save installation failed" forError:error];
    }];
}

不再工作,一切都很好(没有Parse错误)但徽章计数保持在数据库中的旧值

在第二次我努力尝试,似乎暂时工作得更好:

PFInstallation *currentInstallation = [PFInstallation currentInstallation];

if (UIApplication.sharedApplication.applicationIconBadgeNumber > 0 || currentInstallation.badge > 0) {
    UIApplication.sharedApplication.applicationIconBadgeNumber = 0;
    currentInstallation.badge = 0;
    [currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
    {
        if (!succeeded) [ErrorHandler handle:@"save installation failed" forError:error];
    }];
}

但这不起作用,
任何想法?

继承我的快速代码,它的工作原理:

    // Resets badge number in parse
    var installation = PFInstallation.currentInstallation()
    if installation.badge != 0 {
        installation.badge = 0
        installation.saveInBackgroundWithBlock(nil)
    }

    // Resets badge number in app
    if application.applicationIconBadgeNumber > 0 {
        application.applicationIconBadgeNumber = 0
    }

install.badge和application.applicationIconBadgeNumber setter之间似乎存在依赖关系。 确保始终设置安装似乎可以缓解这个问题。

let pcur = PFInstallation.currentInstallation()
        print("current badge = \(pcur.badge)")
        if (pcur.badge != 0){
            pcur.badge = 0
            pcur.saveInBackgroundWithBlock({
                (succeeded,error) in
                print("badge save success = \(succeeded)")
                application.applicationIconBadgeNumber = 0
            })
        }

使用Parse(1.14.2),Xcode 8和ios 10,添加:

    UIApplication.shared.applicationIconBadgeNumber = 0

AppDelegate类的applicationDidBecomeActive方法内部也会将解析服务器上的徽章重置为零。

暂无
暂无

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

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