gpt4 book ai didi

ios - 添加 Watchkit 扩展并让 iPhone 完成工作

转载 作者:行者123 更新时间:2023-11-28 15:05:30 25 4
gpt4 key购买 nike

我需要开发一个 iPhone 应用程序并为其实现一个 Watchkit 扩展。事情是这样的:确实有很多类,尤其是那些负责网络通信(身份验证 token 等)的类。现在构建应用程序的人正在做一些事情,比如从网络通信中显示 UIAlert,如下所示:

class func showReloadDataDialog(_ action: @escaping (_ action: UIAlertAction) -> Void) {
let alert = UIAlertController.init(title: String.localizedString("AlertTitleError", ""),
message: String.localizedString("ActivationRetrySupportedNetworksLoadMessage", ""),
preferredStyle: .alert)
let defaultAction = UIAlertAction.init(title: String.localizedString("AlertNoButton", ""), style: .default, handler: nil)
alert.addAction(defaultAction)
let reloadAction = UIAlertAction.init(title: String.localizedString("AlertYesButton", ""), style: .default, handler: action)
alert.addAction(reloadAction)
self.present(alert)
}

这是 present() 函数:

// MARK: Present
class func present(_ alert: UIAlertController) {
if let window = UIApplication.shared.delegate?.window, var topController = window!.rootViewController {
while topController.presentedViewController != nil {
topController = topController.presentedViewController!
}
if let navigationController = topController as? UINavigationController {
topController = navigationController.visibleViewController!
}
if topController is UIAlertController {
return
}
topController.present(alert, animated: true, completion: nil)
}
}

如您所见,他们做的事情与他们应该做的有点不同。现在这确实是一个问题,因为我不能在我的 Watchkit 扩展中使用这个网络通信类,因为 Apple 的 Watchkit 中没有 UIViewController - 这意味着当我将这个类添加到我的时它不会编译看目标。

这只是一个例子,还有很多其他类似的东西,我真的不想重构整个源代码。

现在我的问题是:我能否以某种方式让 iPhone 完成所有工作(例如,从服务器获取一些数据,同时处理所有身份验证 token 内容),然后将结果推送到 Watchkit Extension?我已经阅读了一些关于 WCSession 的内容 - 我可以将它用于我的案例吗?我基本上是在尝试在 WKInterfaceMap 上显示一些 POI。

最佳答案

关于你的第一个问题,你会找到你的解决方案here关于 watchkit 中的网络服务。在链接中,社区建议让 iPhone 应用程序完成繁重的工作(获取数据等),并将信息返回给 watchApp。

其次,您可以使用 watchconnectivity 框架,也可以使用 MMWormhole 与您的 iPhone 应用程序进行通信。您需要做的就是获取 Place of Interests 数据并将其发送到您的 watchApp。从那里您可以填充您的 map 。

关于ios - 添加 Watchkit 扩展并让 iPhone 完成工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48540797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com