Guide
Comment utiliser Flash dans Capacitor
Utiliser @capgo/capacitor-flash
Plugin Flash Capacitor pour contrôler la lampe torche de l’appareil.
Installer
bun add @capgo/capacitor-flash
bunx cap sync
bunx cap sync copie le code natif du plugin dans vos projets natifs. Relancez-l’après chaque mise à jour du plugin.
Importer
import { CapacitorFlash } from '@capgo/capacitor-flash';
Aperçu de API
| Méthode | Description |
|---|---|
isAvailable |
Vérifie si la torche est disponible sur l'appareil. |
switchOn |
Allume la torche. |
switchOff |
Éteint la lampe torche. |
isSwitchedOn |
Vérifie si la torche est actuellement allumée ou éteinte. |
toggle |
Activez ou désactivez la lampe torche. |
Exemples
isAvailable()
Vérifie si la torche est disponible sur l'appareil.
import { CapacitorFlash } from '@capgo/capacitor-flash';
const { value } = await CapacitorFlash.isAvailable();
if (value) {
console.log('Flashlight is available');
}
switchOn()
Allume la torche.
import { CapacitorFlash } from '@capgo/capacitor-flash';
// Turn on at full brightness
await CapacitorFlash.switchOn({ intensity: 1.0 });
// Turn on at half brightness
await CapacitorFlash.switchOn({ intensity: 0.5 });
switchOff()
Éteint la lampe torche.
import { CapacitorFlash } from '@capgo/capacitor-flash';
await CapacitorFlash.switchOff();
isSwitchedOn()
Vérifie si la torche est actuellement allumée ou éteinte.
import { CapacitorFlash } from '@capgo/capacitor-flash';
const { value } = await CapacitorFlash.isSwitchedOn();
console.log('Flashlight is on:', value);
toggle()
Activez ou désactivez la lampe torche.
import { CapacitorFlash } from '@capgo/capacitor-flash';
const { value } = await CapacitorFlash.toggle();
console.log('Flashlight toggled, now on:', value);
Référence complète
Continuer avec « Utiliser @capgo/capacitor-flash »
Si vous utilisez Utiliser @capgo/capacitor-flash pour planifier les opérations du dashboard et de API, connectez-l’avec @capgo/capacitor-flash pour les détails d'implémentation dans @capgo/capacitor-flash, Prise en main pour les détails d'implémentation dans Getting Started Aperçu de API pour les détails d'implémentation dans « Vue d'ensemble de API », Introduction pour les détails d'implémentation dans l'Introduction, et Clés API pour les détails d'implémentation dans les clés API.