I'm trying to call a URL using URLSession to log out of an oauth2 session in swift in an iOS app.
The URL is something like this:
Why doesn't swift like "myapp://" or (myapp%3A%2F%2F) being a query string parameter?
Stack Overflow Question
The URL is something like this:
Notice that some parameters are URL Encoded*
Code Block https://xxxxxx.auth.us-east-1.amazoncognito.com/logout?client_id=49jaf4a848hakh&logout_uri=myapp%3A%2F%2F&redirect_uri=myapp%3A%2F%2F&response_type=token
I get a run time error using this URL in a data task that says:*
Code Block Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSUnderlyingError=0x60000202ccf0 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "(null)"}, NSErrorFailingURLStringKey=myapp://, NSErrorFailingURLKey=myapp://, NSLocalizedDescription=unsupported URL}
I already have "myapp" in my info.plist.*
Code Block <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLName</key> <string>com.***.yyy</string> <key>CFBundleURLSchemes</key> <array> <string>myapp</string> </array> </dict> </array>
Below is the code to execute this simple URLSession data task*
Code Block let s = URLSession.shared let u = URL(string: "https://***.yyy.auth.us-east-1.amazoncognito.com/logout?client_id=7c2aqa0fibv51v8valq6pagtoq&logout_uri=myapp%3A%2F%2F&redirect_uri=myapp%3A%2F%2F&response_type=token")! let t = s.dataTask(with: u) { (d: Data?, r: URLResponse?, e:Error?) in if e != nil { print("error: \(e)") } let decoded = String(data: d!, encoding: .utf8) print("Data: \(decoded)") print("url Response: \(r)") print("Breakpoint") }.resume()
I've tried with both URL strings below and still get the same error*
Code Block let u = URL(string: "https://***.yyy.auth.us-east-1.amazoncognito.com/logout?client_id=7c2aqa0fibv51v8valq6pagtoq&logout_uri=myapp%3A%2F%2F&redirect_uri=myapp%3A%2F%2F&response_type=token")! let u = URL(string: "https://***.yyy.auth.us-east-1.amazoncognito.com/logout?client_id=7c2aqa0fibv51v8valq6pagtoq&logout_uri=myapp://&redirect_uri=myapp://&response_type=token")!
Why doesn't swift like "myapp://" or (myapp%3A%2F%2F) being a query string parameter?
Stack Overflow Question