forked from eatvio/eatvio_app
36 lines
1.1 KiB
Dart
36 lines
1.1 KiB
Dart
import 'dart:developer';
|
|
import 'dart:io';
|
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
import 'package:dio/dio.dart';
|
|
import 'package:eatvio_app/core/locator_service.dart';
|
|
import 'package:eatvio_app/core/token_storage.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
|
|
class FirebaseApi {
|
|
final _firebaseMessaging = FirebaseMessaging.instance;
|
|
|
|
Future<String?> getToken() async {
|
|
await _firebaseMessaging.requestPermission();
|
|
return await _firebaseMessaging.getToken();
|
|
}
|
|
|
|
Future<void> registerPushToken() async {
|
|
if (await TokenStorage.haveTokenInStorage()) {
|
|
try {
|
|
final deviceInfo = DeviceInfoPlugin();
|
|
await sl<Dio>().post(
|
|
'/api/profile/notification/token/register',
|
|
data: {
|
|
'platform': Platform.isIOS ? 'ios' : 'android',
|
|
'hw_id': Platform.isIOS ? (await deviceInfo.iosInfo).identifierForVendor : (await deviceInfo.androidInfo).id,
|
|
'token': await getToken(),
|
|
},
|
|
);
|
|
} catch (e, st) {
|
|
log(e.toString(), stackTrace: st);
|
|
}
|
|
}
|
|
}
|
|
}
|