{"action":"created","issue":{"url":"https://api.github.com/repos/leancloud/leanchat-ios/issues/43","labels_url":"https://api.github.com/repos/leancloud/leanchat-ios/issues/43/labels{/name}","comments_url":"https://api.github.com/repos/leancloud/leanchat-ios/issues/43/comments","events_url":"https://api.github.com/repos/leancloud/leanchat-ios/issues/43/events","html_url":"https://github.com/leancloud/leanchat-ios/issues/43","id":92280233,"number":43,"title":"关于Badge问题","user":{"login":"poundswu","id":12710867,"avatar_url":"https://avatars.githubusercontent.com/u/12710867?v=3","gravatar_id":"","url":"https://api.github.com/users/poundswu","html_url":"https://github.com/poundswu","followers_url":"https://api.github.com/users/poundswu/followers","following_url":"https://api.github.com/users/poundswu/following{/other_user}","gists_url":"https://api.github.com/users/poundswu/gists{/gist_id}","starred_url":"https://api.github.com/users/poundswu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poundswu/subscriptions","organizations_url":"https://api.github.com/users/poundswu/orgs","repos_url":"https://api.github.com/users/poundswu/repos","events_url":"https://api.github.com/users/poundswu/events{/privacy}","received_events_url":"https://api.github.com/users/poundswu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-01T06:23:02Z","updated_at":"2015-07-03T03:03:13Z","closed_at":null,"body":"程序在进入时会清空badge，并且把清空的结果save到server。可是实际上假如用户有3条未读信息，然后在打开后还是不去读的话，程序内消息的标签页Badge会是未读信息数，也就是3。可是AppIconBadge就总是会在打开后变成0，尽管实际上有3条未读。此时如果用户离线，在接单离线消息推送时，AppIconBadge会变成0+1=1，可是实际上未读消息数是3+1=4条。"},"comment":{"url":"https://api.github.com/repos/leancloud/leanchat-ios/issues/comments/118216313","html_url":"https://github.com/leancloud/leanchat-ios/issues/43#issuecomment-118216313","issue_url":"https://api.github.com/repos/leancloud/leanchat-ios/issues/43","id":118216313,"user":{"login":"lzwjava","id":5022872,"avatar_url":"https://avatars.githubusercontent.com/u/5022872?v=3","gravatar_id":"","url":"https://api.github.com/users/lzwjava","html_url":"https://github.com/lzwjava","followers_url":"https://api.github.com/users/lzwjava/followers","following_url":"https://api.github.com/users/lzwjava/following{/other_user}","gists_url":"https://api.github.com/users/lzwjava/gists{/gist_id}","starred_url":"https://api.github.com/users/lzwjava/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lzwjava/subscriptions","organizations_url":"https://api.github.com/users/lzwjava/orgs","repos_url":"https://api.github.com/users/lzwjava/repos","events_url":"https://api.github.com/users/lzwjava/events{/privacy}","received_events_url":"https://api.github.com/users/lzwjava/received_events","type":"User","site_admin":false},"created_at":"2015-07-03T03:03:13Z","updated_at":"2015-07-03T03:03:13Z","body":"@poundswu 你有兴趣弄一下吗？\r\n\r\n```\r\n        AVInstallation *currentInstallation = [AVInstallation currentInstallation];\r\n        [currentInstallation setBadge:0];\r\n        [currentInstallation saveInBackgroundWithBlock: ^(BOOL succeeded, NSError *error) {\r\n            NSLog(@\"%@\", error ? error : @\"succeed\");\r\n        }];\r\n```\r\n\r\n这样来设定 服务端的badge 数。\r\n只要本地未读数有变化的话，就调用上面的代码设置一下。同时设置一下本地的，\r\n```objc\r\napplication.applicationIconBadgeNumber = 0;\r\n```\r\n\r\nCDChatListVC 里面有 totalUnreadCount。在这里维护一个 totalUnreadCount 变量。当每次 viewDidAppear 的时候，查一下当前的totalUnreadCount，如果和上次的有变化，就用上面的代码设置一下服务器和本地的badge。\r\n\r\n有兴趣搞下吗？\r\nThanks！\r\n"}}