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

标签 ios swift swift3 ios-app-extension

我的自定义键盘应用程序扩展在我的真实设备上表现不同,但在我的 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:

我使用的是标准的 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)")
    }
}

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

感谢任何帮助。提前致谢。

最佳答案

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

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

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

关于ios - 从自定义键盘应用程序扩展发出 HTTP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42301827/

相关文章:

ios - 使本地通知默认不显示在通知中心

ios - 自动续订订阅到期日期不符合 Apple 规范

ios - 无法在iOS Simulator中将通行证添加到电子钱包,但未记录任何内容

iOS AWS AppSync 401 IAM + Cognito

Swift:循环遍历 Any 类型的集合?

swift - 从常量 : Ambiguous reference to member 'subscript' 获取值时出错

ios - 通过 GTMOAuth 使用 REST api 让代理在成功登录保管箱时进行回调

ios - 数组?没有名为 "Generator"的成员

ios - UIDocumentMenuViewController 的自定义图像仅显示蓝色框

swift - Mapkit - 始终显示指南针