SFSafariPage 属性像这样获取它的值
class SafariExtensionHandler: SFSafariExtensionHandler {
var somePage: SFSafariPage?
override func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String : Any]?) {
// This method will be called when a content script provided by your extension calls safari.extension.dispatchMessage("message").
if messageName == "script injected successfully" {
somePage = page
NSLog(String(describing: somePage))
}
}
但是当我尝试使用它时
func performPlayerAction(_ action: PlayerAction) {
NSLog("page %@", String(describing: somePage))
somePage?.dispatchMessageToScript(withName: action.rawValue, userInfo: nil)
}
属性 somePage 的值为 nil。为什么会这样?非常感谢!