Skip to content

Commit

Permalink
0.1.1 (#14)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Rushabhshroff authored Oct 9, 2023
1 parent 5875367 commit 2406bdb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ios/Classes/SwiftFlutterSystemProxyPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin {
self.handlePacContent(pacContent: pacContent! as String, url: url, callback: callback)
}
downloadPac(pacUrl: pacUrl!, callback: { pacContent,error in
if(error != nil){

if(error != nil || pacContent == nil){
callback(nil,nil)
}else{
self.handlePacContent(pacContent: pacContent!, url: url, callback: callback)
Expand All @@ -53,7 +53,7 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin {
}

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

0 comments on commit 2406bdb

Please sign in to comment.