NSKeyedArchiver 和 NSKeyedUnarchiver 取决于 bundli-ID

NSKeyedArchiver & NSKeyedUnarchiver depending on bundli-ID

-> 我收到以下错误,表明序列化对象取决于 bundli-ids ?

请有人告诉我,这不是真的,并且有一个变通方法可以让一个应用程序目标写入对象,另一个目标读取对象。

有什么帮助吗?

NSKeyedUnarchiver.unarchiveObjectWithData(数据!);

2016-01-15 10:21:11.476 APP_TARGET1[1684:38753] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (APP_TARGET2.MapTheme) for key (root); the class may be defined in source code or a library that is not linked'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010f5cce65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010f043deb objc_exception_throw + 48
    2   Foundation                          0x000000010ec8835e -[NSCoder(Exceptions) __failWithExceptionName:errorCode:format:] + 0
    3   Foundation                          0x000000010ec88572 -[NSCoder(Exceptions) __failWithExceptionName:errorCode:format:] + 532
    4   Foundation                          0x000000010ebe3927 _decodeObjectBinary + 1659
    5   Foundation                          0x000000010ebe31a5 _decodeObject + 281
    6   Foundation                          0x000000010ec05931 +[NSKeyedUnarchiver unarchiveObjectWithData:] + 89
    7   WorldHistoryAtlasTest               0x000000010e748c11 _TF21WorldHistoryAtlasTest15loadThemeasBlobFSST6existsSb8mapThemeCS_8MapTheme_ + 3745
    8   WorldHistoryAtlasTest               0x000000010e781d9f _TFC21WorldHistoryAtlasTest22TimeLineViewController18load_map_meta_datafS0_FT_T_ + 207
    9   WorldHistoryAtlasTest               0x000000010e781231 _TFC21WorldHistoryAtlasTest22TimeLineViewController11viewDidLoadfS0_FT_T_ + 5889
    10  WorldHistoryAtlasTest               0x000000010e781cb2 _TToFC21WorldHistoryAtlasTest22TimeLineViewController11viewDidLoadfS0_FT_T_ + 34
    11  UIKit                               0x00000001102f9f98 -[UIViewController loadViewIfRequired] + 1198
    12  UIKit                               0x00000001102fa2e7 -[UIViewController view] + 27
    13  UIKit                               0x0000000110aa4f87 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87
    14  UIKit                               0x00000001102c9f62 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 133
    15  UIKit                               0x000000011030cc8c -[UIViewController _presentViewController:withAnimationController:completion:] + 4002
    16  UIKit                               0x000000011030ff2c -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 489
    17  UIKit                               0x000000011030fa3b -[UIViewController presentViewController:animated:completion:] + 179
    18  WorldHistoryAtlasTest               0x000000010e6ba862 _TFC21WorldHistoryAtlasTest14ViewController12showTimelinefS0_FT_T_ + 594
    19  WorldHistoryAtlasTest               0x000000010e6b7ff2 _TFC21WorldHistoryAtlasTest14ViewController10loadModulefS0_FSST_ + 4002
    20  WorldHistoryAtlasTest               0x000000010e6d7036 _TFFFC21WorldHistoryAtlasTest14ViewController10loadModuleFS0_FSST_U2_FT_T_U0_FT_T_ + 86
    21  WorldHistoryAtlasTest               0x000000010e632d57 _TTRXFo__dT__XFdCb__dT__ + 39
    22  libdispatch.dylib                   0x0000000111d03e5d _dispatch_call_block_and_release + 12
    23  libdispatch.dylib                   0x0000000111d2449b _dispatch_client_callout + 8
    24  libdispatch.dylib                   0x0000000111d0c2af _dispatch_main_queue_callback_4CF + 1738
    25  CoreFoundation                      0x000000010f52cd09 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    26  CoreFoundation                      0x000000010f4ee2c9 __CFRunLoopRun + 2073
    27  CoreFoundation                      0x000000010f4ed828 CFRunLoopRunSpecific + 488
    28  GraphicsServices                    0x0000000113f94ad2 GSEventRunModal + 161
    29  UIKit                               0x0000000110163610 UIApplicationMain + 171
    30  WorldHistoryAtlasTest               0x000000010e7414fd main + 109
    31  libdyld.dylib                       0x0000000111d5992d start + 1
    32  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

更新

尝试实施解决方案:

class BlobHandler: NSObject , NSKeyedUnarchiverDelegate{


let data:NSData? = NSData(bytes: point, length: Int(len));
                    //NSKeyedUnarchiver.set

                                  var mykeyedunarchiver:NSKeyedUnarchiver=NSKeyedUnarchiver(forReadingWithData: data!);
                mykeyedunarchiver.delegate = self;
                let temp=mykeyedunarchiver.decodeObject();

..... .... ....

   func unarchiver(_ unarchiver: NSKeyedUnarchiver, cannotDecodeObjectOfClassName name: String, originalClasses classNames: [String]) -> AnyClass? {

        print("I am in the delegated method !");
        return nil;

    }

问题不在于 bundle id,问题在于 classes 编译不同,因为它们内置在不同的目标中。

您可以通过向键控解压器添加委托并实现来处理此问题:

optional func unarchiver(_ unarchiver: NSKeyedUnarchiver, cannotDecodeObjectOfClassName name: String, originalClasses classNames: [String]) -> AnyClass?

以便您可以检查请求的 class 名称和 return 当前目标中的适当匹配 class。