move update token to homepage adn get APNSToken

This commit is contained in:
Jonatas Antunes Messias 2024-06-19 17:19:45 -03:00
parent 44a8f84477
commit 29f82e89f9
2 changed files with 36 additions and 20 deletions

View File

@ -121,23 +121,6 @@ Future singInActionApp(
(loginCall.jsonBody ?? ''), (loginCall.jsonBody ?? ''),
)!; )!;
// FFAppState().token = await FirebaseMessaging.instance.getToken(); // FFAppState().token = await FirebaseMessaging.instance.getToken();
ApiCallResponse? updToken;
String? deviceToken = await FirebaseMessaging.instance.getToken();
FFAppState().token = deviceToken!;
updToken = await PhpGroup.updToken.call(
token: FFAppState().token,
devid: FFAppState().devUUID,
useruuid: FFAppState().userUUID,
);
if (PhpGroup.updToken.error(
(loginCall.jsonBody ?? ''),
) ==
false) {
debugPrint('Token atualizado com sucesso');
debugPrint("Device Token: $deviceToken");
} else {
debugPrint('Erro ao atualizar token');
}
FFAppState().createdAt = dateTimeFormat( FFAppState().createdAt = dateTimeFormat(
'd/M/y H:mm:ss', 'd/M/y H:mm:ss',
getCurrentTimestamp, getCurrentTimestamp,

View File

@ -1,5 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:f_r_e_hub/app_state.dart';
import 'package:f_r_e_hub/backend/api_requests/api_calls.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart';
@ -135,9 +137,40 @@ class PushNotificationService {
} }
Future<void> _updateDeviceToken() async { Future<void> _updateDeviceToken() async {
String? token = await _firebaseMessaging.getToken(); ApiCallResponse? updToken;
debugPrint('Push Messaging token: $token');
// Send token to your server if required ///
NotificationSettings settings =
await _firebaseMessaging.requestPermission();
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
debugPrint('User granted permission');
String? apnsToken = await _firebaseMessaging.getAPNSToken();
if (apnsToken != null) {
debugPrint('APNS Token: $apnsToken');
} else {
debugPrint('Failed to get APNS token');
}
} else {
debugPrint('User declined or has not accepted permission');
}
String? deviceToken = await FirebaseMessaging.instance.getToken();
FFAppState().token = deviceToken!;
updToken = await PhpGroup.updToken.call(
token: FFAppState().token,
devid: FFAppState().devUUID,
useruuid: FFAppState().userUUID,
);
if (PhpGroup.updToken.error(
(updToken.jsonBody ?? ''),
) ==
false) {
debugPrint('Token atualizado com sucesso');
debugPrint("Device Token: $deviceToken");
} else {
debugPrint('Erro ao atualizar token');
}
debugPrint('Push Messaging token: $deviceToken');
} }
void _showNotification(RemoteMessage message) async { void _showNotification(RemoteMessage message) async {