swift - didReceiveMessage 接收并响应消息但未调用方法
问题描述
观看应用界面控制器:
@IBAction func scheduleMeeting(_ sender: WKInterfaceButton) {
if (WCSession.isSupported()) {
session.sendMessage([ "scheduleMeeting": ["scheduleMeeting"] ], replyHandler: { (responses) -> Void in
print("response: \(responses)")
}) { (err) -> Void in
print("error: \(err)")
}
}
}
iOS 应用主视图控制器:
class ParentViewController: UIViewController, WCSessionDelegate {
var session: WCSession?
// WCSession Delegate protocol
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
//FYI i have tried this -DispatchQueue.main.async { - but no difference
print("test1")
do {
//since we are passing true for asynchronous we cannot use the result of the call, the warning below is n/a
try
Communicator.addScheduledMeeting(self.scheduledMeeting, asynchronous: true)
} catch {
print("Unexpected saving scheduled meeting error: \(error).")
}
// Send a reply
replyHandler(["Message":"Hi from app"])
}
//omitted rest of class
正如我们从控制台输出(下图)中看到的那样,应用程序接收到消息并发送回响应
回复:[“消息”:来自应用程序的您好]
我的问题是没有其他代码运行
- print("test1") 从不显示在控制台上
- didReceiveMessage 和 Communicator.addScheduledMeeting 中的断点未命中
旁注我不知道它是否相关,但我觉得它可能是,我应该提到它。
要运行我的手表应用程序,我选择“WatchKit App”并点击播放(它在我的控制台输出的这种模式下)。但是在此期间,我的应用程序仅出现在手表模拟器上。如果我尝试在 iPhone 模拟器上打开它,它会打开显示活动指示器,然后变黑然后返回主屏幕。如果我只选择“”并点击播放,应用程序运行良好。我可以手动启动手表应用程序,但对控制台没有任何影响,也没有任何断点。
解决方案
推荐阅读
- java - 在不使用 Time Zone API 的情况下从用户的当前地理位置获取时区
- c - 试图从汇编程序(64 位)的 glibc 调用 C 函数
- css - 如何“打破”引导布局然后打印?
- python - 改组 itertools.permutation(range(15)) 时出现 Python OOM 错误
- android - 如何在 Android 的操作栏上方显示自定义视图
- html - CSS - 调用元素 [attribute^=value] 后未应用边框 X 颜色的原因
- collision-detection - 多物体碰撞检测与响应
- python - Python 在不断更新单独的窗口时诅咒字符串输入?
- java - 我如何使用外部存储将我的值保存在表单上,在排行榜中创建新条目,并能够将数据拉回?
- selenium - 元素应该被禁用