2014-10-29 62 views
4

我想用web視圖加載YouTube視頻。視頻播放很好,並且完全按照我的要求播放,但調試器不斷髮出警告(請參見結束)。該警告重複約20次。試圖從web視圖加載YouTube視頻時的約束警告

我試圖隔離問題,並沒有任何限制,並且它仍然顯示約束相關的警告新的ViewController。

我試圖玩.translatesAutoresizingMask.scalesToFitPage,但他們似乎沒有什麼區別。

這是我使用嵌入視頻代碼:

// webView from an IBOutlet in an empty ViewController without any constraints 

func playVideo(){ 

    var staticUrlString = "https://www.youtube.com/watch?v=jNQXAC9IVRw" 
    var youtubeVideoId = NSString(string: staticUrlString) 
    var rng: NSRange = youtubeVideoId.rangeOfString("&feature=") 

    if(rng.length>0){ 
     youtubeVideoId = youtubeVideoId.stringByReplacingCharactersInRange(NSMakeRange(rng.location, youtubeVideoId.length-rng.location), withString: "") 
    } 

    youtubeVideoId = youtubeVideoId.stringByReplacingOccurrencesOfString("http://www.youtube.com/watch?v=", withString: "") 
    youtubeVideoId = youtubeVideoId.stringByReplacingOccurrencesOfString("https://www.youtube.com/watch?v=", withString: "") 

    var youTubeVideoHTML: NSString = NSString(format: "<!DOCTYPE html><html><head><style>body{margin:0px 0px 0px 0px; background:#1111}</style></head> <body> <div id=\"player\"></div> <script> var tag = document.createElement('script'); tag.src = \"http://www.youtube.com/player_api\"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { width:'%0.0f', height:'%0.0f', videoId:'%@', events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } });} function onPlayerReady(event) { event.target.playVideo(); } function onPlayerStateChange(event) {if(event.data === 0) { event.target.destroy(); }} </script> </body> </html>",0.0, 0.0,youtubeVideoId) 

    //webView.translatesAutoresizingMaskIntoConstraints() 
    //webView.scalesPageToFit = false 
    webView.mediaPlaybackRequiresUserAction = false 
    webView.opaque = false 

    webView.loadHTMLString(youTubeVideoHTML, baseURL: NSURL(string: NSString(format: "http://www.youtube.com/watch?v=%@", youtubeVideoId))) 


    println("play") 
} 

這是警告之一:

Unable to simultaneously satisfy constraints. 
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7cb37910 UIImageView:0x7cb36fb0.centerX == AVUnsupportedContentIndicatorView:0x7cb36cf0.centerX>", 
    "<NSLayoutConstraint:0x7cb37d70 H:[UIImageView:0x7cb36fb0]-(>=10)-| (Names: '|':AVUnsupportedContentIndicatorView:0x7cb36cf0)>", 
    "<NSLayoutConstraint:0x7cb4f430 H:|-(0)-[AVUnsupportedContentIndicatorView:0x7cb36cf0] (Names: '|':UIView:0x7cb36b20)>", 
    "<NSLayoutConstraint:0x7cb4f460 H:[AVUnsupportedContentIndicatorView:0x7cb36cf0]-(0)-| (Names: '|':UIView:0x7cb36b20)>", 
    "<NSLayoutConstraint:0x7cb4f310 H:|-(0)-[UIView:0x7cb36b20] (Names: '|':AVPlayerView:0x7cb36860)>", 
    "<NSLayoutConstraint:0x7cb4f360 H:[UIView:0x7cb36b20]-(0)-| (Names: '|':AVPlayerView:0x7cb36860)>", 
    "<NSLayoutConstraint:0x7cb5ef40 'UIView-Encapsulated-Layout-Width' H:[AVPlayerView:0x7cb36860(1)]>" 
) 


Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7d342240 UIView:0x7d229b90.centerX == AVExternalPlaybackIndicatorView:0x7d22a150.centerX> 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 

回答

3

它似乎並不像限制你得到警告的都是相關直接查看您創建的內容 - 它們是關於Apple內部視圖結構的。

這是(很有可能)一個錯誤。你應該在這裏提交報告:https://bugreport.apple.com

+0

這些警告是否會減少我獲得批准我應用程序的機會?我可能會看看官方的YouTube視頻幫手,但是這是我需要付出的一大筆額外費用。 – 2014-10-29 21:50:59

+0

不需要。注意警告是個不錯的主意,但不會讓您的應用遭到拒絕。 – radex 2014-10-30 07:00:04