ILPDFKit icon indicating copy to clipboard operation
ILPDFKit copied to clipboard

Crash while opening a PDF with Forms

Open ComputopDeveloper opened this issue 8 years ago • 0 comments

For the most cases I'm able to open PDF with forms, but for a special file the app is crashing because of

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance

If find out that the ILPDFFormContainer is the reason for that. Especially in the populateNameTreeNode: method you expect a NSMutableDictionary, but in my case here it is an array:

   ...
    NSMutableDictionary *dict  = node[base];  // here in the dict var there comes an array and not dictionary, the base is "1" as STRING
    if (dict == nil) {
        dict = [NSMutableDictionary dictionary];
        node[base] = dict;
    }
    [self populateNameTreeNode:dict withComponents:[components subarrayWithRange:NSMakeRange(1, [components count]-1)] final:final];

My bad solution was it to check for the class, and in case that it is not a dictionary I don't populate:

    NSMutableDictionary *dict  = node[base];
    if (dict == nil) {
        dict = [NSMutableDictionary dictionary];
        node[base] = dict;
    }
    if ([dict isKindOfClass:[NSMutableDictionary class]])
    {
        [self populateNameTreeNode:dict withComponents:[components subarrayWithRange:NSMakeRange(1, [components count]-1)] final:final];
    }

ComputopDeveloper avatar Aug 04 '17 12:08 ComputopDeveloper