Clear iOS notification on resume/open (#520)

This commit is contained in:
Diego Mello 2018-10-31 15:40:39 -03:00 committed by GitHub
parent ba9cc637d3
commit afb2e6fd92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 3 deletions

View File

@ -31,12 +31,13 @@ const onNotification = (notification) => {
} }
}; };
const getDeviceToken = () => PushNotification.getDeviceToken();
const setBadgeCount = count => PushNotification.setBadgeCount(count);
const initializePushNotifications = () => { const initializePushNotifications = () => {
PushNotification.configure({ PushNotification.configure({
onNotification onNotification
}); });
setBadgeCount();
}; };
const getDeviceToken = () => PushNotification.getDeviceToken(); export { initializePushNotifications, getDeviceToken, setBadgeCount };
export { initializePushNotifications, getDeviceToken };

View File

@ -19,6 +19,8 @@ class PushNotification {
return this.deviceToken; return this.deviceToken;
} }
setBadgeCount = () => {}
configure(params) { configure(params) {
this.onRegister = params.onRegister; this.onRegister = params.onRegister;
this.onNotification = params.onNotification; this.onNotification = params.onNotification;

View File

@ -21,6 +21,10 @@ class PushNotification {
return this.deviceToken; return this.deviceToken;
} }
setBadgeCount = (count = 0) => {
NotificationsIOS.setBadgesCount(count);
}
configure(params) { configure(params) {
this.onRegister = params.onRegister; this.onRegister = params.onRegister;
this.onNotification = params.onNotification; this.onNotification = params.onNotification;

View File

@ -3,6 +3,7 @@ import { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-ap
import RocketChat from '../lib/rocketchat'; import RocketChat from '../lib/rocketchat';
import log from '../utils/log'; import log from '../utils/log';
import { setBadgeCount } from '../push';
const appHasComeBackToForeground = function* appHasComeBackToForeground() { const appHasComeBackToForeground = function* appHasComeBackToForeground() {
const appRoot = yield select(state => state.app.root); const appRoot = yield select(state => state.app.root);
@ -14,6 +15,7 @@ const appHasComeBackToForeground = function* appHasComeBackToForeground() {
return; return;
} }
try { try {
setBadgeCount();
return yield RocketChat.setUserPresenceOnline(); return yield RocketChat.setUserPresenceOnline();
} catch (e) { } catch (e) {
log('appHasComeBackToForeground', e); log('appHasComeBackToForeground', e);