Rah*_*are 1 macos finder findersync swift3 macos-sierra
目前我正在使用Swift语言为我的应用程序编写FinderSync扩展.我的扩展需要对端口号为40322的本地主机上运行的服务器进行REST调用.根据响应,我将创建上下文菜单项.出于同样的原因,我在"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()
Run Code Online (Sandbox Code Playgroud)
但是错误为 "nw_socket_connect connectx失败:[1]操作不允许"的代码
但是在导入XCPlayground并将行添加为"XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely:true)"之后,相同的代码运行了playground.
我的问题是我们是否需要在应用程序或FinderSync Extension的"info.plist"中添加任何元素以允许扩展进行REST调用,还是有其他方法可以解决此问题?
您是否设置了扩展程序的功能选项卡以允许网络连接?
您的应用扩展程序使用的.entitlements文件与主应用程序不同.确保您另外添加扩展程序所需的任何功能.
<key>com.apple.security.network.client</key>
<true/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1216 次 |
| 最近记录: |