Skip to content

Commit c42aa85

Browse files
authored
Merge pull request #23 from BrowserStackCE/backward-compat-xcode15
add: backward compatibility for <= Xcode15
2 parents a2ebbf5 + b398194 commit c42aa85

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:4.1.0'
11+
classpath 'com.android.tools.build:gradle:8.6.0'
1212
}
1313
}
1414

@@ -23,7 +23,7 @@ apply plugin: 'com.android.library'
2323

2424
android {
2525
namespace 'com.browserstack.fluttersystemproxy.flutter_system_proxy'
26-
compileSdkVersion 30
26+
compileSdkVersion 35
2727

2828
defaultConfig {
2929
minSdkVersion 16

example/android/app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ apply plugin: 'com.android.application'
2525
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2626

2727
android {
28-
compileSdkVersion 31
29-
28+
compileSdkVersion 35
29+
namespace "com.browserstack.fluttersystemproxy.flutter_system_proxy_example"
3030
defaultConfig {
3131
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3232
applicationId "com.browserstack.fluttersystemproxy.flutter_system_proxy_example"
33-
minSdkVersion 16
33+
minSdkVersion flutter.minSdkVersion
3434
targetSdkVersion 30
3535
versionCode flutterVersionCode.toInteger()
3636
versionName flutterVersionName

example/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:4.1.0'
8+
classpath 'com.android.tools.build:gradle:8.6.0'
99
}
1010
}
1111

@@ -22,6 +22,6 @@ subprojects {
2222
project.evaluationDependsOn(':app')
2323
}
2424

25-
task clean(type: Delete) {
25+
tasks.register("clean", Delete) {
2626
delete rootProject.buildDir
2727
}

ios/Classes/SwiftFlutterSystemProxyPlugin.swift

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,20 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin {
4141
if(SwiftFlutterSystemProxyPlugin.proxyCache[url] != nil){
4242
return SwiftFlutterSystemProxyPlugin.proxyCache[url]
4343
}
44-
let proxConfigDict = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() as NSDictionary?
45-
if(proxConfigDict != nil){
46-
if(proxConfigDict!["ProxyAutoConfigEnable"] as? Int == 1){
47-
let pacUrl = proxConfigDict!["ProxyAutoConfigURLString"] as? String
48-
let pacContent = proxConfigDict!["ProxyAutoConfigJavaScript"] as? String
44+
let proxConfigDict = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() as NSDictionary?
45+
if proxConfigDict != nil {
46+
if(proxConfigDict?[kCFNetworkProxiesProxyAutoConfigEnable] as? Int == 1){
47+
let pacUrl = proxConfigDict?[kCFNetworkProxiesProxyAutoConfigURLString] as! String?
48+
let pacContent = proxConfigDict?[kCFNetworkProxiesProxyAutoConfigJavaScript] as! String?
4949
if(pacContent != nil){
50-
self.handlePacContent(pacContent: pacContent! as String, url: url)
50+
self.handlePacContent(pacContent: pacContent!, url: url)
5151
}else if(pacUrl != nil){
5252
self.handlePacUrl(pacUrl: pacUrl!,url: url)
5353
}
54-
} else if (proxConfigDict!["HTTPEnable"] as? Int == 1){
54+
} else if (proxConfigDict![kCFNetworkProxiesHTTPEnable] as? Int == 1){
5555
var dict: [String: Any] = [:]
56-
dict["host"] = proxConfigDict!["HTTPProxy"] as? String
57-
dict["port"] = proxConfigDict!["HTTPPort"] as? Int
58-
SwiftFlutterSystemProxyPlugin.proxyCache[url] = dict
59-
60-
} else if ( proxConfigDict!["HTTPSEnable"] as? Int == 1){
61-
var dict: [String: Any] = [:]
62-
dict["host"] = proxConfigDict!["HTTPSProxy"] as? String
63-
dict["port"] = proxConfigDict!["HTTPSPort"] as? Int
56+
dict["host"] = proxConfigDict![kCFNetworkProxiesHTTPProxy] as? String
57+
dict["port"] = proxConfigDict![kCFNetworkProxiesHTTPPort] as? Int
6458
SwiftFlutterSystemProxyPlugin.proxyCache[url] = dict
6559
}
6660
}
@@ -105,11 +99,20 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin {
10599
CFRunLoopStop(CFRunLoopGetCurrent());
106100
}, &context);
107101
let runLoop = CFRunLoopGetCurrent();
108-
CFRunLoopAddSource(runLoop, runLoopSource, CFRunLoopMode.defaultMode);
102+
CFRunLoopAddSource(runLoop, getRunLoopSource(runLoopSource), CFRunLoopMode.defaultMode);
109103
CFRunLoopRun();
110-
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runLoopSource, CFRunLoopMode.defaultMode);
104+
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), getRunLoopSource(runLoopSource), CFRunLoopMode.defaultMode);
111105
})
112106
}
113107

108+
//For backward compatibility <= XCode 15
109+
static func getRunLoopSource<T>(_ runLoopSource: T) -> CFRunLoopSource {
110+
if let unmanagedValue = runLoopSource as? Unmanaged<CFRunLoopSource> {
111+
return unmanagedValue.takeUnretainedValue()
112+
} else {
113+
return runLoopSource as! CFRunLoopSource
114+
}
115+
}
116+
114117
}
115118

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_system_proxy
22
description: A Flutter Plugin to detect System proxy. When using HTTP client that are not proxy aware this plugin can help with finding the proxy from system settings which then can be used with HTTP Client to make a successful request.
3-
version: 0.1.4
3+
version: 0.1.5
44
homepage: https://github.com/BrowserStackCE/flutter_system_proxy.git
55

66
environment:

0 commit comments

Comments
 (0)