Unable to reproduce WebKitLegacy -[_WebSafeForwarder forwardInvocation:] crash

前端 未结 2 975
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 05:45

I am Getting [_WebSafeForwarder forwardInvocation:] and crash report as following on crashlytics. Unable to reproduce the same condition in my code. I added webview.delega

相关标签:
2条回答
  • 2021-02-01 06:38

    If you are not insisting on using the NSAttributedString class and you are Ok with just using the String class, check out this project here:

    https://github.com/adela-chang/StringExtensionHTML/blob/master/Pod/Classes/StringExtensionHTML.swift

    It is a bit old and not supported but if you just copy the two Swift files HTMLEntityMapping.swift and StringExtensionHTML.swift, you are good to go.

    The top two properties in the extension are the ones to use.

    extension String {
    
    /// Returns a new string made by removing in the `String`
    /// anything enclosed in HTML brackets <>
    public var stringByStrippingHTMLTags: String {
        return replacingOccurrences(of: "<[^>]+>", with: "", options: .regularExpression, range: nil);
    }
    /// Returns a new string made by replacing in the `String`
    /// all HTML character entity references with the corresponding
    /// character.
    public var stringByDecodingHTMLEntities: String {
        return decodeHTMLEntities().decodedString
    }
    

    What they do is strip any unwanted html tags found in the list in HTMLEntityMapping.swift.

    0 讨论(0)
  • 2021-02-01 06:47

    I have the same issue, I used [NSAttributedString alloc] initWithData to load the HTML string on a label. My crashes often happened when the app switch between Background mode and Foreground mode. I got some tips from Apple's documentation, I think this might be useful.

    Following are the discussion on Apple's NSAttributedstring doc:

    The HTML importer should not be called from a background thread (that is, the options dictionary includes NSDocumentTypeDocumentAttribute with a value of NSHTMLTextDocumentType). It will try to synchronize with the main thread, fail, and time out. Calling it from the main thread works (but can still time out if the HTML contains references to external resources, which should be avoided at all costs). The HTML import mechanism is meant for implementing something like markdown (that is, text styles, colors, and so on), not for general HTML import.

    0 讨论(0)
提交回复
热议问题