UIWebView 加载崩溃 [__NSCFDictionary _isChargeEnabled]

发布于 2024-11-29 12:25:04 字数 3501 浏览 0 评论 0原文

使用 UIWebView 加载此网站 http://www.xiaami.com/song/1024665

我有时 如果我触摸此网站中的视图或播放音频,我的应用程序就会崩溃,有时却不会,为什么?
是因为html5吗?怎么解决? 其他网站没问题。

崩溃日志是 * -[MPTransportButton _isChargeEnabled]:消息发送到已释放实例 0x20aa58d0

非常感谢任何帮助

---更新 ---

我创建一个新的基于视图的项目,ViewController 中的代码

如下,崩溃日志是

2011-08-16 18:11:25.450 WebTest[1291:707] -[__NSCFDictionary _isChargeEnabled]: unrecognized selector sent to instance 0x1ede0a10
2011-08-16 18:11:25.462 WebTest[1291:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary _isChargeEnabled]: unrecognized selector sent to instance 0x1ede0a10'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x30ea764f __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x349c2c5d objc_exception_throw + 24
    2   CoreFoundation                      0x30eab1bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
    3   CoreFoundation                      0x30eaa649 ___forwarding___ + 508
    4   CoreFoundation                      0x30e21180 _CF_forwarding_prep_0 + 48
    5   UIKit                               0x30f232bd -[UIWindow warpPoint:] + 200
    6   UIKit                               0x30f0c1d5 _UIApplicationHandleEvent + 2404
    7   GraphicsServices                    0x30790e77 PurpleEventCallback + 666
    8   CoreFoundation                      0x30e7ea97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
    9   CoreFoundation                      0x30e8083f __CFRunLoopDoSource1 + 166
    10  CoreFoundation                      0x30e8160d __CFRunLoopRun + 520
    11  CoreFoundation                      0x30e11ec3 CFRunLoopRunSpecific + 230
    12  CoreFoundation                      0x30e11dcb CFRunLoopRunInMode + 58
    13  GraphicsServices                    0x3079041f GSEventRunModal + 114
    14  GraphicsServices                    0x307904cb GSEventRun + 62
    15  UIKit                               0x30f37d69 -[UIApplication _run] + 404
    16  UIKit                               0x30f35807 UIApplicationMain + 670
    17  WebTest                             0x00013425 main + 48
    18  WebTest                             0x000133f0 start + 40
)
terminate called after throwing an instance of 'NSException'

项目中的源代码,这次没有使用MPMoviePlayerController或者其他的

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [self init];
    return self;
}

- (id)init
{
    if (self = [super initWithNibName:nil bundle:nil])
    {
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    [web loadRequest:[NSURLRequest requestWithURL:
                      [NSURL URLWithString:@"http://www.xiami.com/song/1024665"]]];
    web.delegate = self;
    [self.view addSubview:web];
    [web release];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //[webView stringByEvaluatingJavaScriptFromString:@"window.scrollTo(0, 10);"];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
}

I use UIWebView to load this site http://www.xiami.com/song/1024665

sometimes my app crashes if I touch the view or play the audio in this site and sometimes it does not, why?
is it because html5? how to solve?
other website is no problem.

crash log is
* -[MPTransportButton _isChargeEnabled]: message sent to deallocated instance 0x20aa58d0

any help is much appreciated

---update---

I create a new view-base project, the code in ViewController is as following

This time, the crash log is

2011-08-16 18:11:25.450 WebTest[1291:707] -[__NSCFDictionary _isChargeEnabled]: unrecognized selector sent to instance 0x1ede0a10
2011-08-16 18:11:25.462 WebTest[1291:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary _isChargeEnabled]: unrecognized selector sent to instance 0x1ede0a10'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x30ea764f __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x349c2c5d objc_exception_throw + 24
    2   CoreFoundation                      0x30eab1bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
    3   CoreFoundation                      0x30eaa649 ___forwarding___ + 508
    4   CoreFoundation                      0x30e21180 _CF_forwarding_prep_0 + 48
    5   UIKit                               0x30f232bd -[UIWindow warpPoint:] + 200
    6   UIKit                               0x30f0c1d5 _UIApplicationHandleEvent + 2404
    7   GraphicsServices                    0x30790e77 PurpleEventCallback + 666
    8   CoreFoundation                      0x30e7ea97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
    9   CoreFoundation                      0x30e8083f __CFRunLoopDoSource1 + 166
    10  CoreFoundation                      0x30e8160d __CFRunLoopRun + 520
    11  CoreFoundation                      0x30e11ec3 CFRunLoopRunSpecific + 230
    12  CoreFoundation                      0x30e11dcb CFRunLoopRunInMode + 58
    13  GraphicsServices                    0x3079041f GSEventRunModal + 114
    14  GraphicsServices                    0x307904cb GSEventRun + 62
    15  UIKit                               0x30f37d69 -[UIApplication _run] + 404
    16  UIKit                               0x30f35807 UIApplicationMain + 670
    17  WebTest                             0x00013425 main + 48
    18  WebTest                             0x000133f0 start + 40
)
terminate called after throwing an instance of 'NSException'

the source code in the project, not use MPMoviePlayerController this time or something else

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [self init];
    return self;
}

- (id)init
{
    if (self = [super initWithNibName:nil bundle:nil])
    {
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    [web loadRequest:[NSURLRequest requestWithURL:
                      [NSURL URLWithString:@"http://www.xiami.com/song/1024665"]]];
    web.delegate = self;
    [self.view addSubview:web];
    [web release];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //[webView stringByEvaluatingJavaScriptFromString:@"window.scrollTo(0, 10);"];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

写给空气的情书 2024-12-06 12:25:04

您发布的代码没有任何问题。

NSZombie 表示您的代码中的某处有一个 MPTransportButton 之前已被释放(释放),之后,在代码中的其他位置,您想用它做一些事情。

我认为您可以在 UIWebView 的委托方法之一中执行此操作。

但是...我们需要更多代码。您在哪里分配/初始化您的MPMoviePlayerController?或者你分配/初始化一个MPTransportButton

There's nothing wrong in code that you posted.

NSZombie says that there is a MPTransportButton somewhere in your code that was previously deallocated (released) and after that, somewhere else in your code, you want to do something with it.

I think that you do it in one of your UIWebView's delegate methods.

But... we need more code. Where do you alloc/init your MPMoviePlayerController? Or do you alloc/init a MPTransportButton?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文