Do not trigger foreground notifications on iOS

This commit is contained in:
minibits-cash
2025-04-02 12:44:29 +02:00
parent 270997c5d9
commit 40bb0b3b00
3 changed files with 29 additions and 18 deletions
+10 -4
View File
@@ -5,6 +5,7 @@ import {
View,
Switch,
Alert,
Platform,
} from 'react-native'
import {btoa} from 'react-native-quick-base64'
import notifee, { AndroidImportance } from '@notifee/react-native'
@@ -186,10 +187,15 @@ export const ExportBackupScreen = function ExportBackup({ route }: Props) {
setIsLoading(true)
setIsSwapAllSentToQueue(true)
await NotificationService.createForegroundNotification(
'Optimizing ecash proofs denominations...',
{task: SWAP_ALL_TASK}
)
if(Platform.OS === 'android') {
await NotificationService.createForegroundNotification(
'Optimizing ecash proofs denominations...',
{task: SWAP_ALL_TASK}
)
} else {
// iOS does not support fg notifications with long running tasks
WalletTask.swapAllQueue()
}
}
}
]
+15 -6
View File
@@ -1,6 +1,6 @@
import {observer} from 'mobx-react-lite'
import React, {useState, useEffect, useRef} from 'react'
import {TextInput, TextStyle, View, ViewStyle} from 'react-native'
import {Platform, TextInput, TextStyle, View, ViewStyle} from 'react-native'
import notifee, { AndroidImportance } from '@notifee/react-native'
import {spacing, useThemeColor, colors} from '../theme'
import {
@@ -79,7 +79,11 @@ export const RecoveryOptionsScreen = observer(function RecoveryOptionsScreen({ r
}, [isSyncStateSentToQueue])
const openNotificationSettings = async function() {
await notifee.openNotificationSettings()
if(Platform.OS === 'android') {
await notifee.openNotificationSettings()
} else {
const settings = await notifee.requestPermission()
}
}
@@ -126,10 +130,15 @@ export const RecoveryOptionsScreen = observer(function RecoveryOptionsScreen({ r
setIsLoading(true)
setIsSyncStateSentToQueue(true)
await NotificationService.createForegroundNotification(
'Cleaning spent ecash from spendable balance...',
{task: SYNC_STATE_WITH_ALL_MINTS_TASK}
)
if(Platform.OS === 'android') {
await NotificationService.createForegroundNotification(
'Cleaning spent ecash from spendable balance...',
{task: SYNC_STATE_WITH_ALL_MINTS_TASK}
)
} else {
// iOS does not support fg notifications with long running tasks
WalletTask.syncStateWithAllMintsQueue({isPending: false})
}
}
+4 -8
View File
@@ -339,14 +339,10 @@ const _getRemoteData = async function(remoteMessage: FirebaseMessagingTypes.Remo
}
// Foreground service creation for long running tasks
// Foreground service creation for Android long running tasks
const createForegroundNotification = async function (body: string, data: {task: string, data?: any}) {
log.trace('Start', {body, data}, 'createForegroundNotification')
// Request permissions (required for iOS) // needed?
if(Platform.OS === 'ios') {
await notifee.requestPermission()
}
const isChannelCreated = await notifee.isChannelCreated(TASK_QUEUE_CHANNEL_ID)
if (!isChannelCreated) {
await notifee.createChannel({
@@ -354,8 +350,8 @@ const createForegroundNotification = async function (body: string, data: {task:
name: TASK_QUEUE_CHANNEL_NAME,
sound: 'default',
})
}
}
return notifee.displayNotification({
title: TASK_QUEUE_CHANNEL_NAME,
body,