0

我打电话时发生了奇怪的崩溃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

在主线程中异步调用getAllCookies,不解决问题。

4

1 回答 1

-2

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

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

于 2018-06-04T10:49:32.653 回答