From ebf66a043f57dd0cf06adec389eaf525429575a4 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Tue, 21 Dec 2021 16:17:55 +0100 Subject: [PATCH] meow meow --- .../Fluffychat Notifications.entitlements | 12 ++ ios/Fluffychat Notifications/Info.plist | 13 ++ .../NotificationService.swift | 39 ++++ ios/Runner.xcodeproj/project.pbxproj | 197 +++++++++++++++++- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- ios/Runner/Info.plist | 2 + lib/config/app_config.dart | 2 +- lib/utils/background_push.dart | 55 ++++- pubspec.yaml | 3 +- 9 files changed, 313 insertions(+), 12 deletions(-) create mode 100644 ios/Fluffychat Notifications/Fluffychat Notifications.entitlements create mode 100644 ios/Fluffychat Notifications/Info.plist create mode 100644 ios/Fluffychat Notifications/NotificationService.swift diff --git a/ios/Fluffychat Notifications/Fluffychat Notifications.entitlements b/ios/Fluffychat Notifications/Fluffychat Notifications.entitlements new file mode 100644 index 00000000..e29844f4 --- /dev/null +++ b/ios/Fluffychat Notifications/Fluffychat Notifications.entitlements @@ -0,0 +1,12 @@ + + + + + aps-environment + development + com.apple.security.application-groups + + group.im.fluffychat.app + + + diff --git a/ios/Fluffychat Notifications/Info.plist b/ios/Fluffychat Notifications/Info.plist new file mode 100644 index 00000000..57421ebf --- /dev/null +++ b/ios/Fluffychat Notifications/Info.plist @@ -0,0 +1,13 @@ + + + + + NSExtension + + NSExtensionPointIdentifier + com.apple.usernotifications.service + NSExtensionPrincipalClass + $(PRODUCT_MODULE_NAME).NotificationService + + + diff --git a/ios/Fluffychat Notifications/NotificationService.swift b/ios/Fluffychat Notifications/NotificationService.swift new file mode 100644 index 00000000..234d505a --- /dev/null +++ b/ios/Fluffychat Notifications/NotificationService.swift @@ -0,0 +1,39 @@ +// +// NotificationService.swift +// Fluffychat Notifications +// +// Created by Sorunome on 20.12.2021. +// + +import UserNotifications + +class NotificationService: UNNotificationServiceExtension { + + var contentHandler: ((UNNotificationContent) -> Void)? + var bestAttemptContent: UNMutableNotificationContent? + + override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { + self.contentHandler = contentHandler + bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) + + print("=====================") + print("RECEIVED NOTIF") + print("\(bestAttemptContent)") + + if let bestAttemptContent = bestAttemptContent { + // Modify the notification content here... + bestAttemptContent.title = "[modified] \(bestAttemptContent.title)" + + contentHandler(bestAttemptContent) + } + } + + override func serviceExtensionTimeWillExpire() { + // Called just before the extension will be terminated by the system. + // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. + if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { + contentHandler(bestAttemptContent) + } + } + +} diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 12664c42..6829cbac 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 7295DBEF27709370004ECA76 /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7295DBEE27709370004ECA76 /* NotificationService.swift */; }; + 7295DBF327709370004ECA76 /* Fluffychat Notifications.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 7295DBEC27709370004ECA76 /* Fluffychat Notifications.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; @@ -21,6 +23,13 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 7295DBF127709370004ECA76 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 97C146E61CF9000F007C117D /* Project object */; + proxyType = 1; + remoteGlobalIDString = 7295DBEB27709370004ECA76; + remoteInfo = "Fluffychat Notifications"; + }; C1005C4A261071B5002F4F32 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 97C146E61CF9000F007C117D /* Project object */; @@ -47,6 +56,7 @@ dstPath = ""; dstSubfolderSpec = 13; files = ( + 7295DBF327709370004ECA76 /* Fluffychat Notifications.appex in Embed App Extensions */, C1005C4C261071B5002F4F32 /* FluffyChat Share.appex in Embed App Extensions */, ); name = "Embed App Extensions"; @@ -59,6 +69,10 @@ 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 50DEFC207B70632D9C56ED78 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 72339A3227733E680084AF75 /* Fluffychat Notifications.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Fluffychat Notifications.entitlements"; sourceTree = ""; }; + 7295DBEC27709370004ECA76 /* Fluffychat Notifications.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Fluffychat Notifications.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; + 7295DBEE27709370004ECA76 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = ""; }; + 7295DBF027709370004ECA76 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 76737C9A857D5FD6D2634A3F /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; @@ -82,6 +96,13 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 7295DBE927709370004ECA76 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 97C146EB1CF9000F007C117D /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -108,6 +129,16 @@ name = Frameworks; sourceTree = ""; }; + 7295DBED27709370004ECA76 /* Fluffychat Notifications */ = { + isa = PBXGroup; + children = ( + 72339A3227733E680084AF75 /* Fluffychat Notifications.entitlements */, + 7295DBEE27709370004ECA76 /* NotificationService.swift */, + 7295DBF027709370004ECA76 /* Info.plist */, + ); + path = "Fluffychat Notifications"; + sourceTree = ""; + }; 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( @@ -125,6 +156,7 @@ 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, C1005C43261071B5002F4F32 /* FluffyChat Share */, + 7295DBED27709370004ECA76 /* Fluffychat Notifications */, 97C146EF1CF9000F007C117D /* Products */, E89DCAC000D371640E94E65B /* Pods */, 075EE1BE25359E34308E0B78 /* Frameworks */, @@ -136,6 +168,7 @@ children = ( 97C146EE1CF9000F007C117D /* Runner.app */, C1005C42261071B5002F4F32 /* FluffyChat Share.appex */, + 7295DBEC27709370004ECA76 /* Fluffychat Notifications.appex */, ); name = Products; sourceTree = ""; @@ -181,6 +214,23 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 7295DBEB27709370004ECA76 /* Fluffychat Notifications */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7295DBF727709370004ECA76 /* Build configuration list for PBXNativeTarget "Fluffychat Notifications" */; + buildPhases = ( + 7295DBE827709370004ECA76 /* Sources */, + 7295DBE927709370004ECA76 /* Frameworks */, + 7295DBEA27709370004ECA76 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Fluffychat Notifications"; + productName = "Fluffychat Notifications"; + productReference = 7295DBEC27709370004ECA76 /* Fluffychat Notifications.appex */; + productType = "com.apple.product-type.app-extension"; + }; 97C146ED1CF9000F007C117D /* Runner */ = { isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; @@ -199,6 +249,7 @@ ); dependencies = ( C1005C4B261071B5002F4F32 /* PBXTargetDependency */, + 7295DBF227709370004ECA76 /* PBXTargetDependency */, ); name = Runner; productName = Runner; @@ -228,10 +279,13 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 1240; - LastUpgradeCheck = 1020; + LastSwiftUpdateCheck = 1320; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = ""; TargetAttributes = { + 7295DBEB27709370004ECA76 = { + CreatedOnToolsVersion = 13.2; + }; 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; LastSwiftMigration = 1100; @@ -256,11 +310,19 @@ targets = ( 97C146ED1CF9000F007C117D /* Runner */, C1005C41261071B5002F4F32 /* FluffyChat Share */, + 7295DBEB27709370004ECA76 /* Fluffychat Notifications */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 7295DBEA27709370004ECA76 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 97C146EC1CF9000F007C117D /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -354,6 +416,14 @@ /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 7295DBE827709370004ECA76 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7295DBEF27709370004ECA76 /* NotificationService.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 97C146EA1CF9000F007C117D /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -374,6 +444,11 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 7295DBF227709370004ECA76 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 7295DBEB27709370004ECA76 /* Fluffychat Notifications */; + targetProxy = 7295DBF127709370004ECA76 /* PBXContainerItemProxy */; + }; C1005C4B261071B5002F4F32 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = C1005C41261071B5002F4F32 /* FluffyChat Share */; @@ -492,6 +567,114 @@ }; name = Profile; }; + 7295DBF427709370004ECA76 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_ENTITLEMENTS = "Fluffychat Notifications/Fluffychat Notifications.entitlements"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 4NXF6Z997G; + GCC_C_LANGUAGE_STANDARD = gnu11; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = "Fluffychat Notifications/Info.plist"; + INFOPLIST_KEY_CFBundleDisplayName = "Fluffychat Notifications"; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + IPHONEOS_DEPLOYMENT_TARGET = 15.2; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", + ); + MARKETING_VERSION = 1.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "im.fluffychat.app.Fluffychat-Notifications"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 7295DBF527709370004ECA76 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_ENTITLEMENTS = "Fluffychat Notifications/Fluffychat Notifications.entitlements"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 4NXF6Z997G; + GCC_C_LANGUAGE_STANDARD = gnu11; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = "Fluffychat Notifications/Info.plist"; + INFOPLIST_KEY_CFBundleDisplayName = "Fluffychat Notifications"; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + IPHONEOS_DEPLOYMENT_TARGET = 15.2; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", + ); + MARKETING_VERSION = 1.0; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "im.fluffychat.app.Fluffychat-Notifications"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 7295DBF627709370004ECA76 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_ENTITLEMENTS = "Fluffychat Notifications/Fluffychat Notifications.entitlements"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 4NXF6Z997G; + GCC_C_LANGUAGE_STANDARD = gnu11; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = "Fluffychat Notifications/Info.plist"; + INFOPLIST_KEY_CFBundleDisplayName = "Fluffychat Notifications"; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + IPHONEOS_DEPLOYMENT_TARGET = 15.2; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", + ); + MARKETING_VERSION = 1.0; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "im.fluffychat.app.Fluffychat-Notifications"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Profile; + }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -765,6 +948,16 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 7295DBF727709370004ECA76 /* Build configuration list for PBXNativeTarget "Fluffychat Notifications" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7295DBF427709370004ECA76 /* Debug */, + 7295DBF527709370004ECA76 /* Release */, + 7295DBF627709370004ECA76 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a28140cf..3db53b6e 100644 --- a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ NSAllowsArbitraryLoads + flutter_apns.disable_swizzling + diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart index 459fd7f2..7e31595b 100644 --- a/lib/config/app_config.dart +++ b/lib/config/app_config.dart @@ -51,7 +51,7 @@ abstract class AppConfig { 'Push notifications for FluffyChat'; static const String pushNotificationsAppId = 'chat.fluffy.fluffychat'; static const String pushNotificationsGatewayUrl = - 'https://push.fluffychat.im/_matrix/push/v1/notify'; + 'https://luckyskies.pet/_matrix/push/v1/notify'; static const String pushNotificationsPusherFormat = 'event_id_only'; static const String emojiFontName = 'Noto Emoji'; static const String emojiFontUrl = diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index 4fb75d0b..dbc5a511 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -32,6 +32,7 @@ import 'package:http/http.dart' as http; import 'package:matrix/matrix.dart'; import 'package:unifiedpush/unifiedpush.dart' hide Message; import 'package:vrouter/vrouter.dart'; +import 'package:flutter_apns_only/flutter_apns_only.dart'; import '../config/app_config.dart'; import '../config/setting_keys.dart'; @@ -57,6 +58,7 @@ class BackgroundPush { L10n l10n; Store _store; Store get store => _store ??= Store(); + final _apnsPushConnector = ApnsPushConnectorOnly(); Future loadLocale() async { // inspired by _lookupL10n in .dart_tool/flutter_gen/gen_l10n/l10n.dart l10n ??= (context != null ? L10n.of(context) : null) ?? @@ -74,11 +76,11 @@ class BackgroundPush { onRoomSync ??= client.onSync.stream .where((s) => s.hasRoomUpdate) .listen((s) => _onClearingPush(getFromServer: false)); - _fcmSharedIsolate?.setListeners( - onMessage: _onFcmMessage, - onNewToken: _newFcmToken, - ); if (Platform.isAndroid) { + _fcmSharedIsolate?.setListeners( + onMessage: _onFcmMessage, + onNewToken: _newFcmToken, + ); UnifiedPush.initializeWithReceiver( onNewEndpoint: _newUpEndpoint, onRegistrationFailed: _upUnregistered, @@ -127,9 +129,6 @@ class BackgroundPush { Set oldTokens, bool useDeviceSpecificAppId = false, }) async { - if (PlatformInfos.isIOS) { - await _fcmSharedIsolate?.requestPermission(); - } final clientName = PlatformInfos.clientName; // Just the plain app id, we add the .data_message suffix later var appId = AppConfig.pushNotificationsAppId; @@ -143,8 +142,12 @@ class BackgroundPush { if (!useDeviceSpecificAppId && PlatformInfos.isAndroid) { appId += '.data_message'; } + if (PlatformInfos.isIOS) { + appId = 'chat.fluffy.fluffychat.apns.data_message'; + } final thisAppId = useDeviceSpecificAppId ? deviceAppId : appId; await client.setupPusher( + allowEncryption: false, oldTokens: oldTokens, pusher: Pusher( pushkey: token, @@ -173,6 +176,8 @@ class BackgroundPush { if (!PlatformInfos.isIOS && (await UnifiedPush.getDistributors()).isNotEmpty) { await setupUp(); + } else if (PlatformInfos.isIOS) { + await setupApns(); } else { await setupFirebase(); } @@ -214,6 +219,42 @@ class BackgroundPush { } } + Future setupApns() async { + Logs().v('[Push] Setup apns'); + // remove any old fcm tokens +/* final oldTokens = {}; + try { + print('before'); + final fcmToken = await _fcmSharedIsolate?.getToken(); + print('after'); + print(fcmToken); + oldTokens.add(fcmToken); + } catch (_) {}*/ + + final completer = Completer(); + _apnsPushConnector.token.addListener(completer.complete); + _apnsPushConnector.configureApns(); + _apnsPushConnector.requestNotificationPermissions(); + // TODO: listen to authorizationStatus changes + try { + await completer.future.timeout(Duration(seconds: 2)); + } catch (_) { + // do nothing + } + final apnsToken = _apnsPushConnector.token.value; + if (apnsToken == null) { + Logs().w('[Push] apns token is null'); + return; + } + print(apnsToken); + + await setupPusher( + gatewayUrl: AppConfig.pushNotificationsGatewayUrl, + token: apnsToken, + //oldTokens: oldTokens, + ); + } + Future setupFirebase() async { Logs().v('Setup firebase'); if (_fcmToken?.isEmpty ?? true) { diff --git a/pubspec.yaml b/pubspec.yaml index bd13fd80..23f5ad05 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,6 +24,7 @@ dependencies: file_picker_cross: ^4.5.0 flutter: sdk: flutter + flutter_apns_only: ^1.5.0 flutter_app_badger: ^1.3.0 flutter_app_lock: ^2.0.0 flutter_blurhash: ^0.6.0 @@ -50,7 +51,7 @@ dependencies: lottie: ^1.2.1 #matrix: ^0.7.0 matrix: - path: /home/sorunome/repos/famedly/famedlysdk + path: ../famedly/frontend/famedlysdk matrix_link_text: ^1.0.2 open_noti_settings: ^0.3.0 package_info_plus: ^1.2.1