目前,我正在使用Swift语言为我的应用程序编写FinderSync扩展。我的扩展需要对运行在本地主机上的服务器进行REST调用,端口号为40322。根据响应,我将创建上下文菜单项。出于同样的原因,我在"FinderSync.swift"文件中编写了以下代码
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()但是,当"nw_socket_connect connectx失败:1操作不允许“时出现错误的代码
但在导入"XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: XCPlayground并将行添加为“”后,操场运行的代码相同。
我的问题是,我们是否需要在“info.plist”应用程序的或FinderSync扩展中添加任何元素来允许扩展执行REST调用,还是有其他方法来解决这个问题?
发布于 2017-02-08 22:48:09
您是否将扩展的功能选项卡设置为允许网络连接?
您的应用程序扩展名使用与主应用程序不同的.entitlements文件。确保您还添加了扩展所需的任何功能。
<key>com.apple.security.network.client</key>
<true/>

https://stackoverflow.com/questions/42109952
复制相似问题