获取数据复杂化:未调用 ExtensionDelegate [英] Get Data to Complication: ExtensionDelegate not Called

查看:31
本文介绍了获取数据复杂化:未调用 ExtensionDelegate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(看起来其他人在前几周也遇到过这个问题,但我还没有找到任何解决方案.)

我正在尝试做一件非常基本的事情:从我的 iOS 应用程序或我的 Watch 应用程序获取数据到我的 Complication Controller.

事实证明,我完成这项工作的能力比我想象的要差得多.watchOS 2 Transition Guide 指出我应该使用以下代码[获取]来自扩展委托的所需数据":

ExtensionDelegate* myDelegate = [[WKExtension sharedExtension] 委托];NSDictionary* data = [myDelegate.myComplicationData objectForKey:ComplicationCurrentEntry];

太好了.除了,我一直无法弄清楚如何让它在扩展端工作.尽管更重要的是,我似乎甚至无法从复杂控制器启动中运行扩展委托代码.当我运行复杂功能时,我收到以下消息:扩展收到唤醒复杂功能支持的请求."但是,任何扩展委托的方法中的代码似乎都没有运行.我还在每个方法中设置了断点,但没有一个断点被命中.

它看起来也像 "transferCurrentComplicationUserInfo:" 也被建议用于复杂更新,尽管目前还不清楚它是如何使用的.据我所知,它用于唤醒手表扩展,以便 ExtensionDelegate 可以在下次运行复杂控制器时存储新数据,但由于之前的问题,我无法确认.

我有一个可能的解决方法(从复杂性控制器 ping 服务器并希望会话变量持续存在以便我可以发送相关数据),但是如果我无法解决这个问题,我的复杂性工作很有可能被灌输.这里的任何帮助都将是巨大的.

顺便说一下,这是我的getCurrentTimelineEntryForComplication"代码,如果有帮助的话.

- (void)getCurrentTimelineEntryForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationTimelineEntry * __nullable))handler {NSDate* entryDate = [NSDate 日期];ExtensionDelegate* myDelegate = [[WKExtension sharedExtension] 委托];NSString* data = [myDelegate.complicationData objectForKey:@"meow"];NSLog(@"并发症数据:%@", data);CLKComplicationTimelineEntry* entry = [self getTimelineEntry:@"2015-08-25 00:19:42" entryDate:entryDate complication:complication];处理程序(条目);}

解决方案

自 Xcode 7 Beta 4 以来,我一直在 WatchOS2 中使用 Complications.我现在使用的是最新的 Xcode Beta 6.我已经有了一个数字在 Watch 上运行、在 iPhone 上运行然后安装到 Watch 以及在模拟器上运行的两个 Beta 版本中的问题,由于 API 和操作系统版本似乎有问题,经常会出现误报.我已经能够通过以下方式获取数据以显示并发症.

  • 确保您的主接口控制器实现 WCSessionDelegate 协议.
  • 在接口控制器中实现 didReceiveMessage 和 didReceiveApplicationContext 方法.
  • 在您的 iPhone 应用中,尝试使用 WCSession 向手表发送消息.
  • 如果无法从 iPhone 应用发送消息,请发送应用上下文.
  • 返回接口控制器,当您收到消息或上下文时,更新扩展委托中的值.
  • 仍然在接口控制器中并且仍然在收到消息或上下文后,获取 CLKComplicationServer 的句柄,并为 activeComplications 中的每个复杂功能调用 reloadTimelineForComplication.
  • 在您的 Complication Controller 的 getCurrentTimelineEntryForComplication 中,获取您在 Extension Delegate 中设置的数据,并在您的 CLKComplicationTimelineEntry 中设置值.
  • 这将在通常当应用程序已经在手表上打开时起作用,应用程序仍然驻留在内存中,但在手表上运行,或者你启动应用程序并且它们的上下文正在等待它消耗.
  • 我无法使历史时间线条目(或未来的)起作用.我也无法独立于 Watch 应用获取更新时间线.

如果您遇到问题,可以尝试以下调试方法.正如我上面所说,API 和操作系统似乎有很多问题.下面的步骤工作(有时).

  • 在 SIM 卡中,使用 iPhone 和 Watch sim 卡上的重置所有设置"选项.
  • 在设备上,重新启动 Watch.如有必要,请取消配对并修理手表,尽管这需要很长时间才能完成.
  • 在 iPhone 上,删除应用(如果安装了 Watch 应用,也会删除)并重新安装.

