iOS上下文菜单API无法显示链接演示内容

时间:2019-10-31 13:39:42

标签: ios swift contextmenu

当用户强行或长按链接时,我试图使用LinkPresentation API在UIContextualMenu内显示网站的预览,这类似于偷窥和弹出操作链接的方式。但是,LP API异步地从网站加载元数据,当我强制触摸链接时,上下文菜单显示的预览控制器为空白。以下是UIContextMenuConfiguration的委托方法:

public func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {

    guard let url = shouldShowContextualMenu(location: location) else { return nil }

    return UIContextMenuConfiguration(identifier: nil, previewProvider: { () -> UIViewController? in

        self.getMetadataForUrl(url: url ) { linkView in
            self.previewController = LinkPreviewViewController(linkView: linkView)
        }

        return self.previewController
    }, actionProvider: nil)
}

0 个答案:

没有答案