From 4f3a0932d7d54eb5332a3767d788b910a6a750ce Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 19 Dec 2024 11:46:45 -0800 Subject: [PATCH] Push --- .../cupertino_http/lib/src/cupertino_api.dart | 49 ++++++++++++++++++- pkgs/cupertino_http/pubspec.yaml | 1 + 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/pkgs/cupertino_http/lib/src/cupertino_api.dart b/pkgs/cupertino_http/lib/src/cupertino_api.dart index 6f974016b6..fcd59fa0e0 100644 --- a/pkgs/cupertino_http/lib/src/cupertino_api.dart +++ b/pkgs/cupertino_http/lib/src/cupertino_api.dart @@ -29,6 +29,7 @@ library; import 'dart:async'; import 'dart:isolate'; +import 'package:logging/logging.dart'; import 'package:objective_c/objective_c.dart' as objc; import 'native_cupertino_bindings.dart' as ncb; @@ -54,6 +55,8 @@ export 'native_cupertino_bindings.dart' NSURLSessionWebSocketCloseCode, NSURLSessionWebSocketMessageType; +final _logger = Logger('ClassroomApp'); + abstract class _ObjectHolder { final T _nsObject; @@ -850,6 +853,28 @@ class URLSession extends _ObjectHolder { }) { final protoBuilder = objc.ObjCProtocolBuilder(); + final b = + ncb.ObjCBlock_ffiVoid_ffiVoid_NSURLSession_NSURLSessionTask_NSError + .blocking((_, nsSession, nsTask, nsError) { + _logger.severe( + 'Complete: session: ${nsSession.ref.pointer} task: ${nsTask.ref.pointer}'); + _decrementTaskCount(); + if (onComplete != null) { + onComplete( + URLSession._(nsSession, + isBackground: isBackground, hasDelegate: true), + URLSessionTask._(nsTask), + nsError); + } + }); + + final delegate = objc.getProtocol('NSURLSessionTaskDelegate'); + final sel = objc.registerName('URLSession:task:didCompleteWithError:'); + final signature = objc.getProtocolMethodSignature(delegate, sel, + isRequired: false, isInstanceMethod: true)!; + protoBuilder.implementMethod(sel, signature, b); + +/* ncb.NSURLSessionDataDelegate.URLSession_task_didCompleteWithError_ .implementAsListener(protoBuilder, (nsSession, nsTask, nsError) { _decrementTaskCount(); @@ -861,7 +886,7 @@ class URLSession extends _ObjectHolder { nsError); } }); - +*/ if (onRedirect != null) { ncb .NSURLSessionDataDelegate @@ -897,6 +922,9 @@ class URLSession extends _ObjectHolder { ncb.ObjCBlock_ffiVoid_ffiVoid_NSURLSession_NSURLSessionDataTask_NSURLResponse_ffiVoidNSURLSessionResponseDisposition .blocking( (_, nsSession, nsDataTask, nsResponse, nsCompletionHandler) { + _logger.severe( + 'Response: session: ${nsSession.ref.pointer} task: ${nsDataTask.ref.pointer}'); + final exactResponse = URLResponse._exactURLResponseType(nsResponse); final disposition = onResponse( URLSession._(nsSession, @@ -929,6 +957,24 @@ class URLSession extends _ObjectHolder { } if (onData != null) { + final b = + ncb.ObjCBlock_ffiVoid_ffiVoid_NSURLSession_NSURLSessionDataTask_NSData + .blocking((_, nsSession, nsDataTask, nsData) { + _logger.severe( + 'Data: session: ${nsSession.ref.pointer} task: ${nsDataTask.ref.pointer}'); + onData( + URLSession._(nsSession, + isBackground: isBackground, hasDelegate: true), + URLSessionTask._(nsDataTask), + nsData); + }); + final delegate = objc.getProtocol('NSURLSessionDataDelegate'); + final sel = objc.registerName('URLSession:dataTask:didReceiveData:'); + final signature = objc.getProtocolMethodSignature(delegate, sel, + isRequired: false, isInstanceMethod: true)!; + protoBuilder.implementMethod(sel, signature, b); + + /* ncb.NSURLSessionDataDelegate.URLSession_dataTask_didReceiveData_ .implementAsListener(protoBuilder, (nsSession, nsDataTask, nsData) { onData( @@ -937,6 +983,7 @@ class URLSession extends _ObjectHolder { URLSessionTask._(nsDataTask), nsData); }); + */ } if (onFinishedDownloading != null) { diff --git a/pkgs/cupertino_http/pubspec.yaml b/pkgs/cupertino_http/pubspec.yaml index a463092423..1404ab4552 100644 --- a/pkgs/cupertino_http/pubspec.yaml +++ b/pkgs/cupertino_http/pubspec.yaml @@ -16,6 +16,7 @@ dependencies: sdk: flutter http: ^1.2.0 http_profile: ^0.1.0 + logging: ^1.3.0 objective_c: ^4.0.0 web_socket: ^0.1.0