@@ -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
0 commit comments