<i id='3oZym'><tr id='3oZym'><dt id='3oZym'><q id='3oZym'><span id='3oZym'><b id='3oZym'><form id='3oZym'><ins id='3oZym'></ins><ul id='3oZym'></ul><sub id='3oZym'></sub></form><legend id='3oZym'></legend><bdo id='3oZym'><pre id='3oZym'><center id='3oZym'></center></pre></bdo></b><th id='3oZym'></th></span></q></dt></tr></i><div id='3oZym'><tfoot id='3oZym'></tfoot><dl id='3oZym'><fieldset id='3oZym'></fieldset></dl></div>
<legend id='3oZym'><style id='3oZym'><dir id='3oZym'><q id='3oZym'></q></dir></style></legend>
  • <small id='3oZym'></small><noframes id='3oZym'>

  • <tfoot id='3oZym'></tfoot>

        • <bdo id='3oZym'></bdo><ul id='3oZym'></ul>

        为什么在创建 UIWebView 后清除 NSUserDefaults 会导致 EXC_CRASH?

        Why does clearing NSUserDefaults cause EXC_CRASH later when creating a UIWebView?(为什么在创建 UIWebView 后清除 NSUserDefaults 会导致 EXC_CRASH?)

            1. <legend id='2yEhx'><style id='2yEhx'><dir id='2yEhx'><q id='2yEhx'></q></dir></style></legend>

              <small id='2yEhx'></small><noframes id='2yEhx'>

              • <bdo id='2yEhx'></bdo><ul id='2yEhx'></ul>
                  <tbody id='2yEhx'></tbody>
                <tfoot id='2yEhx'></tfoot>

                  <i id='2yEhx'><tr id='2yEhx'><dt id='2yEhx'><q id='2yEhx'><span id='2yEhx'><b id='2yEhx'><form id='2yEhx'><ins id='2yEhx'></ins><ul id='2yEhx'></ul><sub id='2yEhx'></sub></form><legend id='2yEhx'></legend><bdo id='2yEhx'><pre id='2yEhx'><center id='2yEhx'></center></pre></bdo></b><th id='2yEhx'></th></span></q></dt></tr></i><div id='2yEhx'><tfoot id='2yEhx'></tfoot><dl id='2yEhx'><fieldset id='2yEhx'></fieldset></dl></div>
                1. 本文介绍了为什么在创建 UIWebView 后清除 NSUserDefaults 会导致 EXC_CRASH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我开始之前,我应该告诉你这发生在 iOS 5.1 中.在最近的更新之前,这从未发生过,并且在任何其他版本上仍然没有发生.也就是说,这就是发生的事情.

                  Before I begin, I should tell you that this only happens in iOS 5.1. Before the most recent update, this had never happened and it still does not happen on any other version. That said, here's what's going on.

                  当用户退出我的应用程序时,发生的一件事是所有 NSUserDefaults 都被删除.我没有手动删除我可能添加到用户默认值的每个键,而是使用 NSUserDefaults545091/clearing-nsuserdefaults">这个问题:

                  When a user logs out of my app, one of the things that happens is that all of the NSUserDefaults get deleted. Rather than manually removing every key I might add to the user's defaults, I just completely delete all of the NSUserDefaults, using the method suggested in this SO question:

                  NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
                  [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
                  

                  但似乎发生的情况是,每次我在删除 NSUserDefaults 后尝试创建 UIWebView 时,都会得到一个 EXC_CRASH (SIGABRT).当我调用 [[UIWebView alloc] initWithFrame:frame] 时发生崩溃.奇怪吧?完全退出并重新打开应用程序允许再次创建 UIWebView.

                  What seems to happen though, is that every time I try to create a UIWebView after having removed NSUserDefaults, I get an EXC_CRASH (SIGABRT). The crash happens when I call [[UIWebView alloc] initWithFrame:frame]. Strange right? Completely quitting and reopening the app allows UIWebViews to be created again.

                  所以,我设法弄清楚删除默认值会导致 UIWebView 问题,但可以肯定的是,我为 -[NSUserDefaults setObject:forKey:]<添加了一个符号断点/代码>.

                  So, I managed to figure out that removing the defaults would cause the UIWebView issue, but to be sure, I added a symbolic breakpoint for -[NSUserDefaults setObject:forKey:].

                  创建 UIWebView 确实会触发断点.

                  Creating a UIWebView does indeed trigger the breakpoint.

                  查看崩溃日志给出了异常原因:

                  Poking through the crash logs gives me the exception reason:

                  -[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: WebKitLocalStorageDatabasePathPreferenceKey)
                  

                  这是堆栈跟踪的开头:

                  0 CoreFoundation 0x3340688f __exceptionPreprocess + 163
                  1 libobjc.A.dylib 0x37bd4259 objc_exception_throw + 33
                  2 CoreFoundation 0x33406789 +[NSException raise:format:] + 1
                  3 CoreFoundation 0x334067ab +[NSException raise:format:] + 35
                  4 CoreFoundation 0x3337368b -[__NSCFDictionary setObject:forKey:] + 235
                  5 WebKit 0x3541e043 -[WebPreferences _setStringValue:forKey:] + 151
                  6 UIKit 0x32841f8f -[UIWebView _webViewCommonInit:] + 1547
                  7 UIKit 0x328418d7 -[UIWebView initWithFrame:] + 75
                  8 MyApp 0x0007576f + 0
                  9 UIKit 0x326d4dbf -[UIViewController view] + 51
                  10 UIKit 0x327347e5 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 93
                  11 UIKit 0x32734783 -[UITabBarController transitionFromViewController:toViewController:] + 31
                  12 UIKit 0x327340bd -[UITabBarController _setSelectedViewController:] + 301
                  13 UIKit 0x327bd5d9 -[UITabBarController _tabBarItemClicked:] + 345
                  

                  我现在在做什么,以及什么有效,只是跟踪我设置的 NSUserDefaults 键,并在需要时手动删除它们.但是我总是有可能忘记敏感键,所以简单地清除所有 NSUserDefaults 让我觉得更明智.所以,我想知道为什么我不能这样做.这是一个错误还是我做错了什么?

                  What I'm doing for now, and what works, is just keeping track of the NSUserDefaults keys I have set and removing them all manually when I need to. But there's always a risk I might forget a sensitive key, so simply clearing all NSUserDefaults strikes me as more sensible. So, I would like to know why I can't do that. Is it a bug or am I doing something wrong?

                  如果您想了解更多信息,请告诉我!谢谢.

                  If you want any more info, just let me know! Thanks.

                  在删除所有 NSUserDefaults 后执行 [[NSUserDefaults standardUserDefaults] synchronize] 没有帮助.

                  Doing [[NSUserDefaults standardUserDefaults] synchronize] after deleting all NSUserDefaults does not help.

                  推荐答案

                  我也看到了这个问题,我认为您必须先创建一个 UIWebView,然后才能清除用户默认设置.具有以下内容的干净项目将导致 iOS5.1 崩溃,这在 iOS5.0 及更早版本中可以正常工作:

                  I'm seeing this issue as well, I think you have to have created a UIWebView first before clearing user defaults for it to occur. A clean project with the following will cause the crash in iOS5.1, this works fine in iOS5.0 and earlier:

                  UIWebView *webView = [[UIWebView alloc] init];
                  [webView release];
                  
                  [[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary] forName:[[NSBundle mainBundle] bundleIdentifier]];
                  
                  UIWebView *anotherWebView = [[UIWebView alloc] init];
                  [anotherWebView release];
                  

                  我可以通过这样做来解决崩溃问题,这样就不必记住所有设置键:

                  I can work around the crash by doing this instead, which avoids having to remember all your settings keys:

                  id workaround51Crash = [[NSUserDefaults standardUserDefaults] objectForKey:@"WebKitLocalStorageDatabasePathPreferenceKey"];
                  NSDictionary *emptySettings = (workaround51Crash != nil)
                                  ? [NSDictionary dictionaryWithObject:workaround51Crash forKey:@"WebKitLocalStorageDatabasePathPreferenceKey"]
                                  : [NSDictionary dictionary];
                  [[NSUserDefaults standardUserDefaults] setPersistentDomain:emptySettings forName:[[NSBundle mainBundle] bundleIdentifier]];
                  

                  有人发现这样做有什么问题吗?

                  Anyone see any issues with doing it this way?

                  这篇关于为什么在创建 UIWebView 后清除 NSUserDefaults 会导致 EXC_CRASH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                  Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                  ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                  How to get indexPath.row of tableView which is currently being displayed?(如何获取当前正在显示的 tableView 的 indexPath.row?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)
                    <tbody id='b4AOg'></tbody>

                  • <bdo id='b4AOg'></bdo><ul id='b4AOg'></ul>

                    <legend id='b4AOg'><style id='b4AOg'><dir id='b4AOg'><q id='b4AOg'></q></dir></style></legend>

                        1. <small id='b4AOg'></small><noframes id='b4AOg'>

                          <tfoot id='b4AOg'></tfoot>
                            <i id='b4AOg'><tr id='b4AOg'><dt id='b4AOg'><q id='b4AOg'><span id='b4AOg'><b id='b4AOg'><form id='b4AOg'><ins id='b4AOg'></ins><ul id='b4AOg'></ul><sub id='b4AOg'></sub></form><legend id='b4AOg'></legend><bdo id='b4AOg'><pre id='b4AOg'><center id='b4AOg'></center></pre></bdo></b><th id='b4AOg'></th></span></q></dt></tr></i><div id='b4AOg'><tfoot id='b4AOg'></tfoot><dl id='b4AOg'><fieldset id='b4AOg'></fieldset></dl></div>