Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkgs/cupertino_http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.1-wip

* Fix a [bug](https://github.com/dart-lang/http/issues/1398) where
`package:cupertino_http` only worked with iOS 17+.

## 2.0.0

* The behavior of `CupertinoClient` and `CupertinoWebSocket` has not changed.
Expand Down
52 changes: 28 additions & 24 deletions pkgs/cupertino_http/lib/src/cupertino_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -850,24 +850,26 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
}) {
final protoBuilder = objc.ObjCProtocolBuilder();

ncb.NSURLSessionDataDelegate.addToBuilderAsListener(
protoBuilder,
URLSession_task_didCompleteWithError_: (nsSession, nsTask, nsError) {
_decrementTaskCount();
if (onComplete != null) {
onComplete(
URLSession._(nsSession,
isBackground: isBackground, hasDelegate: true),
URLSessionTask._(nsTask),
nsError);
}
},
);
ncb.NSURLSessionDataDelegate.URLSession_task_didCompleteWithError_
.implementAsListener(protoBuilder, (nsSession, nsTask, nsError) {
_decrementTaskCount();
if (onComplete != null) {
onComplete(
URLSession._(nsSession,
isBackground: isBackground, hasDelegate: true),
URLSessionTask._(nsTask),
nsError);
}
});

if (onRedirect != null) {
ncb.NSURLSessionDataDelegate.addToBuilderAsListener(protoBuilder,
ncb
.NSURLSessionDataDelegate
// ignore: lines_longer_than_80_chars
URLSession_task_willPerformHTTPRedirection_newRequest_completionHandler_:
.URLSession_task_willPerformHTTPRedirection_newRequest_completionHandler_
.implementAsListener(protoBuilder,
// ignore: lines_longer_than_80_chars

(nsSession, nsTask, nsResponse, nsRequest, nsRequestCompleter) {
final request = URLRequest._(nsRequest);
URLRequest? redirectRequest;
Expand All @@ -891,8 +893,9 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
}

if (onResponse != null) {
ncb.NSURLSessionDataDelegate.addToBuilderAsListener(protoBuilder,
URLSession_dataTask_didReceiveResponse_completionHandler_:
ncb.NSURLSessionDataDelegate
.URLSession_dataTask_didReceiveResponse_completionHandler_
.implementAsListener(protoBuilder,
(nsSession, nsDataTask, nsResponse, nsCompletionHandler) {
final exactResponse = URLResponse._exactURLResponseType(nsResponse);
final disposition = onResponse(
Expand All @@ -905,8 +908,8 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
}

if (onData != null) {
ncb.NSURLSessionDataDelegate.addToBuilderAsListener(protoBuilder,
URLSession_dataTask_didReceiveData_: (nsSession, nsDataTask, nsData) {
ncb.NSURLSessionDataDelegate.URLSession_dataTask_didReceiveData_
.implementAsListener(protoBuilder, (nsSession, nsDataTask, nsData) {
onData(
URLSession._(nsSession,
isBackground: isBackground, hasDelegate: true),
Expand Down Expand Up @@ -942,9 +945,9 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
}

if (onWebSocketTaskOpened != null) {
ncb.NSURLSessionWebSocketDelegate.addToBuilderAsListener(protoBuilder,
URLSession_webSocketTask_didOpenWithProtocol_:
(nsSession, nsTask, nsProtocol) {
ncb.NSURLSessionWebSocketDelegate
.URLSession_webSocketTask_didOpenWithProtocol_
.implementAsListener(protoBuilder, (nsSession, nsTask, nsProtocol) {
onWebSocketTaskOpened(
URLSession._(nsSession,
isBackground: isBackground, hasDelegate: true),
Expand All @@ -954,8 +957,9 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
}

if (onWebSocketTaskClosed != null) {
ncb.NSURLSessionWebSocketDelegate.addToBuilderAsListener(protoBuilder,
URLSession_webSocketTask_didCloseWithCode_reason_:
ncb.NSURLSessionWebSocketDelegate
.URLSession_webSocketTask_didCloseWithCode_reason_
.implementAsListener(protoBuilder,
(nsSession, nsTask, closeCode, reason) {
onWebSocketTaskClosed(
URLSession._(nsSession,
Expand Down
2 changes: 1 addition & 1 deletion pkgs/cupertino_http/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cupertino_http
version: 2.0.0
version: 2.0.1-wip
description: >-
A macOS/iOS Flutter plugin that provides access to the Foundation URL
Loading System.
Expand Down
Loading