简体   繁体   English

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

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

I use installation, push and badge on my ios app (parse.com sdk 1.7.2.2) and I noticed something few days ago, the code that reset the badge to 0 as explained in the blog post (old one http://blog.parse.com/announcements/badge-management-for-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];
    }];
}

does not work anymore, everything is good (no Parse error) but the badge count stay to the old value in the database 不再工作,一切都很好(没有Parse错误)但徽章计数保持在数据库中的旧值

In a second time I tried the hard way, and it seems to work better for a moment: 在第二次我努力尝试,似乎暂时工作得更好:

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];
    }];
}

But this is not working, 但这不起作用,
any idea? 任何想法?

Heres my swift code and it works: 继承我的快速代码,它的工作原理:

    // 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
    }

there seems to be a dependency between the installation.badge and the application.applicationIconBadgeNumber setters. install.badge和application.applicationIconBadgeNumber setter之间似乎存在依赖关系。 Ensuring the installation is always set first seems to alleviate the issue. 确保始终设置安装似乎可以缓解这个问题。

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
            })
        }

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

    UIApplication.shared.applicationIconBadgeNumber = 0

inside the applicationDidBecomeActive method in the AppDelegate class will also reset the badge on the parse server to zero. AppDelegate类的applicationDidBecomeActive方法内部也会将解析服务器上的徽章重置为零。

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

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