objective-c - 使用 ipa 文件安装时应用程序无法正常工作

标签 objective-c ios youtube

我正在使用此代码通过 webView 在 iPad 上播放 YouTube 视频。

NSString *htmlString = [NSString stringWithFormat:@"<html>\
                        <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 done = false;\
                            var player;\
                            function onYouTubePlayerAPIReady() {\
                               player = new YT.Player('player', {\
                               height: '%i',\
                               width: '%i',\
                               videoId: '%@',\
                               events: {\
                                'onReady': onPlayerReady,\
                                'onStateChange': onPlayerStateChange\
                                }\
                              });\
                            }\
                            function onPlayerReady(evt) {\
                                evt.target.playVideo();\
                            }\
                            function onPlayerStateChange(evt) {\
                                if(evt.data==0)\
                                {\
                                      window.location=\"http:\\end\";\
                                 }\
                             }\
                             function resizePlayer(width,height)\
                             {\
                                   player.setSize(width, height);\
                             }\
                           </script>\
                        </body>\
                     </html>",
                        height,width, videoID];

问题是,当我通过 xCode 安装应用程序时,它工作正常,但当我使用 ipa 文件时,它就不行。

最佳答案

您遇到的问题可能取决于特定的设备和 iOS 版本(UIWebView 实现存在细微差别),而不是使用 ipa 文件。

因此,您可以尝试重现 UIWebView 无法正确解释 HTML 代码段的环境。另外,不要忘记定义 webView:didFailLoadWithError:并查看 intercept javascript errors inside of UIWebViews 的方法并将它们显示在控制台上。

希望这有帮助。

关于objective-c - 使用 ipa 文件安装时应用程序无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8878270/

相关文章:

ios - 无法更改 Storyboard 中设置的 TabBar 项目图标

objective-c - UITabBarController 为 TabBar 的每个 ViewController 提供不同的 Storyboard文件

jquery - 什么技术为 iPhone/iPad 开发了 "Financial Times Web App"

javascript - 当我切换到网站的 SSL 加密时,我的 YouTube 视频停止播放

objective-c - 在 C 中动态分配变量

ios - 如何在 AFNetworking 3.0 中获取 allHTTPHeaderFields

objective-c - CoreData 多对多关系(子)查询

ios - 不支持armv7的iOS 5设备

javascript - Youtube Iframe : onYouTubePlayerAPIReady() not called

ios - 在 youtube 应用程序中启动 youtube channel