Posts

Post not yet marked as solved
22 Replies
0 Views
Being bitten by this right now. Does anyone know if this has been fixed in iOS 12?
Post not yet marked as solved
3 Replies
0 Views
Any potential edge cases to watch out for? I'm always a little leery about abusing blind spots created by dynamic dispatch.
Post not yet marked as solved
1 Replies
0 Views
I want to add that the template image in question has zero alpha in it. It's a hairline asset (single pixel (not point!) in either width or height) that I'm trying to utilize instead of code so that I don't risk floating point artifacts when dealing with different screen scales.
Post marked as solved
4 Replies
0 Views
Thanks eskimo, this is really helpful!In regards to my thought on URLProtocol, I had some time last night to take a crack at it (for the sake of science, of course). By the time I was done, I had two thoughts:1. Holy moly, this API needs some love.2. Holy moly, this is pretty slick.It was honestly very cool in the way I was able to hook into the didReceiveChallenge machinery and make it look like a native challenge by URLSession. All the crazy token stuff was handled in the background by the URLProtocol subclass and completely hidden to the user. By the end of my little experiment, the entirety of my front-facing client looked like:let myBaseURL = URL(string: "my-custom-protocol://gateway.myserver.com")! lazy var session: URLSession = { let configuration = URLSessionConfiguration.default configuration.protocolClasses = [MyURLProtocol.self] return URLSession(configuration: configuration, delegate: self, delegateQueue: nil) }() func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { guard challenge.previousFailureCount < 5 else { completionHandler(.cancelAuthenticationChallenge, nil) return } if let proposedCredential = challenge.proposedCredential, proposedCredential.hasPassword { completionHandler(.useCredential, proposedCredential) return } switch challenge.protectionSpace.authenticationMethod { case NSURLAuthenticationMethodDefault where challenge.protectionSpace.protocol == "my-custom-protocol": completionHandler(.useCredential, URLCredential(user: "<username>", password: "<password>", persistence: .permanent)) default: completionHandler(.cancelAuthenticationChallenge, nil) } } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { let url = myBaseURL.appendingPathComponent("/some/data/endpoint/") let task = session.dataTask(with: url) { (data, response, error) in if let result = try? JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments) as? NSDictionary { print(result) } } task.resume() return true }At the same time, the bit-rot is real. URLProtocol was clearly a product of its time and not designed for anything like URLSession in mind. Despite this, I really think there's potential here, so I gotta ask: is there hope for URLProtocol modernization in the near future (perhaps even it getting superceded by a new URLSessionProtocol class), or is the writing on the wall for this API?