【发布时间】:2013-07-21 07:48:28
【问题描述】:
我今天注意到UIWebview 的奇怪行为。
当您在模态视图中打开 Uiwebview 并播放视频时。完整的视频播放完毕后,我们dismissuiwebview 再次调用它,我们就会崩溃。
这里要注意的有趣一点是,这种行为只存在于iPad 中,并且在iPhone 中可以正常工作。
在调试和启用它指向的僵尸时
[MPTransportButton _isChargeEnabled]: message sent to deallocated instance 0x7530930.
调用者:
#import "POCViewController.h"
#import "POCWebViewController.h"
@interface POCViewController ()
@end
@implementation POCViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)displayWebview:(id)sender {
POCWebViewController *objPOCWebViewController = [[POCWebViewController alloc]init];
[self presentViewController:objPOCWebViewController animated:YES completion:nil];
[objPOCWebViewController release];
}
@end
包含视图控制器的UIWebview
#import "POCWebViewController.h"
@interface POCWebViewController ()
@end
@implementation POCWebViewController
@synthesize webview;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSURL *usl = [NSURL URLWithString:@"Any Youtube url"];
NSURLRequest *urlReq = [NSURLRequest requestWithURL:usl];
[webview loadRequest:urlReq];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
if(webview != nil)
[webview release], webview = nil;
[super dealloc];
}
- (IBAction)dismissTapped:(id)sender {
[self dismissViewControllerAnimated:NO completion:nil];
}
@end
知道我哪里出错了吗?
编辑 1:在玩过代码后,我发现缺陷仅限于 HTML 中使用的“jw-player”,即 flash 和其他播放器都很好。
您可以尝试使用此链接http://www.longtailvideo.com/jw-player/ 打开同一个 POC。这使用了一个 jw 播放器。
播放完整视频时,如果您关闭包含uiwebview 的view controller 并再次呈现它,则会导致崩溃。
【问题讨论】:
-
我想向您推荐使用 YouTubeVideoPlayer github.com/surajwebo/YouTubeVideoPlayer 。我用它。它工作正常。
-
不仅仅是播放 youtube 视频,任何带有嵌入视频的 HTML 的行为都相同。
标签: ios objective-c xcode ipad uiwebview