gpt4 book ai didi

ios - 自 iOS8 以来,NullSafe 在 UIKit/Webkit/UIWebViewPDF/UIWebView/UIWebDocumentView/... 上崩溃

转载 作者:行者123 更新时间:2023-12-02 03:30:26 32 4
gpt4 key购买 nike

好吧,这个 iOS8 开始引起很多问题,这就是其中之一。

我正在使用 NullSafe 库(您可以在 github 上找到),在解析空内容时它基本上返回 nil 而不是异常。

现在,当 NullSafe 工作时,它只是浏览所有类(来自项目中的每个框架/ bundle /套件)。我不太有信心理解为什么这个 Nullsafe 库会这样做,但它确实做到了,而且现在崩溃了。

调试时,崩溃时检查的类有所不同,但我们永远无法在苹果文档或 bundle 中的任何位置找到它......所以我的结论是:

NullSafe 似乎正在尝试浏览不存在的类

  • 我无法真正摆脱 NullSafe,或者至少我想尝试不这样做暂时到。
  • 它总是出现与 View 相关的崩溃类。
  • 当我们寻找它们时,它们似乎从未存在过。

你们中有人使用 NullSafe 或了解它,以便我们可以尝试继续吗?

最佳答案

联系 Nick(Nullsafe 的制造商)后,我发现我的问题消失了。他刚刚给了我最新版本,1.2.1。

这是完整的 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

希望这有帮助:)

关于ios - 自 iOS8 以来,NullSafe 在 UIKit/Webkit/UIWebViewPDF/UIWebView/UIWebDocumentView/... 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25969633/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com