0

I'm trying the following code to create a URL:

Approach 1:

let url = URL (string: "https://xxxx-xxxx.com/xxx.html?tokenID=PuUPbFjauRZNPrHQot3Xea70loblCZL3GP9HOrjDP7vTvP3ROWDZrmFJlvKBC1oQ&MobileKey=DE1C-7B19-9CFC83CB83C8||Apple,simulator&widvalue=cl-mobile-dashboard")
let requestObj = URLRequest(url: url!) // <<== error here!

However I'm getting the error

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

Approach 2:

var _request : URLRequest?
if let webViewURL = URL(string: "https://xxxx-xxxx.com/xxx.html?tokenID=PuUPbFjauRZNPrHQot3Xea70loblCZL3GP9HOrjDP7vTvP3ROWDZrmFJlvKBC1oQ&MobileKey=DE1C-7B19-9CFC83CB83C8||Apple,simulator&widvalue=cl-mobile-dashboard") {
    _request = URLRequest(url:webViewURL) // <<== execution not entering this block!!
}

Can anybody please help me with this? Thank you in advance.

as diu
  • 1,010
  • 15
  • 31
  • 1
    Which line is causing the crash exactly? Do you have an error message? – Larme Jan 25 '18 at 16:55
  • 1
    Test the value of the `url` variable instead of using `!` to insist that it's non-nil. – Phillip Mills Jan 25 '18 at 16:58
  • Updated code above with second approach where I'm not forcefully unwrapping.. using optional safely. Can you please help. – as diu Jan 25 '18 at 16:59
  • 2
    Is the url the one you are using there? For me it works fine. – Giuseppe Lanza Jan 25 '18 at 17:00
  • Also worth pointing out that `UIWebView` has been deprecated in favour of `WKWebView`. – Jacob King Jan 25 '18 at 17:24
  • Clearly you are not really using the exact URL posted in your question. Whatever URL you are really using isn't valid. Post the actual URL (but with a fake domain name if desired) you are really using. You probably have one or more characters than need to be escaped properly. – rmaddy Jan 25 '18 at 17:43
  • How are you building that URL? Show that code. Or are you hardcoding that whole string in your code? – rmaddy Jan 25 '18 at 18:02
  • @rmaddy I'm constructing that url based on tokenID from backend and UDID as well as other parameters from a cipher text. I'm just appending all these together. funny part is, it works as if I'm transacting with this device even when I paste it in a web browser on my Mac. Thats why I'm kinda frustrated debugging this. Can you please help me. – as diu Jan 25 '18 at 18:11

0 Answers0