简体   繁体   English

自iOS8起,NullSafe在UIKit / Webkit / UIWebViewPDF / UIWebView / UIWebDocumentView /上崩溃

[英]NullSafe crashing on UIKit/Webkit / UIWebViewPDF / UIWebView / UIWebDocumentView / … since iOS8

Okay so this iOS8 is starting to cause a lot of problems, and this is one of them. 好的,所以这个iOS8开始引起很多问题,这就是其中之一。

I'm using the NullSafe library (that you can find on github) that basically returns nil instead of an exception when parsing something empty. 我正在使用NullSafe库(可以在github上找到),该库在解析空内容时基本上返回nil而不是异常。

Now when NullSafe is working, it just browse all the classes (from every framework/bundle/kit in your project ). 现在,当NullSafe工作时,它只是浏览所有类(从项目中的每个框架/捆绑软件/工具包中浏览)。 I'm not really confident in the understanding on why this Nullsafe library does that, but it does it, and it crashes now. 对于这个Nullsafe库为什么会那样做,我并没有真正的信心,但是确实做到了,现在崩溃了。

When debugging, the class being checked when crashing varies, but we can never find it anywhere in the apple doc or the bundles... So my conclusion is : 调试时,崩溃时要检查的类有所不同,但是我们永远无法在apple doc或捆绑软件中的任何地方找到它。所以我的结论是:

It appears that NullSafe is trying to browse classes that don't exist 看来NullSafe试图浏览不存在的类

  • I can't really get rid of NullSafe, or at least i'd like to try not to for the time being. 我真的不能摆脱NullSafe,或者至少我暂时不想这样做。
  • It always appears to crash on view related classes. 它总是在与视图相关的类上崩溃。
  • They never seem to exist when we look for them. 当我们寻找它们时,它们似乎永远不存在。

Does any of you use NullSafe or know anything about it so we could try to go forward? 你们中有人使用NullSafe还是对此有所了解,所以我们可以尝试前进吗?

After contacting Nick (maker of Nullsafe )i've seen my issues go away. 联系了Nick(Nullsafe的制造商)后,我发现我的问题消失了。 He just gave me the latest version, 1.2.1. 他只是给了我最新版本1.2.1。

Here is the complete Nullsafe.m file : 这是完整的Nullsafe.m文件:

//
//  NullSafe.m
//
//  Version 1.2.1
//
//  Created by Nick Lockwood on 19/12/2012.
//  Copyright 2012 Charcoal Design
//
//  Distributed under the permissive zlib License
//  Get the latest version from here:
//
//  https://github.com/nicklockwood/NullSafe
//
//  This software is provided 'as-is', without any express or implied
//  warranty.  In no event will the authors be held liable for any damages
//  arising from the use of this software.
//
//  Permission is granted to anyone to use this software for any purpose,
//  including commercial applications, and to alter it and redistribute it
//  freely, subject to the following restrictions:
//
//  1. The origin of this software must not be misrepresented; you must not
//  claim that you wrote the original software. If you use this software
//  in a product, an acknowledgment in the product documentation would be
//  appreciated but is not required.
//
//  2. Altered source versions must be plainly marked as such, and must not be
//  misrepresented as being the original software.
//
//  3. This notice may not be removed or altered from any source distribution.
//

#import <objc/runtime.h>
#import <Foundation/Foundation.h>


#ifndef NULLSAFE_ENABLED
#define NULLSAFE_ENABLED 1
#endif


#pragma GCC diagnostic ignored "-Wgnu-conditional-omitted-operand"


@implementation NSNull (NullSafe)

#if NULLSAFE_ENABLED

- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
{
    @synchronized([self class])
    {
        //look up method signature
        NSMethodSignature *signature = [super methodSignatureForSelector:selector];
        if (!signature)
        {
            //not supported by NSNull, search other classes
            static NSMutableArray *classList = nil;
            static NSMutableDictionary *signatureCache = nil;
            if (signatureCache == nil)
            {
                classList = [[NSMutableArray alloc] init];
                signatureCache = [[NSMutableDictionary alloc] init];

                //get class list
                int numClasses = objc_getClassList(NULL, 0);
                Class *classes = (Class *)malloc(sizeof(Class) * (unsigned long)numClasses);
                numClasses = objc_getClassList(classes, numClasses);

                //add to list for checking
                NSMutableSet *excluded = [NSMutableSet set];
                for (int i = 0; i < numClasses; i++)
                {
                    //determine if class has a superclass
                    Class someClass = classes[i];
                    Class superclass = class_getSuperclass(someClass);
                    while (superclass)
                    {
                        if (superclass == [NSObject class])
                        {
                            [classList addObject:someClass];
                        }
                        Class next = class_getSuperclass(superclass);
                        [excluded addObject:NSStringFromClass(superclass)];
                        superclass = next;
                    }
                }

                //remove all classes that have subclasses
                for (Class someClass in [classList reverseObjectEnumerator])
                {
                    if ([excluded containsObject:NSStringFromClass(someClass)])
                    {
                        [classList removeObject:someClass];
                    }
                }

                //free class list
                free(classes);
            }

            //check implementation cache first
            NSString *selectorString = NSStringFromSelector(selector);
            signature = [signatureCache objectForKey:selectorString];
            if (!signature)
            {
                //find implementation
                for (Class someClass in classList)
                {
                    if ([someClass instancesRespondToSelector:selector])
                    {
                        signature = [someClass instanceMethodSignatureForSelector:selector];
                        break;
                    }
                }

                //cache for next time
                [signatureCache setObject:signature ?: [NSNull null] forKey:selectorString];
            }
            else if ([signature isKindOfClass:[NSNull class]])
            {
                signature = nil;
            }
        }
        return signature;
    }
}

- (void)forwardInvocation:(NSInvocation *)invocation
{
    [invocation invokeWithTarget:nil];
}

#endif

@end

Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM