1

Currently I am writing FinderSync Extension for my App using Swift language. My Extension require to do the REST call to the Server which is running on local host at port number 40322. Based on the response I will create the context menu Items. For same reason I wrote the following code in "FinderSync.swift" file as

let config = URLSessionConfiguration.default
// Session Configuration
let session = URLSession(configuration: config)
// Load configuration into Session
let request_url = URL(string: "http://127.0.0.1:40322/api/get_rclick_settings_and_check_target")!

let task = session.dataTask(with: request_url, completionHandler: {
    (data, response, error) in
    if error != nil {
        print("TAKS ERROR: \(error!.localizedDescription)")
    }
    else {
        do {
            if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any]
            {
                NSLog("TASK RESPONSE: \(json)")
            }
        } catch {
            NSLog("error in JSONSerialization")                   
        }
    }
})
task.resume()

But The code giving Error as "nw_socket_connect connectx failed: [1] Operation not permitted"

But the same code is running of playground after importing XCPlayground and adding line as "XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)"

My Question is do we need to add any elements in "info.plist" of application or FinderSync Extension to allow the extension to do the REST call or is there any other way to solve this problem?

Rahul.Shikhare
  • 179
  • 1
  • 16
  • I'm experience the same issue when connecting to localhost on non-standard http ports when sandboxed, regardless of the sandbox entitlements (network client, server, etc). To me it seems like a bug in Sierra 10.12.4 related to app transport security. Would be happy to hear if you've found a solution to this. – Sean Reilly May 05 '17 at 13:42

1 Answers1

5

Have you set the extension's Capabilities tab to allow network connections?

Your app extension uses a different .entitlements file than the main app. Make sure you additionally add any capabilities the extension will require there.

<key>com.apple.security.network.client</key>
<true/>

enter image description here

pkamb
  • 33,281
  • 23
  • 160
  • 191