2

I need to open an external link in Safari to a page but the server I'm hitting with the url requires that I need to verify the IP address in a header. How can I pass header data in with UIApplication.shared.open?

There's an option parameter but I can't find any examples or documentation if this is the correct parameter to use to pass header data like ['header': _ipAddress].

Below is an example of where I'm setting headers for another kind of request that just opens in the app itself but I don't know how I can do this for UIApplication.shared.open.

let newRequest = (self.request as NSURLRequest).mutableCopy() as! NSMutableURLRequest

    if let _ip = EDataManager.shared.ipAddressOfTheUser, _ip.length() > 0 {
        newRequest.setValue(_ip, forHTTPHeaderField: "ex_header")
    }
    URLProtocol.setProperty("true", forKey: EWebViewAssetDownloadProtocol.CustomKey, in: newRequest)
    let defaultConfigObj = URLSessionConfiguration.default
    let defaultSession = URLSession(configuration: defaultConfigObj, delegate: self, delegateQueue: nil)

    self.dataTask = defaultSession.dataTask(with: newRequest as URLRequest)
    self.dataTask!.resume()
Marco Chiang
  • 159
  • 1
  • 4
  • 15

1 Answers1

2

Unfortunately this is not supported for UIApplication.openURL(:options:completion:). Additionally, you can't open a URLRequest out to another application, so there really is no way to pass header fields into an external link to open in Safari.

If you have control of the external API, the best way to handle this is to pass URL query parameters into the url you open. However you have to be careful with that, because URL query parameters are viewable by users, so you can't pass any sensitive data that way.

AnthonyMDev
  • 1,496
  • 1
  • 13
  • 27