move update token to homepage adn get APNSToken
This commit is contained in:
parent
44a8f84477
commit
29f82e89f9
|
@ -121,23 +121,6 @@ Future singInActionApp(
|
|||
(loginCall.jsonBody ?? ''),
|
||||
)!;
|
||||
// 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(
|
||||
'd/M/y H:mm:ss',
|
||||
getCurrentTimestamp,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import 'dart:async';
|
||||
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:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
|
@ -135,9 +137,40 @@ class PushNotificationService {
|
|||
}
|
||||
|
||||
Future<void> _updateDeviceToken() async {
|
||||
String? token = await _firebaseMessaging.getToken();
|
||||
debugPrint('Push Messaging token: $token');
|
||||
// Send token to your server if required
|
||||
ApiCallResponse? updToken;
|
||||
|
||||
///
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue