diff --git a/example/pubspec.lock b/example/pubspec.lock index 034cff0..38e7991 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -4,11 +4,20 @@ packages: app_group_directory: dependency: transitive description: - name: app_group_directory - sha256: ad89800fd55133b46e1f6940ac6b974562f7fb6394c662c0f4422b90167f2416 + path: "." + ref: HEAD + resolved-ref: "6612fedceab9e75859dbfb0a54365ef812925c6b" + url: "https://github.com/nhathuynh2803/app_group_directory" + source: git + version: "2.0.0" + archive: + dependency: transitive + description: + name: archive + sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "3.6.1" async: dependency: transitive description: @@ -49,6 +58,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.18.0" + crypto: + dependency: transitive + description: + name: crypto + sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27 + url: "https://pub.dev" + source: hosted + version: "3.0.5" cupertino_icons: dependency: "direct main" description: @@ -86,19 +103,19 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.0" - flutter_native_image: - dependency: transitive - description: - name: flutter_native_image - sha256: "0ff23d6222064259df8f85ea56925627ea1ec8658814672c5b6c23fc9174c65e" - url: "https://pub.dev" - source: hosted - version: "0.0.6+1" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + image: + dependency: transitive + description: + name: image + sha256: "2237616a36c0d69aef7549ab439b833fb7f9fb9fc861af2cc9ac3eedddd69ca8" + url: "https://pub.dev" + source: hosted + version: "4.2.0" leak_tracker: dependency: transitive description: @@ -218,6 +235,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.0" + petitparser: + dependency: transitive + description: + name: petitparser + sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 + url: "https://pub.dev" + source: hosted + version: "6.0.2" platform: dependency: transitive description: @@ -287,6 +312,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.2" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" vector_math: dependency: transitive description: @@ -311,6 +344,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.4" + xml: + dependency: transitive + description: + name: xml + sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 + url: "https://pub.dev" + source: hosted + version: "6.5.0" sdks: dart: ">=3.4.0 <4.0.0" flutter: ">=3.22.0" diff --git a/ios/Classes/SwiftLiveActivitiesPlugin.swift b/ios/Classes/SwiftLiveActivitiesPlugin.swift index 6924193..953151c 100644 --- a/ios/Classes/SwiftLiveActivitiesPlugin.swift +++ b/ios/Classes/SwiftLiveActivitiesPlugin.swift @@ -38,7 +38,50 @@ public class SwiftLiveActivitiesPlugin: NSObject, FlutterPlugin, FlutterStreamHa urlSchemeChannel.setStreamHandler(instance) activityStatusChannel.setStreamHandler(instance) registrar.addApplicationDelegate(instance) + + print("LiveActivitiesPlugin is registered TEST123") + if #available(iOS 17.2, *) { + Task { + for await data in Activity.pushToStartTokenUpdates { + let token = data.map {String(format: "%02x", $0)}.joined() + print("Activity PushToStart Token: \(token)") + //send this token to your notification server + + // PushToken über den Flutter Channel senden + channel.invokeMethod("onPushTokenReceived", arguments: token) + } + + for await activity in Activity.activityUpdates { + // Upon finding one, listen for its push token (it is not available immediately!) + for await pushToken in activity.pushTokenUpdates { + let pushTokenString = pushToken.reduce("") { $0 + String(format: "%02x", $1) } + print("New activity detected with push token: \(pushTokenString)") + } + } + } + } + } + + public func getPushToStartToken() { + if #available(iOS 17.2, *) { + Task { + for await data in Activity.pushToStartTokenUpdates { + let token = data.map {String(format: "%02x", $0)}.joined() + print("Activity PushToStart Token: \(token)") + //send this token to your notification server + } + + for await activity in Activity.activityUpdates { + // Upon finding one, listen for its push token (it is not available immediately!) + for await pushToken in activity.pushTokenUpdates { + let pushTokenString = pushToken.reduce("") { $0 + String(format: "%02x", $1) } + print("New activity detected with push token: \(pushTokenString)") + } + } + } + } } + public func detachFromEngine(for registrar: FlutterPluginRegistrar) { urlSchemeSink = nil diff --git a/lib/services/app_groups_image_service.dart b/lib/services/app_groups_image_service.dart index 34b92fd..d63e297 100644 --- a/lib/services/app_groups_image_service.dart +++ b/lib/services/app_groups_image_service.dart @@ -2,9 +2,10 @@ import 'dart:io'; import 'dart:ui'; import 'package:app_group_directory/app_group_directory.dart'; -import 'package:flutter_native_image/flutter_native_image.dart'; import 'package:live_activities/models/live_activity_image.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:image/image.dart' as img; + const kPictureFolderName = 'LiveActivitiesPictures'; @@ -59,11 +60,13 @@ class AppGroupsImageService { final targetWidth = (imageWidth * value.resizeFactor).round(); - file = await FlutterNativeImage.compressImage( + /*file = await FlutterNativeImage.compressImage( file.path, targetWidth: targetWidth, targetHeight: (imageHeight * targetWidth / imageWidth).round(), - ); + );*/ + + file = await compressImage(file, targetWidth); } final finalDestination = '${appGroupPicture.path}/$fileName'; @@ -94,3 +97,28 @@ class AppGroupsImageService { } } } +Future compressImage(File file, int targetWidth) async { + // Lade das Bild von der Datei + final bytes = await file.readAsBytes(); + final image = img.decodeImage(bytes); + + if (image == null) { + throw Exception("Das Bild konnte nicht geladen werden."); + } + + // Berechne die Zielhöhe basierend auf den Bilddimensionen + final imageWidth = image.width; + final imageHeight = image.height; + final targetHeight = (imageHeight * targetWidth / imageWidth).round(); + + // Skaliere das Bild auf die Zielgröße + final resizedImage = img.copyResize(image, width: targetWidth, height: targetHeight); + + // Komprimiere das Bild als JPEG + final compressedBytes = img.encodeJpg(resizedImage, quality: 85); + + // Speichere das komprimierte Bild in einer neuen Datei + final compressedFile = File(file.path)..writeAsBytesSync(compressedBytes); + + return compressedFile; +} diff --git a/pubspec.yaml b/pubspec.yaml index 7ec1c55..b27fed2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,9 +24,10 @@ dependencies: flutter: sdk: flutter plugin_platform_interface: ^2.1.8 - app_group_directory: ^2.0.0 + app_group_directory: + git: https://github.com/SnapDrive/app_group_directory path_provider: ^2.1.4 - flutter_native_image: ^0.0.6+1 + image: ^4.2.0 dev_dependencies: flutter_test: