Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting badge amount correctly #10

Closed
holgersindbaek opened this issue Feb 12, 2016 · 6 comments
Closed

Setting badge amount correctly #10

holgersindbaek opened this issue Feb 12, 2016 · 6 comments

Comments

@holgersindbaek
Copy link

I want to increment badge count by 1 for every notification the user receives and when the user enters the app, I want the badge count to reset to 0.

Right now, I'm using your system to keep track of badge count, but your system doesn't reset the badge count to 0 once the user enters the app. Is there any way I can reset the badge count to 0 for a user using the iOS library?

If not, is there any way I can receive a message in the background? Right now, I have a callback for "initWithLaunchOptions", but that only gets called if the user is currently in the app and not if the app is running in the background.

Any of these 2 solutions would work nicely.

@jkasten2
Copy link
Member

To increment the badge count when a notification is received you can set ios_badgeType to "Increase" and ios_badgeCount to 1. Our SDK should be resetting the badge count back to 0 each time the app is opened / resumed automatically. I haven't seen any bugs with this is it is more likely another plugin / SDK code be interfering. Can you try to reproduce the issue in a new project? Let us know the steps to reproduce the issue if you're still seeing it.

You can set content_available to true on OneSignal to wake up your app in the background. It will fire the application:didReceiveRemoteNotification:fetchCompletionHandler: selector in your app's code.

Thanks.

@holgersindbaek
Copy link
Author

That's not what I'm experiencing. When I enter the app, the increment count is not reset. It might be that it's reset if you open the app by clicking the notification, but not if you open the app like normal. 

All the best

Holger Sindbaek · UI/UX Designer & Web/iOS Programmer · HolgerSindbaek.com

On Fri, Feb 12, 2016 at 2:07 PM -0800, "Josh Kasten" notifications@github.com wrote:

To increment the badge count when a notification is received you can set ios_badgeType to "Increase" and ios_badgeCount to 1. Our SDK should be resetting the badge count back to 0 each time the app is opened / resumed automatically. I haven't seen any bugs with this is it is more likely another plugin / SDK code be interfering. Can you try to reproduce the issue in a new project? Let us know the steps to reproduce the issue if you're still seeing it.

You can set content_available to true on OneSignal to wake up your app in the background. It will fire the application:didReceiveRemoteNotification:fetchCompletionHandler: selector in your app's code.

Thanks.


Reply to this email directly or view it on GitHub.

@jkasten2
Copy link
Member

The only issue I can see where the badge counter would not be cleared is if you were not calling initWithLaunchOptions from the application:didFinishLaunchingWithOptions: selector in your app or there is another plugin / SDK or code changing the value.

We have a clearBadgeCount internal function that is called in a number of locations to make sure the badge is cleared. It includes the follow events.

  • An app cold start from either tapping on a notification or tapping on the app icon. Called from it application:didFinishLaunchingWithOptions: as long as initWithLaunchOptions is called from it.
  • When focus is resumed to the app from any event. Our SDK hooks into applicationWillResignActive: where this function is called.
  • A OneSignal notification event is fired. Anytime a OneSignal notification is counted as open from either tapping on one or one is received while the app is in focus.

Can you post a project reproducing the issue along with the iOS version you're testing on with step by step instructions reproducing the issue?

Thanks.

@holgersindbaek
Copy link
Author

I was setting "applicationIconBadgeNumber" manually different places. I think that had some unexpected consequences.

I've taken that away now and it's working perfectly.

@AmirDaliri
Copy link

AmirDaliri commented Dec 25, 2017

@jkasten2 , @ALL hi ,
how to set content_available in application:didReceiveRemoteNotification:fetchCompletionHandler ??? , What code is it? i don't know! i search about and, There is no explanation for this
please help me, Thanx

@jkasten2
Copy link
Member

@AmirDaliri application:didReceiveRemoteNotification:fetchCompletionHandler will fire when a notification is received with content_available set to true from OneSignal. See Apple's docs below for more detail on this method.
https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application

There is another issue open related to syncing badge counts you can follow bellow.
#57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants