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

@@ -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);
}