From 3fad6e6b51ceda6a34bccb76d8a9d3a16186ca19 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 7 Jun 2024 00:17:45 +0800 Subject: [PATCH] :sparkles: Use APNs on iOS/macOS --- lib/providers/account.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/providers/account.dart b/lib/providers/account.dart index 39c3423..1daf41d 100644 --- a/lib/providers/account.dart +++ b/lib/providers/account.dart @@ -9,6 +9,7 @@ import 'package:platform_device_id/platform_device_id.dart'; import 'package:solian/models/notification.dart'; import 'package:solian/models/packet.dart'; import 'package:solian/models/pagination.dart'; +import 'package:solian/platform.dart'; import 'package:solian/providers/auth.dart'; import 'package:solian/services.dart'; import 'package:web_socket_channel/io.dart'; @@ -172,14 +173,22 @@ class AccountProvider extends GetxController { final AuthProvider auth = Get.find(); if (!await auth.isAuthorized) throw Exception('unauthorized'); + late final String? token; + late final String provider; final deviceUuid = await PlatformDeviceId.getDeviceId; - final token = await FirebaseMessaging.instance.getToken(); - // TODO On iOS/macOS, using getAPNSToken() instead. + + if (PlatformInfo.isIOS || PlatformInfo.isMacOS) { + provider = "apple"; + token = await FirebaseMessaging.instance.getAPNSToken(); + } else { + provider = "firebase"; + token = await FirebaseMessaging.instance.getToken(); + } final client = auth.configureClient(service: 'passport'); final resp = await client.post('/api/notifications/subscribe', { - 'provider': 'firebase', + 'provider': provider, 'device_token': token, 'device_id': deviceUuid, });