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

Accessing CapacitorKV from App #103

Open
ChristianK43 opened this issue Aug 22, 2024 · 3 comments
Open

Accessing CapacitorKV from App #103

ChristianK43 opened this issue Aug 22, 2024 · 3 comments

Comments

@ChristianK43
Copy link

Hey,
I'm working on implementing a background task and need it to stop running when the app is in the foreground.
Using an event dispatch when the app goes into the background doesn't work because there's no active runner when the appStateChange event triggers.

It seems to me that the simplest solution would be to use CapacitorKV to set the state during the appStateChange event to handle this. Is this possible? I couldn't find any information on this in the documentation.
I've seen that #99 would allow to access the App-API, but it would be great to have a solution until it gets merged.

@yshalsager
Copy link

yshalsager commented Sep 2, 2024

@ChristianK43
You can use @capacitor/preferences and configure it to use same xml file as background runner

// app
import {Preferences} from '@capacitor/preferences'

await Preferences.configure({
    group: 'com.example.background'
})
await Preferences.set({
    key: 'test',
    value: 'true',
})

// background
addEventListener('example', async (resolve, reject, args) => {
	console.log('kv test', CapacitorKV.get('test'))
})

@web-jw
Copy link

web-jw commented Nov 19, 2024

@yshalsager Is there a way to do it with @ionic/storage?

@yshalsager
Copy link

@yshalsager Is there a way to do it with @ionic/storage?

No idea, never used.

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