我在UIWebView中遇到了一个奇怪的崩溃,其中MPVolumeView某种程度上是由OS实例化的,而不是在主线程中实例化的。结果,应用程序崩溃。

在我的代码中没有任何地方使用或调用MPVolumeView,因此我不确定在这里应该做什么。该崩溃在iOS 7中不存在,而仅在iOS 8中开始出现。

以下是崩溃前的回溯:

Stacktrace: (
    0   CustomFramework                    0x000000010e918587 PSPDFAssertIfNotMainThread + 87
    1   CustomFramework                    0x000000010e918690 __PSPDFUIKitMainThreadGuard_block_invoke_2 + 32
    2   UIKit                               0x000000010cd2338c -[UIView initWithFrame:] + 153
    3   MediaPlayer                         0x0000000119b64b0d -[MPVolumeView initWithFrame:style:] + 80
    4   UIKit                               0x000000010cd22fb7 -[UIView init] + 62
    5   WebCore                             0x00000001151f9913 -[WebMediaSessionHelper initWithCallback:] + 115
    6   WebCore                             0x00000001151f9259 _ZN7WebCore22MediaSessionManageriOSC2Ev + 89
    7   WebCore                             0x00000001151f91d1 _ZN7WebCore19MediaSessionManager13sharedManagerEv + 49
    8   WebCore                             0x00000001151f7b6e _ZN7WebCore12MediaSessionC2ERNS_18MediaSessionClientE + 46
    9   WebCore                             0x0000000114be08a8 _ZN7WebCore16HTMLMediaSession6createERNS_18MediaSessionClientE + 40
    10  WebCore                             0x0000000114bc3545 _ZN7WebCore16HTMLMediaElementC2ERKNS_13QualifiedNameERNS_8DocumentEb + 1733
    11  WebCore                             0x0000000114c36118 _ZN7WebCore16HTMLVideoElementC2ERKNS_13QualifiedNameERNS_8DocumentEb + 24
    12  WebCore                             0x0000000114c34219 _ZN7WebCore16HTMLVideoElement6createERKNS_13QualifiedNameERNS_8DocumentEb + 57
    13  WebCore                             0x0000000114b9ef41 _ZN7WebCoreL16videoConstructorERKNS_13QualifiedNameERNS_8DocumentEPNS_15HTMLFormElementEb + 81
    14  WebCore                             0x0000000114b9df14 _ZN7WebCore18HTMLElementFactory13createElementERKNS_13QualifiedNameERNS_8DocumentEPNS_15HTMLFormElementEb + 356
    15  WebCore                             0x0000000114b8af85 _ZN7WebCore12HTMLDocument13createElementERKN3WTF12AtomicStringERi + 101
    16  WebCore                             0x0000000114e14f35 _ZN7WebCore40jsDocumentPrototypeFunctionCreateElementEPN3JSC9ExecStateE + 357
    17  ???                                 0x0000042139137034 0x0 + 4540738007092
    18  JavaScriptCore                      0x0000000117742d8e llint_entry + 22744
    19  JavaScriptCore                      0x000000011773d291 callToJavaScript + 311
    20  JavaScriptCore                      0x0000000117621be3 _ZN3JSC7JITCode7executeEPNS_2VMEPNS_14ProtoCallFrameE + 35
    21  JavaScriptCore                      0x0000000117603c93 _ZN3JSC11Interpreter7executeEPNS_17ProgramExecutableEPNS_9ExecStateEPNS_8JSObjectE + 8035
    22  JavaScriptCore                      0x000000011747272c _ZN3JSC8evaluateEPNS_9ExecStateERKNS_10SourceCodeENS_7JSValueEPS5_ + 508
    23  WebCore                             0x000000011546d2f4 _ZN7WebCore16ScriptController15evaluateInWorldERKNS_16ScriptSourceCodeERNS_15DOMWrapperWorldE + 260
    24  WebCore                             0x000000011546d609 _ZN7WebCore16ScriptController8evaluateERKNS_16ScriptSourceCodeE + 41
    25  WebCore                             0x0000000115473d62 _ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE + 194
    26  WebCore                             0x0000000114bf6107 _ZN7WebCore16HTMLScriptRunner36executePendingScriptAndDispatchEventERNS_13PendingScriptE + 231
    27  WebCore                             0x0000000114bf68a7 _ZN7WebCore16HTMLScriptRunner29executeParsingBlockingScriptsEv + 135
    28  WebCore                             0x0000000114b8e3fb _ZN7WebCore18HTMLDocumentParser14notifyFinishedEPNS_14CachedResourceE + 59
    29  WebCore                             0x000000011477f067 _ZN7WebCore14CachedResource11checkNotifyEv + 343
    30  WebCore                             0x0000000115553347 _ZN7WebCore17SubresourceLoader16didFinishLoadingEd + 119
    31  CFNetwork                           0x0000000110e205f7 ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 107
    32  CFNetwork                           0x0000000110eec871 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 273
    33  CFNetwork                           0x0000000110e0bb36 _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 72
    34  CoreFoundation                      0x000000010eebe714 CFArrayApplyFunction + 68
    35  CFNetwork                           0x0000000110e0b9f7 _ZN19RunloopBlockContext7performEv + 133
    36  CFNetwork                           0x0000000110e0b836 _ZN17MultiplexerSource7performEv + 256
    37  CFNetwork                           0x0000000110e0b64c _ZN17MultiplexerSource8_performEPv + 72
    38  CoreFoundation                      0x000000010eeebad1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    39  CoreFoundation                      0x000000010eee199d __CFRunLoopDoSources0 + 269
    40  CoreFoundation                      0x000000010eee0fd4 __CFRunLoopRun + 868
    41  CoreFoundation                      0x000000010eee0a06 CFRunLoopRunSpecific + 470
    42  WebCore                             0x00000001156e8a95 _ZL12RunWebThreadPv + 469
    43  libsystem_pthread.dylib             0x000000010f842899 _pthread_body + 138
    44  libsystem_pthread.dylib             0x000000010f84272a _pthread_struct_init + 0
    45  libsystem_pthread.dylib             0x000000010f846fc9 thread_start + 13

最佳答案

您有一个“确保”在后台线程上没有UIKit方法被调用的框架。但是,如您所见,不建议在生产环境中使用此类框架,而仅在调试环境中使用。

这是一个Apple框架错误。已经报告了该错误,您还应该创建一个错误报告。

确保将您的帮助程序框架更新到最新版本:
https://gist.github.com/steipete/5664345

我的建议是用#if DEBUG语句包围该框架。这不应在生产代码上运行。甚至该框架的作者也这样说:


  您仅应在调试版本中使用它。它不使用私人
  API,但我不会发货。

关于ios - -[MPVolumeView initWithFrame:style]加载UIWebView时未在主线程上调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25963367/

10-10 22:14