I'm developing iOS message extension to filter the unwanted message. The plugin needs a help from server to filter the message. However, the iOS returned the error NSURLErrorDomain
while requesting the server.
Based on the official document, I have done the following steps:
- I added Associated Domains capability with value:
messagefilter:mydomain.io
- I defined the key/value pair in
Info.plist
of Message Extension.ILMessageFilterExtensionNetworkURL
has value:https://mydomain.io/api/v1/sms
The code that I test the request as follows:
let url = URL(string: "https://mydomain.io/api/v1/sms")!
var request = URLRequest(url: url)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("you-value-goes-here", forHTTPHeaderField: "X-API-KEY")
let task = URLSession.shared.dataTask(with: request) { data, _, error in
if let data = data {
print(data)
} else if let error = error {
print("Http failed: \(error)")
}
}
task.resume()
From the stack trace, as far as I known, there is a problem with dns resolution. Why does this happened and how to fix this case?
[0] (null) "_kCFStreamErrorCodeKey" : Int32(-72000)
[1] (null) "NSUnderlyingError" : domain: "kCFErrorDomainCFNetwork" - code: 18446744073709550613
[2] (null) "_NSURLErrorFailingURLSessionTaskErrorKey" : "LocalDataTask <B496A974-7009-4FCE-BF45-FEC07BA1E8DF>.<1>"
[3] (null) "_NSURLErrorRelatedURLSessionTaskErrorKey" : 1 element
[4] (null) "NSLocalizedDescription" : "A server with the specified hostname could not be found."
Thanks