簡體   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