好的,我是 URL 查询和 Swift 整个方面的新手,需要帮助。照原样,我有一个 iMessage 应用程序,其中包含和SKScene
. 为了让用户轮流玩游戏,我需要在 1 个会话内来回发送游戏,正如我在这里学到的:https ://medium.com/lost-bananas/building-an-interactive-imessage-application -for-ios-10-in-swift-7da4a18bdeed。
到目前为止,我的场景都在工作,但是我倾注了 Apple 的冰淇淋演示,他们在其中来回发送连续制作的冰淇淋,我无法理解如何“查询”我SKScene
的所有内容,以便发送场景。
我不清楚URLQueryItem
s 是如何工作的,因为文档与 sprite kit 场景无关。
苹果在当前状态下查询他们的“冰淇淋”,如下所示:
init?(queryItems: [URLQueryItem]) {
var base: Base?
var scoops: Scoops?
var topping: Topping?
for queryItem in queryItems {
guard let value = queryItem.value else { continue }
if let decodedPart = Base(rawValue: value), queryItem.name == Base.queryItemKey {
base = decodedPart
}
if let decodedPart = Scoops(rawValue: value), queryItem.name == Scoops.queryItemKey {
scoops = decodedPart
}
if let decodedPart = Topping(rawValue: value), queryItem.name == Topping.queryItemKey {
topping = decodedPart
}
}
guard let decodedBase = base else { return nil }
self.base = decodedBase
self.scoops = scoops
self.topping = topping
}
}
fileprivate func composeMessage(with iceCream: IceCream, caption: String, session: MSSession? = nil) -> MSMessage {
var components = URLComponents()
components.queryItems = iceCream.queryItems
let layout = MSMessageTemplateLayout()
layout.image = iceCream.renderSticker(opaque: true)
layout.caption = caption
let message = MSMessage(session: session ?? MSSession())
message.url = components.url!
message.layout = layout
return message
}
}
但我不知道如何“查询”一个SKScene
. 我如何SKScene
来回“发送”?这可能吗?