【发布时间】:2017-11-08 14:33:18
【问题描述】:
我通过 Crashlytics 看到崩溃,并从客户那里得知应用程序在打开时就崩溃了。
这仅限于迁移领域数据库之一的应用程序。很遗憾,我无法重现该问题,因为我无法理解所看到的错误。
我有逻辑检查应用程序何时启动以检查领域是否需要压缩。当这样做时,领域确定它需要被迁移并命中迁移块。
config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
if (oldSchemaVersion < 17) {
[migration enumerateObjects:Event.className block:^(RLMObject *oldObject, RLMObject *newObject) {
NSString *className = [[oldObject[@"endDateTime"] objectSchema] className];
if ([className isEqualToString:@"DateObject"]) {
newObject[@"endDateTime"] = oldObject[@"endDateTime"][@"value"];
}
}];
}
};
由于我在进行之前的迁移时出错,我在决定迁移之前手动检查属性是否属于特定类型。 不幸的是,根据 Crashlytics,应该是 RLMObject 类型的 oldObject 似乎是 NSTaggedDate 类型
[__NSTaggedDate objectSchema]: unrecognized selector sent to instance 0xe41bf592ee000000
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x186419d04 __exceptionPreprocess
1 libobjc.A.dylib 0x185668528 objc_exception_throw
2 CoreFoundation 0x1864271c8 __methodDescriptionForSelector
3 CoreFoundation 0x18641f6b0 ___forwarding___
4 CoreFoundation 0x18630501c _CF_forwarding_prep_0
5 MY_mobile_ios_common 0x10199c8c0 __34+[MYRealm getRealmConfigByName:]_block_invoke_2 (MYRealm.m:44)
6 Realm 0x1011b6598 -[RLMMigration enumerateObjects:block:] (RLMMigration.mm:99)
7 MY_mobile_ios_common 0x10199c830 __34+[MYRealm getRealmConfigByName:]_block_invoke (MYRealm.m:40)
8 Realm 0x1011b6ab4 -[RLMMigration execute:] (RLMMigration.mm:131)
9 Realm 0x1012297ec std::__1::__function::__func<+[RLMRealm realmWithConfiguration:error:]::$_1, std::__1::allocator<+[RLMRealm realmWithConfiguration:error:]::$_1>, void (std::__1::shared_ptr<realm::Realm>, std::__1::shared_ptr<realm::Realm>, realm::Schema&)>::operator()(std::__1::shared_ptr<realm::Realm>&&, std::__1::shared_ptr<realm::Realm>&&, realm::Schema&) (RLMRealm.mm:410)
10 Realm 0x10124fa90 std::__1::__function::__func<realm::Realm::update_schema(realm::Schema, unsigned long long, std::__1::function<void (std::__1::shared_ptr<realm::Realm>, std::__1::shared_ptr<realm::Realm>, realm::Schema&)>, std::__1::function<void (std::__1::shared_ptr<realm::Realm>)>, bool)::$_2, std::__1::allocator<realm::Realm::update_schema(realm::Schema, unsigned long long, std::__1::function<void (std::__1::shared_ptr<realm::Realm>, std::__1::shared_ptr<realm::Realm>, realm::Schema&)>, std::__1::function<void (std::__1::shared_ptr<realm::Realm>)>, bool)::$_2>, void ()>::operator()() (memory:4625)
11 Realm 0x101181f64 realm::ObjectStore::apply_schema_changes(realm::Group&, unsigned long long, realm::Schema&, unsigned long long, realm::SchemaMode, std::__1::vector<realm::SchemaChange, std::__1::allocator<realm::SchemaChange> > const&, std::__1::function<void ()>) (object_store.cpp:753)
12 Realm 0x10124bbb8 realm::Realm::update_schema(realm::Schema, unsigned long long, std::__1::function<void (std::__1::shared_ptr<realm::Realm>, std::__1::shared_ptr<realm::Realm>, realm::Schema&)>, std::__1::function<void (std::__1::shared_ptr<realm::Realm>)>, bool) (functional:1860)
13 Realm 0x101226a10 +[RLMRealm realmWithConfiguration:error:] (functional:1860)
14 MY_mobile_ios_common 0x10199cba0 +[MYRealm mainRealmCompact] (MYRealm.m:137)
15 MY App 0x1002b49dc -[AppDelegate compactRealmIfNeeded] (AppDelegate.m:808)
16 MY App 0x1002af940 -[AppDelegate application:didFinishLaunchingWithOptions:] (AppDelegate.m:48)
任何关于我在这里可能做错的想法,我将删除领域数据库并强制用户再次返回初始加载数据。
产品名称:Mac OS X 产品版本:10.12.6 构建版本:16G1036
/Applications/Xcode.app/Contents/Developer Xcode 9.1 构建版本 9B55
/usr/local/bin/pod 1.3.1 领域 (2.10.2) 领域 (= 2.10.2)
/bin/bash GNU bash,版本 3.2.57(1)-release (x86_64-apple-darwin16)
(此处未使用)
/usr/local/bin/git git 版本 2.12.2
【问题讨论】:
-
在结束之前检查
if ([[oldObject[@"endDateTime"] isKindOfClass:[NSDate date]){//Do something else because it's a date, not an object of the class where you can callobjectSchema`} else //做你的事。;`?
标签: objective-c realm realm-migration