Skip to content

Commit 2406bdb

Browse files
0.1.1 (#14)
* use Android Proxy Selector instead or env vars. * use minSDKVersion 31 in example * ios: use min platform version 11.0 for example * fix: use Foundation Lib for executing pac * return error string instead of "Error" * clean code * release 0.1.0 * update: Homepage * modify project details * fix : crash when invalid pac file url * fix: crash when empty pac content
1 parent 5875367 commit 2406bdb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ios/Classes/SwiftFlutterSystemProxyPlugin.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin {
3535
self.handlePacContent(pacContent: pacContent! as String, url: url, callback: callback)
3636
}
3737
downloadPac(pacUrl: pacUrl!, callback: { pacContent,error in
38-
39-
if(error != nil){
38+
39+
if(error != nil || pacContent == nil){
4040
callback(nil,nil)
4141
}else{
4242
self.handlePacContent(pacContent: pacContent!, url: url, callback: callback)
@@ -53,7 +53,7 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin {
5353
}
5454

5555
func handlePacContent(pacContent: String,url: String, callback:(_ host:String?,_ port:Int?)->Void){
56-
let proxies = CFNetworkCopyProxiesForAutoConfigurationScript(pacContent as CFString, CFURLCreateWithString(kCFAllocatorDefault, url as CFString, nil), nil)!.takeUnretainedValue() as? [[CFString: Any]] ?? [];
56+
let proxies = CFNetworkCopyProxiesForAutoConfigurationScript(pacContent as CFString, CFURLCreateWithString(kCFAllocatorDefault, url as CFString, nil), nil)?.takeUnretainedValue() as? [[CFString: Any]] ?? [];
5757
if(proxies.count > 0){
5858
let proxy = proxies.first{$0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTP || $0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTPS}
5959
if(proxy != nil){
@@ -75,8 +75,9 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin {
7575
config.connectionProxyDictionary = [AnyHashable: Any]()
7676
let session = URLSession.init(configuration: config,delegate: nil,delegateQueue: OperationQueue.current)
7777
session.dataTask(with: URL(string: pacUrl)!, completionHandler: { data, response, error in
78-
if(error != nil){
78+
if(error != nil || data == nil){
7979
callback(nil,error)
80+
return;
8081
}
8182
pacContent = String(bytes: data!,encoding: String.Encoding.utf8)!
8283
callback(pacContent,nil)

0 commit comments

Comments
 (0)