Skip to content

Commit 0544e1f

Browse files
authored
Fix a bug where cupertino_http did not work on iOS<17. (#1399)
- Fixes #1398
1 parent 8db0d0a commit 0544e1f

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

pkgs/cupertino_http/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.1-wip
2+
3+
* Fix a [bug](https://github.com/dart-lang/http/issues/1398) where
4+
`package:cupertino_http` only worked with iOS 17+.
5+
16
## 2.0.0
27

38
* The behavior of `CupertinoClient` and `CupertinoWebSocket` has not changed.

pkgs/cupertino_http/lib/src/cupertino_api.dart

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -850,24 +850,26 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
850850
}) {
851851
final protoBuilder = objc.ObjCProtocolBuilder();
852852

853-
ncb.NSURLSessionDataDelegate.addToBuilderAsListener(
854-
protoBuilder,
855-
URLSession_task_didCompleteWithError_: (nsSession, nsTask, nsError) {
856-
_decrementTaskCount();
857-
if (onComplete != null) {
858-
onComplete(
859-
URLSession._(nsSession,
860-
isBackground: isBackground, hasDelegate: true),
861-
URLSessionTask._(nsTask),
862-
nsError);
863-
}
864-
},
865-
);
853+
ncb.NSURLSessionDataDelegate.URLSession_task_didCompleteWithError_
854+
.implementAsListener(protoBuilder, (nsSession, nsTask, nsError) {
855+
_decrementTaskCount();
856+
if (onComplete != null) {
857+
onComplete(
858+
URLSession._(nsSession,
859+
isBackground: isBackground, hasDelegate: true),
860+
URLSessionTask._(nsTask),
861+
nsError);
862+
}
863+
});
866864

867865
if (onRedirect != null) {
868-
ncb.NSURLSessionDataDelegate.addToBuilderAsListener(protoBuilder,
866+
ncb
867+
.NSURLSessionDataDelegate
869868
// ignore: lines_longer_than_80_chars
870-
URLSession_task_willPerformHTTPRedirection_newRequest_completionHandler_:
869+
.URLSession_task_willPerformHTTPRedirection_newRequest_completionHandler_
870+
.implementAsListener(protoBuilder,
871+
// ignore: lines_longer_than_80_chars
872+
871873
(nsSession, nsTask, nsResponse, nsRequest, nsRequestCompleter) {
872874
final request = URLRequest._(nsRequest);
873875
URLRequest? redirectRequest;
@@ -891,8 +893,9 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
891893
}
892894

893895
if (onResponse != null) {
894-
ncb.NSURLSessionDataDelegate.addToBuilderAsListener(protoBuilder,
895-
URLSession_dataTask_didReceiveResponse_completionHandler_:
896+
ncb.NSURLSessionDataDelegate
897+
.URLSession_dataTask_didReceiveResponse_completionHandler_
898+
.implementAsListener(protoBuilder,
896899
(nsSession, nsDataTask, nsResponse, nsCompletionHandler) {
897900
final exactResponse = URLResponse._exactURLResponseType(nsResponse);
898901
final disposition = onResponse(
@@ -905,8 +908,8 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
905908
}
906909

907910
if (onData != null) {
908-
ncb.NSURLSessionDataDelegate.addToBuilderAsListener(protoBuilder,
909-
URLSession_dataTask_didReceiveData_: (nsSession, nsDataTask, nsData) {
911+
ncb.NSURLSessionDataDelegate.URLSession_dataTask_didReceiveData_
912+
.implementAsListener(protoBuilder, (nsSession, nsDataTask, nsData) {
910913
onData(
911914
URLSession._(nsSession,
912915
isBackground: isBackground, hasDelegate: true),
@@ -942,9 +945,9 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
942945
}
943946

944947
if (onWebSocketTaskOpened != null) {
945-
ncb.NSURLSessionWebSocketDelegate.addToBuilderAsListener(protoBuilder,
946-
URLSession_webSocketTask_didOpenWithProtocol_:
947-
(nsSession, nsTask, nsProtocol) {
948+
ncb.NSURLSessionWebSocketDelegate
949+
.URLSession_webSocketTask_didOpenWithProtocol_
950+
.implementAsListener(protoBuilder, (nsSession, nsTask, nsProtocol) {
948951
onWebSocketTaskOpened(
949952
URLSession._(nsSession,
950953
isBackground: isBackground, hasDelegate: true),
@@ -954,8 +957,9 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
954957
}
955958

956959
if (onWebSocketTaskClosed != null) {
957-
ncb.NSURLSessionWebSocketDelegate.addToBuilderAsListener(protoBuilder,
958-
URLSession_webSocketTask_didCloseWithCode_reason_:
960+
ncb.NSURLSessionWebSocketDelegate
961+
.URLSession_webSocketTask_didCloseWithCode_reason_
962+
.implementAsListener(protoBuilder,
959963
(nsSession, nsTask, closeCode, reason) {
960964
onWebSocketTaskClosed(
961965
URLSession._(nsSession,

pkgs/cupertino_http/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: cupertino_http
2-
version: 2.0.0
2+
version: 2.0.1-wip
33
description: >-
44
A macOS/iOS Flutter plugin that provides access to the Foundation URL
55
Loading System.

0 commit comments

Comments
 (0)