自 iOS 15 以来的 NSKeyedUnarchiver 警告

NSKeyedUnarchiver Warnings since iOS 15

提问人:EK412 提问时间:10/13/2021 最后编辑:karelEK412 更新时间:9/10/2022 访问量:1166

问:

自 iOS 15 以来,我不断收到类似的警告。我使用的唯一框架是 Mapbox。是否有解决方法或修复方法?

2021-10-13 10:03:39.530114+0200 DemoApp[2661:532530] [general] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSNumber' (0x1dcadbe40) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.objects', even though it was not explicitly included in the client allowed classes set: '{(
    "'NSDictionary' (0x1dcad0c28) [/System/Library/Frameworks/CoreFoundation.framework]"
)}'. This will be disallowed in the future.
2021-10-13 10:03:39.530315+0200 DemoApp[2661:532530] [general] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSString' (0x1dcadb6e8) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.objects', even though it was not explicitly included in the client allowed classes set: '{(
    "'NSDictionary' (0x1dcad0c28) [/System/Library/Frameworks/CoreFoundation.framework]"
)}'. This will be disallowed in the future.
2021-10-13 10:03:39.530365+0200 DemoApp[2661:532530] [general] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSString' (0x1dcadb6e8) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.objects', even though it was not explicitly included in the client allowed classes set: '{(
    "'NSDictionary' (0x1dcad0c28) [/System/Library/Frameworks/CoreFoundation.framework]"
)}'. This will be disallowed in the future.
Swift Mapbox nskeyedunarchiver

评论

2赞 lorem ipsum 10/13/2021
如果您不控制写入/写入的文件,则无法对此执行任何操作,控制它们的人可能会发布更新。如果您确实控制了这些文件,则必须使这些结构/类符合 NSSecureCodingplist
0赞 Sapar Friday 10/14/2021
我也在包含 Firebase 的项目中看到了这一点。我们需要等待 pod 的更新。
0赞 shyla 3/2/2022
此警告有什么解决方案吗?请更新
0赞 EK412 3/16/2022
不,我自己仍在等待任何更新,并不断收到这些警告。

答:

0赞 Yohst 9/10/2022 #1

在代码(或库)中的某个位置,必须调用 NSKeyedUnarchiver,如下所示:

如果让 yourObject = try?NSKeyedUnarchiver.unarchivedObject(ofClass: yourclass.self, 来自:dataVariable) { }

“yourClass”包含一个必须显式允许的 String 对象,因此请将代码更改为:

如果让 yourObject = try?NSKeyedUnarchiver.unarchivedObject(ofClasses: [YourClass.self, NSString.self], from: dataVariable) 作为?您的班级 { }