Fails to open URL

1.5k Views Asked by At

I've got the following code:

let reachUrl = "https://helpers.pythonanywhere.com/load-data/announcements?key=\(key)&data=[\"\(nameTF.text!)\", \"\(infoTF.text!)\", \"\(pickerView.selectedRow(inComponent: 0))\"]"
        
UIApplication.shared.open(URL(string: reachUrl.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!)!)

The error I get is

Failed to open URL https%3A%2F%2Fhelpers%2Epythonanywhere%2Ecom%2Fload%2Ddata%2Fannouncements%3Fkey%3D3409298423076318kk%2B8i%26data%3D%5Bff%2C%2 ... C%201%5D: Error Domain=NSOSStatusErrorDomain Code=-50 "invalid input parameters" UserInfo={NSDebugDescription=invalid input parameters, _LSLine=234, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}

The error is only shown in console, nothing is done within the app itself.

I'm wondering what's the matter. Thanks for any help

1

There are 1 best solutions below

0
Prateek Varshney On

I see what the problem is, can you please try the code below and let me know if it works.

let reachUrl = "https://helpers.pythonanywhere.com/load-data/announcements?key=\(key)&data=[\"\(nameTF.text!)\", \"\(infoTF.text!)\", \"\(pickerView.selectedRow(inComponent: 0))\"]"
        
UIApplication.shared.open(URL(string: reachUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)!)

Thanks, Happy Coding.