Skip to content

PushNotificationIOS.setApplicationIconBadgeNumber() doesn't work if the app is in background state. #22740

Description

@JulienUsson

Environment

 React Native Environment Info:
    System:
      OS: macOS 10.14.2
      CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
      Memory: 40.18 MB / 8.00 GB
      Shell: 5.6.2 - /usr/local/bin/zsh
    Binaries:
      Node: 11.0.0 - ~/.nvm/versions/node/v11.0.0/bin/node
      Yarn: 1.12.1 - ~/.nvm/versions/node/v11.0.0/bin/yarn
      npm: 6.4.1 - ~/.nvm/versions/node/v11.0.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 23, 24, 25, 26, 27
        Build Tools: 23.0.1, 24.0.3, 25.0.2, 26.0.1, 26.0.2, 27.0.3
    IDEs:
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.57.8 => 0.57.8 
    npmGlobalPackages:
      react-native-cli: 2.0.1

Description

PushNotificationIOS.setApplicationIconBadgeNumber() doesn't work on IOS if the app is in background state.

Reproducible Demo

import React, {Component} from 'react'
import {PushNotificationIOS, Text, View} from 'react-native'
import OneSignal from 'react-native-onesignal'

export default class App extends Component {
    state = {
        notification: null
    }

    componentDidMount() {
        OneSignal.init("token", {kOSSettingsKeyAutoPrompt: true})
        OneSignal.inFocusDisplaying(0)
        OneSignal.addEventListener('received', this.onReceived)
    }

    componentWillUnmount() {
        OneSignal.removeEventListener('received', this.onReceived)
    }

    onReceived = async notification => {
        PushNotificationIOS.setApplicationIconBadgeNumber(1)  // doesn't work in background
        this.setState({notification}) // work in background
    }

    render() {
        return (
            <View>
                <Text>{JSON.stringify(this.state.notification)}</Text>
            </View>
        )
    }
}
`
``

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions