从自定义键盘应用程序扩展发出 HTTP 请求

Jac*_*son 5 ios swift ios-app-extension swift3

我的自定义键盘应用程序扩展在我的真实设备上表现不同,但在我的 iOS 模拟器上表现良好。

我在真实设备上收到以下错误

2017-02-17 16:30:01.369868 Custom Keyboard[8472:570942] [default] error registring notify port: (1000000)
2017-02-17 16:30:01.371652 Custom Keyboard[8472:570889] [Common] BKSAccelerometer unable to create notifyd token for device orientation
2017-02-17 16:30:01.702241 Custom Keyboard[8472:570940] [] __nwlog_err_simulate_crash_libsystem libsystem simulate crash failed "libsystem_network.dylib: networkd_settings_setup_notify_watch :: notify_register_dispatch(com.apple.system.networkd.settings) [status 1000000] failed"
2017-02-17 16:30:01.706023 Custom Keyboard[8472:570940] [] networkd_settings_setup_notify_watch notify_register_dispatch(com.apple.system.networkd.settings) [status 1000000] failed, dumping backtrace:
Run Code Online (Sandbox Code Playgroud)

我正在使用标准 Alamofire 代码:

Alamofire.request("https://httpbin.org/get").response { response in
    print("Request: \(response.request)")
    print("Response: \(response.response)")
    print("Error: \(response.error)")

    if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
        print("Data: \(utf8Text)")
    }
}
Run Code Online (Sandbox Code Playgroud)

我真的不明白这是怎么回事。

任何帮助表示赞赏。提前致谢。

Jac*_*son 7

您需要具有完全访问权限才能使自定义键盘启用网络。

转到 Info.plist,查看 NSExtensionAttributes 内部并将 RequestsOpenAccess 更改为 YES。

然后,在 iOS 设备上安装键盘时,打开完全访问开关。


小智 5

转到 Info.plist。

  1. 查看内部“NSExtension -> NSExtensionAttributes -> RequestsOpenAccess 为 YES”。

  2. 您必须添加“应用程序传输安全设置 -> 允许任意加载为 YES”。

然后,

  1. 前往苹果设置,然后选择“常规”。

  2. 点击“键盘”,然后点击“键盘”。

  3. 点击“您的键盘”,然后切换“允许完全访问”开关。

  4. 按“允许”。