iOS Development

ios – App crashes when I attempt to convert HTML string to NSAttributedString – “NSInternalInconsistencyException”

Spread the love


App crashes when I attempt to convert HTML string to NSAttributedString and assign it to a textView.

@IBOutlet weak var standingBillerNoteTextView: UITextView!

self.standingBillerNoteTextView.attributedText = isFlexSip ? paymentVM.flexSipPaymentNotes.htmlToAttributedString: paymentVM.sipSINotes.htmlToAttributedString

I’m utilizing under code for conversion –

extension String {
    
    var htmlToAtrributtedString: NSAttributedString? {
        guard let knowledge = knowledge(utilizing: .utf8) else { return NSAttributedString() }
        do {
            return strive NSAttributedString(knowledge: knowledge, choices: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)
        } catch {
            debugPrint(error.localizedDescription)
            return nil
        }
        
    }
}

PFB the crash report –

# Crashlytics - Stack hint
# Utility: com.mfonlinepartners.hdfc
# Platform: apple
# Model: 1.8.3 (1.0)
# Problem: a99d65f3ecab66be55e782fbe249fb8f
# Session: 49de9f67a8944764873302dcc737cc00_DNE_0_v2
# Date: Fri Dec 08 2023 20:45:06 GMT+0530 (India Customary Time)

Deadly Exception: NSInternalInconsistencyException
0  CoreFoundation                 0xed5e0 __exceptionPreprocess
1  libobjc.A.dylib                0x2bc00 objc_exception_throw
2  Basis                     0x6bc4d4 -[NSMutableDictionary(NSMutableDictionary) initWithContentsOfFile:]
3  UIKitCore                      0x297f80 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
4  CoreFoundation                 0x361dc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
5  CoreFoundation                 0x34be4 __CFRunLoopDoObservers
6  CoreFoundation                 0x33e64 CFRunLoopRunSpecific
7  UIFoundation                   0xdace8 -[NSHTMLReader _loadUsingWebKit]
8  UIFoundation                   0xdb898 -[NSHTMLReader attributedString]
9  UIFoundation                   0x84128 _NSReadAttributedStringFromURLOrDataCommon
10 UIFoundation                   0x7f2b8 _NSReadAttributedStringFromURLOrData
11 UIFoundation                   0x7f130 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:]
12 HDFC-MF                        0x3bbbb0 @nonobjc NSAttributedString.init(knowledge:choices:documentAttributes:) (<compiler-generated>)
13 HDFC-MF                        0x3bb6ec NSAttributedString.init(knowledge:choices:documentAttributes:) (<compiler-generated>)
14 HDFC-MF                        0x3bb3dc String.htmlToAttributedString.getter + 96 (StringExtension.swift:96)
15 HDFC-MF                        0x52e538 TransactionPaymentTableViewCell.setUpNotes() + 240 (TransactionPaymentTableViewCell.swift:240)
16 HDFC-MF                        0x52b670 TransactionPaymentTableViewCell.configureCell(kind:folioNumber:cellViewModel:frequencyType:schemeType:contactMissing:contemplating:dynamicDataVM:) + 135 (TransactionPaymentTableViewCell.swift:135)
17 HDFC-MF                        0x63835c SIPSchemeViewController.tableView(_:cellForRowAt:) + 531 (SIPSchemeViewController.swift:531)
18 HDFC-MF                        0x641a98 @objc SIPSchemeViewController.tableView(_:cellForRowAt:) (<compiler-generated>)
19 UIKitCore                      0x28a08c (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
20 UIKitCore                      0x289ac4 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
21 UIKitCore                      0x288010 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
22 UIKitCore                      0x287af8 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
23 UIKitCore                      0x331d8 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
24 QuartzCore                     0x67780 (Lacking UUID 0fb9e837c0aa3977a0be28ba0f207a50)
25 QuartzCore                     0x67308 (Lacking UUID 0fb9e837c0aa3977a0be28ba0f207a50)
26 QuartzCore                     0x6d844 (Lacking UUID 0fb9e837c0aa3977a0be28ba0f207a50)
27 QuartzCore                     0x66b34 (Lacking UUID 0fb9e837c0aa3977a0be28ba0f207a50)
28 UIKitCore                      0xe53790 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
29 UIKitCore                      0xe01a3c (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
30 UIKitCore                      0xe51620 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
31 UIKitCore                      0xe51a88 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
32 UIKitCore                      0x122adb4 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
33 UIKitCore                      0xbe3ff4 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
34 UIKitCore                      0x79ebbc (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
35 UIKitCore                      0x79eef0 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
36 UIKitCore                      0x79e5fc (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
37 UIKitCore                      0x20dad0 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
38 UIKitCore                      0xc86fdc (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
39 UIKitCore                      0x2d24cc (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
40 UIKitCore                      0x2cfce4 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
41 UIKitCore                      0x2cf418 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
42 UIKitCore                      0x2ceb60 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
43 UIKitCore                      0x10052c (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
44 UIKitCore                      0xffa6c (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
45 UIKit                          0xa3b8 -[UIKeyboardSceneDelegateAccessibility setInputViews:animationStyle:]
46 UIKitCore                      0xff9b8 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
47 UIKitCore                      0x136534 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
48 UIKitCore                      0x8a96ec (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
49 UIKitCore                      0xc5a94c (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
50 libdispatch.dylib              0x4300 _dispatch_client_callout
51 libdispatch.dylib              0x77b8 _dispatch_continuation_pop
52 libdispatch.dylib              0x1b5c0 _dispatch_source_latch_and_call
53 libdispatch.dylib              0x1a190 _dispatch_source_invoke
54 libdispatch.dylib              0x128a8 _dispatch_main_queue_drain
55 libdispatch.dylib              0x125b0 _dispatch_main_queue_callback_4CF
56 CoreFoundation                 0x379bc __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
57 CoreFoundation                 0x346c8 __CFRunLoopRun
58 CoreFoundation                 0x33e18 CFRunLoopRunSpecific
59 GraphicsServices               0x35ec GSEventRunModal
60 UIKitCore                      0x22f350 (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
61 UIKitCore                      0x22e98c (Lacking UUID 948b271ad49d3b3fac082223908f51ab)
62 HDFC-MF                        0xfbf9ec important + 20 (AppDelegate.swift:20)
63 ???                            0x1d2d47d44 (Lacking)

I’ve seen many posts in stackOverflow, Medium, Apple developer, and so on however didn’t discover any resolution. It happens solely in some gadgets and really random. Please present an answer. Thanks upfront.

Leave a Reply

Your email address will not be published. Required fields are marked *