SRM*_*RMR 5 ios swift watchkit watchos-2 apple-watch-complication
我所有的数据创建都是在ExtensionDelegate.swift
.
该问题ExtensionDelegate.swift
没有得到该功能之前叫getCurrentTimelineEntryForComplication
我的ComplicationController.swift
。
有任何想法吗? 这是我的代码和详细信息:
所以我的数组extEvnts
是空的ComplicationController.swift
:
func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: ((CLKComplicationTimelineEntry?) -> Void)) {
let extEvnts = ExtensionDelegate.evnts
}
Run Code Online (Sandbox Code Playgroud)
因为 myExtensionDelegate.swift
还没有被调用,这就是为数组创建数据的原因:
class ExtensionDelegate: NSObject, WKExtensionDelegate, WCSessionDelegate {
private let session = WCSession.defaultSession()
var receivedData = Array<Dictionary<String, String>>()
static var evnts = [Evnt]()
func session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]) {
if let tColorValue = userInfo["TeamColor"] as? String, let matchValue = userInfo["Matchup"] as? String {
receivedData.append(["TeamColor" : tColorValue , "Matchup" : matchValue])
ExtensionDelegate.evnts.append(Evnt(dataDictionary: ["TeamColor" : tColorValue , "Matchup" : matchValue]))
} else {
print("tColorValue and matchValue are not same as dictionary value")
}
}
func applicationDidFinishLaunching() {
// Perform any final initialization of your application.
if WCSession.isSupported() {
session.delegate = self
session.activateSession()
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:
对于 Apple,看起来这与它有关,但出于某种原因,我不知道如何实际实现它,因为我无法调用mydelegate.evnts
:
// Get the complication data from the extension delegate.
let myDelegate = WKExtension.sharedExtension().delegate as! ExtensionDelegate
var data : Dictionary = myDelegate.myComplicationData[ComplicationCurrentEntry]!
Run Code Online (Sandbox Code Playgroud)
所以我已经尝试过这样的事情,但仍然无法让它工作,因为我仍然没有得到任何数据:
func someMethod() {
let myDelegate = WKExtension.sharedExtension().delegate as! ExtensionDelegate
let dict = ExtensionDelegate.evnts
print("ExtensionDel.evnts: \(dict.count)")
Run Code Online (Sandbox Code Playgroud)
}
有用的问题对我有帮助
在该功能中,requestedUpdateDidBegin()
您可以更新将在复杂功能中显示的信息。因此,在此方法中,您可以使用sendMessage:replyHandler:errorHandler:WatchConnectivity
等方法调用父应用程序以接收新信息。
您可以用来NSUserDefaults
存储将在您的 中使用的命令性数据ComplicationController
,然后从您的复杂性中加载此信息NSUserDefaults
。我将此数据存储在用户默认值中,以便在新数据无法加载时始终显示旧数据。
归档时间: |
|
查看次数: |
1850 次 |
最近记录: |