should have push notifs as well as Battery SOC monitoring
This commit is contained in:
18
lib/BlindMasterResources/fcm_service.dart
Normal file
18
lib/BlindMasterResources/fcm_service.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:blind_master/BlindMasterResources/secure_transmissions.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
|
||||
class FcmService {
|
||||
/// Request permission, fetch the FCM token, and register it with the server.
|
||||
/// Safe to call on every login/session-restore — the server just upserts the value.
|
||||
static Future<void> register() async {
|
||||
try {
|
||||
final messaging = FirebaseMessaging.instance;
|
||||
await messaging.requestPermission(alert: true, badge: true, sound: true);
|
||||
final token = await messaging.getToken();
|
||||
if (token == null) return;
|
||||
await securePost({'token': token}, 'register_fcm_token');
|
||||
} catch (_) {
|
||||
// Non-fatal — push notifications simply won't work until the next successful registration.
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user