- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用通过 WatchConnectivity 从 IOS/iPhone 传输的数据更新 watchOS2 时钟套件并发症。
尽管进行了相当多的研究,但迄今为止未成功。我发现虽然其他帖子描述了类似的挑战(还没有解决方案)
我面临3个问题:
1) 来自 ComplicationController 的 sendMessage 似乎没有唤醒 IOS 父应用程序(而从 InterfaceController 发送的相同 sendMessage 确实唤醒了 IOS 父应用程序)
2)即使将值传输到 ComplicationController(通过 sendUserInfoToComplication 并且当 IOS 应用程序处于前台时),显示在复杂功能中的值也只是有时会更新(还没有找到模式为什么有时会/有时不会)
3) 我将“getNextRequestUpdate..”设置为 2 分钟(用于测试目的)。不过,这似乎没有任何区别。 (即使在任意时间在模拟器中也被触发,但未使用“预算”/我设置了塞子来验证)
请注意,我对 IOS/Swift 编程比较陌生。但是我看到,根据其他问题/帖子,我似乎并不是唯一一个为此苦苦挣扎的人。
这里的示例代码:
复杂功能 Controller :
//
// ComplicationController.swift
// IOSDataToComplication WatchKit Extension
//
// Created by Thomas Peter on 11.10.2015.
// Copyright © 2015 Thomas Peter. All rights reserved.
//
import ClockKit
import WatchConnectivity
class ComplicationController: NSObject, CLKComplicationDataSource, WCSessionDelegate {
var session:WCSession!
var text:String = "watchdefault"
var textOld:String = ""
var header:String = "TestHeader"
override init(){
super.init()
startSession()
}
// MARK: - Timeline Configuration
func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void) {
handler([.None])
}
func getTimelineStartDateForComplication(complication: CLKComplication, withHandler handler: (NSDate?) -> Void) {
handler(nil)
}
func getTimelineEndDateForComplication(complication: CLKComplication, withHandler handler: (NSDate?) -> Void) {
handler(nil)
}
func getPrivacyBehaviorForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationPrivacyBehavior) -> Void) {
handler(.ShowOnLockScreen)
}
// MARK: - Timeline Population
func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: ((CLKComplicationTimelineEntry?) -> Void)) {
// Call the handler with the current timeline entry
if complication.family == .ModularLarge {
//createData()
let entry = self.createTimeLineEntry(text, date: NSDate())
handler(entry)
} else {
handler(nil)
}
}
func getTimelineEntriesForComplication(complication: CLKComplication, beforeDate date: NSDate, limit: Int, withHandler handler: (([CLKComplicationTimelineEntry]?) -> Void)) {
// Call the handler with the timeline entries prior to the given date
handler(nil)
}
func getTimelineEntriesForComplication(complication: CLKComplication, afterDate date: NSDate, limit: Int, withHandler handler: (([CLKComplicationTimelineEntry]?) -> Void)) {
// Call the handler with the timeline entries after to the given date
handler(nil)
}
// MARK: - Update Scheduling
func getNextRequestedUpdateDateWithHandler(handler: (NSDate?) -> Void) {
// Call the handler with the date when you would next like to be given the opportunity to update your complication content
handler(NSDate(timeIntervalSinceNow: (60 * 2)))
}
// MARK: - Placeholder Templates
func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached
let template = CLKComplicationTemplateModularLargeStandardBody()
template.headerTextProvider = CLKSimpleTextProvider(text: "header")
template.body1TextProvider = CLKSimpleTextProvider(text:"defaul text")
handler(nil)
}
func requestedUpdateDidBegin() {
print("Complication update is starting")
createData()
let server=CLKComplicationServer.sharedInstance()
for comp in (server.activeComplications) {
server.reloadTimelineForComplication(comp)
print("Timeline has been reloaded!")
}
}
func requestedUpdateBudgetExhausted() {
print("Budget exhausted")
}
func createTimeLineEntry(bodyText: String, date:NSDate) -> CLKComplicationTimelineEntry {
let template = CLKComplicationTemplateModularLargeStandardBody()
template.headerTextProvider = CLKSimpleTextProvider(text: header)
template.body1TextProvider = CLKSimpleTextProvider(text: text)
let entry = CLKComplicationTimelineEntry(date: date, complicationTemplate: template)
return(entry)
}
func createData(){
let applicationData = ["wake":"fromComplication"]
session.sendMessage(applicationData, replyHandler: {(replyMessage: [String : AnyObject]) -> Void in
// handle reply from iPhone app here
//let answer:[String:AnyObject] = replyMessage
self.text = replyMessage["text"] as! String
print("complication received messagereply \(self.text)")
}, errorHandler: {(error ) -> Void in
// catch any errors here
print("no reply message")
})
print("complication sent \(applicationData) to iOS")
}
func session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]) {
textOld = text
text = userInfo["text"] as! String
print("complication received userinfo \(text)")
dispatch_async(dispatch_get_main_queue()) {
//if text != textOld {
self.requestedUpdateDidBegin()
//}
}
}
private func startSession(){
if (WCSession.isSupported()) {
session = WCSession.defaultSession()
session.delegate = self;
session.activateSession()
}
}
}
//
// ViewController.swift
// IOSDataToComplication
//
// Created by Thomas Peter on 11.10.2015.
// Copyright © 2015 Thomas Peter. All rights reserved.
//
import UIKit
import WatchConnectivity
class ViewController: UIViewController, WCSessionDelegate {
var session:WCSession!
var time:String = "default"
var text:String = "default"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
startSession()
getData()
sendUserInfoToComplication()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func getData(){
let timeValue = NSDate()
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "hh:mm"
time = dateFormatter.stringFromDate(timeValue)
text = "iPhone \(time)"
print("constructed \(text)")
}
private func startSession(){
if (WCSession.isSupported()) {
session = WCSession.defaultSession()
session.delegate = self;
session.activateSession()
}
print("iPhone session started")
}
func session(session: WCSession, didReceiveMessage message: [String : AnyObject], replyHandler: ([String : AnyObject]) -> Void) {
let receivedMessage = message["wake"] as! String
print("iphone received message \(receivedMessage)")
let applicationDict = ["text":text]
replyHandler(applicationDict as [String : AnyObject])
getData()
}
func sendUserInfoToComplication(){
let applicationDict = ["text":text]
session.transferCurrentComplicationUserInfo(applicationDict)
print("iphone sent userinfo \(applicationDict) to complication")
}
}
objc[7501]: Class SPAssetCacheAssets is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/System/Library/Frameworks/WatchKit.framework/WatchKit and /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/System/Library/PrivateFrameworks/SockPuppetGizmo.framework/SockPuppetGizmo. One of the two will be used. Which one is undefined.
objc[7501]: Class SPAssetCacheSyncData is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/System/Library/Frameworks/WatchKit.framework/WatchKit and /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/System/Library/PrivateFrameworks/SockPuppetGizmo.framework/SockPuppetGizmo. One of the two will be used. Which one is undefined.
最佳答案
使用 CLKComplicationServer
像这样:
CLKComplicationServer* server = [CLKComplicationServer sharedInstance];
[server.activeComplications enumerateObjectsUsingBlock:^(CLKComplication * _Nonnull each, NSUInteger idx, BOOL * _Nonnull stop) {
[server reloadTimelineForComplication: each];
}];
ComplicationController
.
关于apple-watch - 使用 IOS 数据更新 WatchOS2 ClockKit 并发症,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33063515/
在 Elastic Watcher 的官方网站上,他们说 Watcher 是 Elasticsearch 的插件,可根据数据的变化提供警报和通知 可以通过定期 Elasticsearch 查询 识别相
我有一个配置了 watch OS1 架构的项目。现在我想在同一个项目中只支持 watch OS2 架构。因此,为了在现有项目中仅配置 watch OS2,我删除了 watch OS1 的所有目标,包括
我想从我的 xcode 项目生成一个 .watchface 文件。有什么方法可以从默认 watch 应用程序之外创建 .watchface 文件吗? 我找到了一个网站Facer ,他们提供定制选项并从
我的手机在 Xcode 中被列为 ineligible target 并在旁边显示(没有配对的 Apple Watch)。 我的 Apple Watch 在 iOS 设备下注册。我可以看到UDID。
最近我在 gulp watch 上遇到错误,我用谷歌搜索并试图解决这个问题,但没有成功。有谁知 Prop 体原因吗? 应用程序基于 AngulerJs 1.3 并运行在 npm 5.7.1/node
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
我有一个并发症,可能需要每 5 分钟更新一次。这很容易总结为每天 120 次更新。有没有办法只在用户唤醒 watch 时更新? 最佳答案 我认为您的问题的答案是否,目前没有办法只在用户唤醒 watch
有没有人有苹果 watch 在没有任何额外应用程序或集成设备的情况下生成的数据类型列表?它必须是 these 的子集,但我无法弄清楚哪些 最佳答案 数据类型的确切列表取决于型号,但最新的 Apple
在我的苹果 watch 扩展中,我想使用长按手势功能。是否有任何 api 等效于 UILongPressGestureRecognizer。我的要求是,在 watch 扩展上,我有表格想要长按单元格,
我一直在互联网上关注很多教程来学习如何设置并发症。按预期设置并发症我没有问题。 直到初始时间线条目过期。 12 小时后,我不知道如何更新它以保持并发症的存在。我将在下面分享我拥有的所有内容,希望有人可
今天几乎是偶然的,我偶然发现了索尼正在开放固件开发并在他们自己的引擎盖下创建一个项目的公告: http://developer.sonymobile.com/services/open-smartwa
目前用于语音听写的方法并不忙。使用的方法是“presentTextInputControllerWithSuggestions”。它遵循单个语音输入“VoiceInputButton -> Speak
我在获取 gulp-watch 时遇到问题或 gulp-watch-less在遵循记录的示例后触发。我最初解决的问题是lazypipe(此处未显示),但在我看来,我在使用插件的方式上做错了。这是我的简
我正在使用 Xcode 开发 Apple Watch 应用程序。我想在屏幕的左上角放置一些文本,与列出时间的位置相邻。 当我将标签向上拖动到屏幕的一部分时,它会自动向下对齐。 我看到大多数 Apple
我似乎找不到在哪里设置我的 Apple Watch 应用程序的产品名称。我确实看到了产品名称选项,但更新它没有任何作用。也看不到文档中的任何内容 最佳答案 为了让您的应用程序名称在 iPhone 上的
只是一个简单的问题。 选项和实例方法有什么区别? 基于 watch 示例,我们可以将 watcher 实现为一个选项( https://v3.vuejs.org/api/options-data.ht
是否可以设置count而不会触发 $watch打回来? $scope.count=1; $scope.$watch('count',function(){...}); 谢谢。 最佳答案 您可以使用 s
对于 sass 目前我正在使用 sass --watch path1:path2 将 scss 文件编译为 css 但我什至发现 compass watch path1:path2 还。这两款 wat
“事件”应用程序是否有 API?例如,我想从应用程序的“锻炼”部分检索信息(您燃烧的卡路里),我想检索您第一次打开应用程序时输入的个人信息。那可能吗?我如何检索这些信息? 最佳答案 没有专门针对事件应
有什么方法可以在 Apple Watch 上启用/配置 Wi-Fi 代理服务器吗? 我们想通过 Charles 测试一些东西,所以我们想将 Apple Watch 与 Charles 连接起来。 我没
我是一名优秀的程序员,十分优秀!