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

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

问题描述

(看来前几周其他人都遇到了这个问题,但是我没有找到任何解决方案.)

我正在尝试做一件非常基本的事情:将数据从我的iOS应用程序或我的Watch应用程序获取到并发症控制器.

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

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

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

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

我有一个解决方法(从复杂控制器中对服务器执行ping操作,并希望会话变量能够持续存在,以便我可以发送相关数据),但是如果我无法解决这个问题,那么很有可能我的复杂工作将会用软管.任何帮助都将是巨大的.

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

- (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);  
}

解决方案

自Xcode 7 Beta 4起,我一直在WatchOS2中使用Complications.我现在使用的是最新的Xcode Beta 6.在Watch上运行的两个Beta版本,在iPhone上运行,然后安装到Watch上以及在模拟器上运行的两个Beta版本中,存在的问题经常由于错误的API和操作系统版本而给假阴性.我已经能够通过以下方式获得有关并发症的数据.

  • 确保您的主接口控制器实现了WCSessionDelegate协议.
  • 在您的接口控制器中实现两者 didReceiveMessage和didReceiveApplicationContext方法.
  • 在您的iPhone应用程序中,尝试使用WCSession向手表发送消息.
  • 如果消息无法从iPhone应用程序发送,请发送应用程序上下文.
  • 在界面控制器中,当您收到消息-或-上下文时,请更新您的Extension Delegate中的值.
  • 仍然在接口控制器中,并且仍然在接收到消息或上下文之后,获取CLKComplicationServer的句柄,并为activeComplications中的每个并发症调用reloadTimelineForComplication.
  • 在并发症控制器的getCurrentTimelineEntryForComplication中,获取在扩展代理中设置的数据,并在CLKComplicationTimelineEntry中设置值.
  • 通常在手表上已打开应用程序,该应用程序仍驻留在内存中,但在手表上作为背景时,或者您启动该应用程序且其处于上下文等待状态时,通常消耗.
  • 我无法使历史时间线条目起作用(或将来的).也没有,我能够获得独立于Watch应用程序更新的时间表.

如果遇到问题,请尝试以下调试方法.如前所述,API和OS似乎有很多漏洞. 下面的步骤有时会起作用.

  • 在sim卡中,使用iPhone和Watch sim卡上的重设所有设置选项.
  • 在设备上,重新启动Watch.如有必要,请取消配对并修理手表,尽管这需要花费很长时间.
  • 在iPhone上,删除该应用程序(如果已安装,还将删除Watch应用程序)并重新安装.

希望对您有帮助!

Justin

(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天全站免登陆