0

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

kha
  • 349
  • 3
  • 18
  • Have you added the apple-app-site-association file to your server? – Paulw11 Jun 16 '22 at 04:31
  • @Paulw11 not yet. Why is apple-app-site-association related to DNS query ? – kha Jun 16 '22 at 07:47
  • The apple-app-site-association file is the key to enabling an associated domain. The "Shared credentials" document linked to by the document you linked to describes setting up the site association file. I imagine you get a DNS lookup because your extension operates in a sandboxed network environment and your server is not whitelisted – Paulw11 Jun 16 '22 at 07:53
  • @Paulw11. Thank you for your information. I will try. Is there any method to generate the apple-app-site-association ? or I have to configure by myself based on the [document](https://developer.apple.com/documentation/xcode/supporting-associated-domains) ? – kha Jun 16 '22 at 08:00

0 Answers0