希望能帮到你!

贾斯汀

(It looks like this issue has been encountered by others in previous weeks, but there haven't been any solutions that I've found.)

I'm trying to do a really basic thing: Get data from either my iOS app or my Watch app to my Complication Controller.

I am turning out to be way less capable of getting this done than I thought. watchOS 2 Transition Guide indicates that I should "[fetch] the needed data from the extension delegate" using the following code:

ExtensionDelegate* myDelegate = [[WKExtension sharedExtension] delegate];  
NSDictionary* data = [myDelegate.myComplicationData objectForKey:ComplicationCurrentEntry];

Great. Except, I haven't been able to figure out how to get this to work on the extension side. Though even more importantly, I can't seem to even get the extension delegate code to run at all from a complication controller launch. When I run the complication, I get this message: "Extension received request to wake up for complication support." However, none of the code within any of the extension delegate's methods seems to run. I've also set breakpoints within every method and none of those breakpoints are hit.

It also looks like "transferCurrentComplicationUserInfo:" is also suggested to be used for complication updates, though it's unclear precisely how it's used. As much as I've gathered, it's used to wake up the watch extension so that ExtensionDelegate can store the new data for the next time the complication controller runs, but due to the previous issue I haven't been able to confirm.

I've got one maybe workaround (pinging the server from the complication controller and hoping that session variables persist so I can send relevant data), but there's every chance that if I can't get this worked out my complication work will be hosed. Any help here would be tremendous.

By the way, here's the code I have for "getCurrentTimelineEntryForComplication", if that's helpful at all.

- (void)getCurrentTimelineEntryForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationTimelineEntry * __nullable))handler {  
    NSDate* entryDate = [NSDate date];  

    ExtensionDelegate* myDelegate = [[WKExtension sharedExtension] delegate];  
    NSString* data = [myDelegate.complicationData objectForKey:@"meow"];  
    NSLog(@"complication data: %@", data);  

    CLKComplicationTimelineEntry* entry = [self getTimelineEntry:@"2015-08-25 00:19:42" entryDate:entryDate complication:complication];  

    handler(entry);  
}

解决方案

I've been working with Complications in WatchOS2 since Xcode 7 Beta 4. I'm now on the latest, Xcode Beta 6. I've had a number of issues as in both Beta versions running on the Watch, running on the iPhone then installing to the Watch, and running on the simulator frequently give false negatives due to what appears to be buggy APIs and OS releases. I have been able to get data to show on complications in the following way.

  • Ensure that your primary Interface Controller implements the WCSessionDelegate protocol.
  • Implement both the didReceiveMessage and didReceiveApplicationContext methods in your Interface Controller.
  • In your iPhone app, attempt to send a message using the WCSession to the Watch.
  • If the message fails to send from the iPhone app, send the application context.
  • Back in the Interface Controller, when you receive a message -or- a context, update the values in your Extension Delegate.
  • Still in the Interface Controller and still after receiving a message -or- context, get a handle to the CLKComplicationServer and for each complication in activeComplications call reloadTimelineForComplication.
  • In your Complication Controller's getCurrentTimelineEntryForComplication grab the data you set in the Extension Delegate and set the values in your CLKComplicationTimelineEntry.
  • This will work usually when the App is already open on the Watch, the app is still resident in memory, but backgrounded on the Watch, or you start the app and their is context waiting which it consumes.
  • I have not been able to get the historical timeline entries to function (or the future ones). Nor, I have I been able to get the timeline to update independently of the Watch app.

If you are having trouble, here are some debugging things to try. As I stated above, the API and OS appears to be very buggy. The steps below do work (sometimes).

  • In the sim, use the Reset all Settings option on both the iPhone and Watch sim.
  • On the device, restart the Watch. If necessary, unpair and repair the Watch, although this takes a really long time to do.
  • On the iPhone, delete the app (which will also delete the Watch app if installed) and reinstall.

I hope that helps!

Justin

这篇关于获取数据复杂化:未调用 ExtensionDelegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