feat(ios): add iOS 26+ continued processing and Live Activities (#1514)

This commit is contained in:
UltraGeek0102 authored and GitHub committed 2026-09-15 22:49:11 +08:00
1 parent cee5f3336e
commit e47a20a1bd
18 files changed
+2983 -3

No files matched your search

+63 -2
View File
@@ -63,8 +63,19 @@ import UIKit
GopeedInvokeAsyncWithResult(method, path, query, body, requestID, result)
case "subscribeTaskEvents":
let arguments = call.arguments as? [String: Any]
let mask = (arguments?["mask"] as? NSNumber)?.int64Value ?? 0
GopeedSubscribeTaskEventsWithForwarder(mask, mask == 0 ? nil : taskEventForwarder)
let flutterMask =
(arguments?["mask"] as? NSNumber)?.int64Value ?? 0
let liveActivityMask =
LibgopeedLiveActivityTaskEventMask()
let combinedMask =
flutterMask | liveActivityMask
GopeedSubscribeTaskEventsWithForwarder(
combinedMask,
taskEventForwarder
)
result(nil)
default:
result(FlutterMethodNotImplemented)
@@ -91,5 +102,55 @@ import UIKit
result(FlutterMethodNotImplemented)
}
}
let continuedProcessingChannel =
FlutterMethodChannel(
name: "gopeed/continued_processing",
binaryMessenger: messenger
)
continuedProcessingChannel
.setMethodCallHandler { call, result in
switch call.method {
case "isSupported":
if #available(iOS 26.0, *) {
result(true)
} else {
result(false)
}
case "setEnabled":
let arguments =
call.arguments
as? [String: Any]
let enabled =
arguments?["enabled"]
as? Bool
?? false
if #available(iOS 26.0, *) {
GopeedContinuedProcessingManager
.shared
.setEnabled(enabled) {
success in
result(success)
}
} else {
result(!enabled)
}
default:
result(
FlutterMethodNotImplemented
)
}
}
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,28 @@
import ActivityKit
import Foundation
@available(iOS 16.2, *)
struct GopeedDownloadAttributes: ActivityAttributes {
struct ContentState: Codable, Hashable {
// Real confirmed progress.
var progress: Double
var downloaded: Int64
var total: Int64
var speed: Int64
var status: String
// Used by the self-moving estimated progress bar.
var estimatedStart: Date
var estimatedEnd: Date
var usesEstimatedProgress: Bool
}
// Static properties.
var taskId: String
var fileName: String
var generation: String
}
File diff suppressed because it is too large. Load diff
@@ -13,6 +13,18 @@ FOUNDATION_EXPORT void GopeedSubscribeTaskEventsWithForwarder(
int64_t mask,
GopeedTaskEventForwarder * _Nullable listener);
typedef void (^GopeedNativeInvokeCompletion)(
BOOL success,
NSString *payload);
FOUNDATION_EXPORT void GopeedInvokeAsyncNative(
NSString *method,
NSString *path,
NSString *query,
NSString *body,
GopeedNativeInvokeCompletion completion);
FOUNDATION_EXPORT void GopeedInvokeAsyncWithResult(
NSString *method,
NSString *path,
@@ -2,6 +2,8 @@
#import <Libgopeed/Libgopeed.h>
#import "Runner-Swift.h"
@interface GopeedTaskEventForwarder () <LibgopeedTaskEventListener>
@property(nonatomic, strong) FlutterMethodChannel *channel;
@@ -47,6 +49,45 @@
@end
@interface GopeedNativeInvokeResultForwarder
: NSObject <LibgopeedInvokeResultListener>
@property(nonatomic, copy, nullable)
GopeedNativeInvokeCompletion completion;
- (instancetype)initWithCompletion:
(GopeedNativeInvokeCompletion)completion;
@end
@implementation GopeedNativeInvokeResultForwarder
- (instancetype)initWithCompletion:
(GopeedNativeInvokeCompletion)completion {
self = [super init];
if (self) {
_completion = [completion copy];
}
return self;
}
- (void)onResult:(int64_t)requestID
success:(BOOL)success
payload:(NSString * _Nullable)payload {
GopeedNativeInvokeCompletion completion =
self.completion;
self.completion = nil;
if (completion == nil) {
return;
}
completion(success, payload ?: @"");
}
@end
@implementation GopeedTaskEventForwarder
- (instancetype)initWithChannel:(FlutterMethodChannel *)channel {
@@ -59,9 +100,59 @@
- (void)onTaskEvent:(NSString * _Nullable)payload {
NSString *arguments = payload ?: @"";
NSData *data =
[arguments dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = nil;
if (data) {
json =
[NSJSONSerialization JSONObjectWithData:data
options:0
error:nil];
}
NSString *type = json[@"type"];
NSString *taskID = json[@"taskId"];
BOOL continuedProcessingHandlesTask = NO;
// iOS 26 system continued-processing Live Activity.
if (@available(iOS 26.0, *)) {
GopeedContinuedProcessingManager *manager =
[GopeedContinuedProcessingManager shared];
[manager handleTaskEventPayload:arguments];
if (taskID.length > 0) {
continuedProcessingHandlesTask =
[manager isHandlingTaskId:taskID];
}
}
// When BGCPT is active, let Apple's system Live Activity
// represent progress. Otherwise keep using our existing
// custom Gopeed ActivityKit implementation.
if (!continuedProcessingHandlesTask) {
[[GopeedLiveActivityManager shared]
handleTaskEventPayload:arguments];
}
// Flutter currently understands only done/error.
BOOL flutterEvent =
[type isEqualToString:@"task.done"] ||
[type isEqualToString:@"task.error"];
if (!flutterEvent) {
return;
}
FlutterMethodChannel *channel = self.channel;
dispatch_async(dispatch_get_main_queue(), ^{
[channel invokeMethod:@"taskEvent" arguments:arguments];
[channel invokeMethod:@"taskEvent"
arguments:arguments];
});
}
@@ -84,3 +175,26 @@ void GopeedInvokeAsyncWithResult(
[[GopeedInvokeResultForwarder alloc] initWithResult:result];
LibgopeedInvokeAsync(method, path, query, body, requestID, forwarder);
}
void GopeedInvokeAsyncNative(
NSString *method,
NSString *path,
NSString *query,
NSString *body,
GopeedNativeInvokeCompletion completion) {
if (completion == nil) {
return;
}
GopeedNativeInvokeResultForwarder *forwarder =
[[GopeedNativeInvokeResultForwarder alloc]
initWithCompletion:completion];
LibgopeedInvokeAsync(
method,
path,
query,
body,
0,
forwarder);
}
+10
View File
@@ -115,6 +115,7 @@
<key>UIBackgroundModes</key>
<array>
<string>location</string>
<string>processing</string>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
@@ -156,5 +157,14 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSSupportsLiveActivities</key>
<true/>
<key>NSSupportsLiveActivitiesFrequentUpdates</key>
<true/>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).continuedDownload.*</string>
</array>
</dict>
</plist>