【问题标题】:WKHTTPCookieStore getAllCookies crashWKHTTPCookieStore getAllCookies 崩溃
【发布时间】:2018-06-04 10:39:41
【问题描述】:

我在调用getAllCookies()时遇到了奇怪的崩溃

崩溃只能在装有 iOS 11.3.1 的真实设备上重现。在模拟器上工作正常。

let httpCookieStore = WKWebsiteDataStore.default().httpCookieStore
httpCookieStore.getAllCookies { (cookies) in

}

Xcode 控制台中的崩溃说:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0x10fc42790'

Crashlytics 上的崩溃:

Fatal Exception: NSInvalidArgumentException
-[NSURL length]: unrecognized selector sent to instance 0x1c4466d00

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x18105ed8c __exceptionPreprocess
1  libobjc.A.dylib                0x1802185ec objc_exception_throw
2  CoreFoundation                 0x18106c098 __methodDescriptionForSelector
3  CoreFoundation                 0x1810645c8 ___forwarding___
4  CoreFoundation                 0x180f4a41c _CF_forwarding_prep_0
5  CFNetwork                      0x1817a8e44 _CFStringGetOrCreateCString
6  CFNetwork                      0x181799a54 CompactHTTPCookieWithData::CompactHTTPCookieWithData(__CFDictionary const*)::PropDecanter::getEnumeratedString(unsigned int)
7  CFNetwork                      0x181798fb4 Decanter::decant(__CFAllocator const*)
8  CFNetwork                      0x18179956c CompactHTTPCookieWithData::CompactHTTPCookieWithData(__CFDictionary const*)
9  CFNetwork                      0x18164f8b0 CFHTTPCookieCreateWithProperties
10 CFNetwork                      0x18171fe58 -[NSHTTPCookie initWithProperties:]
11 CFNetwork                      0x18171fe24 +[NSHTTPCookie cookieWithProperties:]
12 WebKit                         0x190cdc598 WTF::Function<void (WTF::Vector<WebCore::Cookie, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&)>::CallableWrapper<-[WKHTTPCookieStore getAllCookies:]::$_0>::call(WTF::Vector<WebCore::Cookie, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&)
13 WebKit                         0x190b292ac WebKit::GenericCallback<WTF::Vector<WebCore::Cookie, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&>::performCallbackWithReturnValue(WTF::Vector<WebCore::Cookie, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&)
14 WebKit                         0x190b291b4 WebKit::WebCookieManagerProxy::didGetCookies(WTF::Vector<WebCore::Cookie, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&, WebKit::CallbackID)
15 WebKit                         0x190b2bb08 void IPC::handleMessage<Messages::WebCookieManagerProxy::DidGetCookies, WebKit::WebCookieManagerProxy, void (WebKit::WebCookieManagerProxy::*)(WTF::Vector<WebCore::Cookie, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&, WebKit::CallbackID)>(IPC::Decoder&, WebKit::WebCookieManagerProxy*, void (WebKit::WebCookieManagerProxy::*)(WTF::Vector<WebCore::Cookie, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&, WebKit::CallbackID))
16 WebKit                         0x190a0a5bc IPC::MessageReceiverMap::dispatchMessage(IPC::Connection&, IPC::Decoder&)
17 WebKit                         0x190a5e3c0 WebKit::NetworkProcessProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&)
18 WebKit                         0x1909cd8ec IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >)
19 WebKit                         0x1909d02f4 IPC::Connection::dispatchOneMessage()
20 JavaScriptCore                 0x188663e98 WTF::RunLoop::performWork()
21 JavaScriptCore                 0x188664158 WTF::RunLoop::performWork(void*)
22 CoreFoundation                 0x181007404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
23 CoreFoundation                 0x181006c2c __CFRunLoopDoSources0
24 CoreFoundation                 0x18100479c __CFRunLoopRun
25 CoreFoundation                 0x180f24da8 CFRunLoopRunSpecific
26 GraphicsServices               0x182f07020 GSEventRunModal
27 UIKit                          0x18af0578c UIApplicationMain
28 NAKD-InHouseProd               0x100164ea4 main (AppDelegate.swift:13)
29 libdyld.dylib                  0x1809b5fc0 start

Calling getAllCookies asynchronously in the main thread,不解决问题。

【问题讨论】:

    标签: ios wkwebview httpcookie wkhttpcookiestore


    【解决方案1】:

    从崩溃日志看来,您正在访问NSURL 对象上的length 属性,而NSURL 对象没有length 属性。这就是崩溃的原因。

    您的应用程序中的某个地方可能会获取字符串长度,但该对象是NSURL 类型。请调试它并放置异常断点以识别崩溃的确切位置。

    【讨论】:

    • 我没有在代码中调用NSURL.lenght。如您所见,我的代码是在 Swift 中而不是在 Objective-C 中。恕我直言 WKWebView 在内部调用 [NSURL length] 并使应用程序崩溃。
    • 这并不能解决崩溃问题,一个私有 API 正在为您调用 length 方法,因此您无能为力。请在此处查看解决方案stackoverflow.com/questions/49954273/…
    猜你喜欢
    • 2018-10-01
    • 2019-08-29
    • 2020-12-03
    • 2022-11-02
    • 1970-01-01
    • 2018-03-09
    • 2011-11-22
    • 2021-05-14
    • 1970-01-01
    相关资源
    最近更新 更多