我见过几个类似的问题,但没有一个答案对我有用。理想情况下,用户会将视频网址输入到表单中,点击提交,然后视频将显示在表单下方。这是我的代码不能正常工作(对不起,如果它是混乱或混乱):
let text = String(format:"Download the app on your iPhone")
// set up activity view controller
let objectsToShare: [AnyObject] = [ text ]
self.activityViewController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
self.activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
self.activityViewController.completionWithItemsHandler = { activity, success, items, error in
if success {
// Success handling here
}
}
// exclude some activity types from the list (optional)
self.activityViewController.excludedActivityTypes = [ UIActivityTypeAirDrop, UIActivityTypePostToFacebook ]
// present the view controller
self.presentViewController(self.activityViewController, animated: true, completion: nil)
答案 0 :(得分:0)
您似乎要求用户输入一个网址,例如" www.youtube.com/watch?v = vidID",然后获取整个字符串值并将其插入{{1源值。
这实质上将来源设置为" www.youtube.com/embed/www.youtube.com/watch?v = vidID"。
您需要解析用户提交的网址,并在插入<iframe>
由于这些网址的结构,视频ID是字符串中的最后一个值。这意味着你可以做&#34;爆炸&#34;字符串并获取创建的数组中的最后一个值。
以下是您如何做到这一点的简单示例:
<iframe>