in src/actions/app-actions.ts [1144:1186]
export function subscribeToPushNotifications(): ReduxAction {
return async (dispatch: ReduxThunkDispatch, getState: ReduxStateGetter) => {
if (await DeviceInfo.isEmulator()) {
return;
}
PushNotificationsProcessor.init();
const onSwitchAccount = async (account: StorageState, issueId?: string, articleId?: string) => {
await dispatch(switchAccount(account, false, issueId, articleId));
};
const userLogin = getState().app.user?.login as string;
if (isRegisteredForPush()) {
log.info('App Actions: Device was already registered for push notifications. Initializing.');
try {
PushNotifications.initialize(onSwitchAccount, getState().app.user?.login!);
} catch (e) {
setRegisteredForPush(false);
}
return;
}
if (isAndroidPlatform()) {
const ver = typeof Platform.Version === 'string' ? parseInt(Platform.Version, 10) : Platform.Version;
if (ver >= 33) {
try {
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
await doSubscribe(onSwitchAccount, userLogin);
log.info('App Actions: Push notifications permission granted');
} else {
log.warn('App Actions: Push notifications permission is not allowed');
}
} catch (err) {
log.warn(err);
}
}
} else {
await doSubscribe(onSwitchAccount, userLogin);
}
};
}