title: Making network request from iOS App Extension returns error: "A server with the specified hostname could not be found"
body: <p>I'm trying to download a language translation model from Google MLKit. I can download the model successfully on the main iOS app, but when I try to download it on the keyboard extension app, I receive an error: &quot;A server with the specified hostname could not be found.&quot;</p>
  <pre><code>testKeyboard[43687:3987699] [] networkd_settings_read_from_file Sandbox is preventing this process from reading networkd settings file at &quot;/Library/Preferences/com.apple.networkd.plist&quot;, please add an exception.
  testKeyboard[43542:3979636] [discovery] [d 6BF0C0BD-3B78-43CD-A23F-26023D59A4F3] &lt;PKHost:0x283acc400&gt; Failed discovery: Error Domain=PlugInKit Code=4 &quot;Connection invalid&quot; UserInfo={NSLocalizedDescription=Connection invalid}.
  testKeyboard[43542:3979636] [xpc] XPC error sending request to pkd: Connection invalid
  testKeyboard[43542:3979662] [] nw_resolver_can_use_dns_xpc_block_invoke Sandbox does not allow access to com.apple.dnssd.service
  testKeyboard[43542:3979662] dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:9 Err:-1 Errno:1 Operation not permitted
  testKeyboard[43542:3979662] [connection] nw_resolver_create_dns_service_locked [C1] DNSServiceCreateDelegateConnection failed: ServiceNotRunning(-65563)
  testKeyboard[43542:3979662] Task &lt;38FA4936-22C4-4E80-BECC-1D592945BE52&gt;.&lt;1&gt; HTTP load failed, 0/0 bytes (error code: -1003 [10:-72000])
  testKeyboard[43542:3979662] Task &lt;38FA4936-22C4-4E80-BECC-1D592945BE52&gt;.&lt;1&gt; finished with error [-1003] Error Domain=NSURLErrorDomain Code=-1003 &quot;A server with the specified hostname could not be found.&quot; UserInfo={_kCFStreamErrorCodeKey=-72000, NSUnderlyingError=0x2821c14a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 &quot;(null)&quot; UserInfo={_kCFStreamErrorCodeKey=-72000, _kCFStreamErrorDomainKey=10}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDownloadTask &lt;38FA4936-22C4-4E80-BECC-1D592945BE52&gt;.&lt;1&gt;, _NSURLErrorRelatedURLSessionTaskErrorKey=(
      &quot;LocalDownloadTask &lt;38FA4936-22C4-4E80-BECC-1D592945BE52&gt;.&lt;1&gt;&quot;
  ), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://redirector.gvt1.com/edgedl/translate/offline/v5/high/r24/en_es.zip, NSErrorFailingURLKey=https://redirector.gvt1.com/edgedl/translate/offline/v5/high/r24/en_es.zip, _kCFStreamErrorDomainKey=10}
  error downloading Optional(Error Domain=com.google.mlkit Code=2 &quot;Failed to download the model from the server.&quot; UserInfo={NSLocalizedDescription=Failed to download the model from the server.})
  
  </code></pre>
  <p>I'm using the same code to download the model according to <a href="https://developers.google.com/ml-kit/language/translation/ios" rel="noreferrer">Google's &quot;Translate Text with MLKit on iOS&quot; documentation</a> in the KeyboardViewController's viewDidLoad() function:</p>
  <pre><code>        let options = TranslatorOptions(sourceLanguage: .english, targetLanguage: .spanish)
          self.translator = Translator.translator(options: options)
          let conditions = ModelDownloadConditions(allowsCellularAccess: true, allowsBackgroundDownloading: true )
          self.translator!.downloadModelIfNeeded(with: conditions) { error in
              guard error == nil else {
                  print(&quot;error downloading&quot;, error)
                  return
              }
              print(&quot;Model downloaded successfully&quot;)
          }
  </code></pre>
  <p>My Info.plist settings are such:</p>
  <ol>
  <li>&quot;RequestsOpenAccess&quot; as 1</li>
  <li>&quot;App Transport Security Settings&quot; &gt; &quot;Allow Arbitrary Loads&quot; as YES</li>
  </ol>
  <p><a href="https://i.stack.imgur.com/xmbdu.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xmbdu.png" alt="Info.plist file" /></a></p>
  <p>I don't understand what is going on here. Why am I able to download the ML Kit language model on the main app, but not on the keyboard extension? Any help appreciated.</p>