2

我正在使用RestKit(0.10.0)和后端的Core Data使用以下方法从服务器加载编辑的对象。每当应用程序进入前台时,都会调用该方法作为同步过程的一部分。

[syncObjectManager loadObjectsAtResourcePath:[NSString stringWithFormat:@"?config=accounts&since=%@", lastSync] usingBlock:^(RKObjectLoader *loader) {
    [loader.mappingProvider setObjectMapping:companyMappingSync forKeyPath:@"data"];
    loader.backgroundPolicy = RKRequestBackgroundPolicyContinue;
    loader.delegate = self;
}];

响应加载正常,并且似乎也找到了缓存。

2012-04-11 15:58:32.147 mobileCRM[3575:707] T restkit.support:RKCache.m:82 Found cachePath '/var/mobile/Applications/C5E4BF4F-4CB0-4F4C-AC11-FC1E17AE4AF2/Library/Caches/RKClientRequestCache-www.URLTOSERVER.de/PermanentStore/37abc4aff62918578288d10530e6bcd6' for PermanentStore/37abc4aff62918578288d10530e6bcd6
2012-04-11 15:58:32.152 mobileCRM[3575:707] T restkit.support:RKCache.m:119 Wrote cached data to path '/var/mobile/Applications/C5E4BF4F-4CB0-4F4C-AC11-FC1E17AE4AF2/Library/Caches/RKClientRequestCache-www.URLTOSERVER.de/PermanentStore/37abc4aff62918578288d10530e6bcd6'
2012-04-11 15:58:32.158 mobileCRM[3575:707] T restkit.support:RKCache.m:100 Writing dictionary to cache key: 'PermanentStore/37abc4aff62918578288d10530e6bcd6.headers'
2012-04-11 15:58:32.159 mobileCRM[3575:707] T restkit.support:RKCache.m:82 Found cachePath '/var/mobile/Applications/C5E4BF4F-4CB0-4F4C-AC11-FC1E17AE4AF2/Library/Caches/RKClientRequestCache-www.URLTOSERVER.de/PermanentStore/37abc4aff62918578288d10530e6bcd6.headers' for PermanentStore/37abc4aff62918578288d10530e6bcd6.headers
2012-04-11 15:58:32.166 mobileCRM[3575:707] T restkit.support:RKCache.m:103 Wrote cached dictionary to cacheKey 'PermanentStore/37abc4aff62918578288d10530e6bcd6.headers'

在测试属性“street”中的更改时,更改也会被映射。

2012-04-11 15:58:33.013 mobileCRM[3575:1a03] T restkit.object_mapping:RKObjectMappingOperation.m:332 Mapped attribute value from keyPath 'street' to 'street'. Value: Musterweg 55

完成操作后,我正在调用一个新的 fetchRequest 并重新加载所属的表视图。

问题

在第一次调用之后,以某种方式更改的对象没有保存在后端(即使 Core Data 显示 COMMIT 消息)。

2012-04-11 16:05:44.235 mobileCRM[3603:351f] I restkit.core_data:RKInMemoryEntityCache.m:131 Caching all 2861 Company objectsIDs to thread local storage
2012-04-11 16:05:44.354 mobileCRM[3603:351f] CoreData: sql: BEGIN EXCLUSIVE
2012-04-11 16:05:44.357 mobileCRM[3603:351f] CoreData: sql: UPDATE ZCOMPANY SET ZSTREET = ?, Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
2012-04-11 16:05:44.361 mobileCRM[3603:351f] CoreData: sql: COMMIT

但是当我再次打开应用程序以再次调用该方法时,刷新的数据会按预期显示。因此,我正在努力使该方法在第一次通话时起作用。

谢谢你的想法!

4

1 回答 1

1

检查输出后

// App Delegate
RKLogConfigureByName("RestKit/*", RKLogLevelTrace);

// Scheme
-com.apple.CoreData.SQLDebug 1

我意识到我在核心数据中的数据提交完成之前重新加载了数据。

因此,即使我使用的是 RKRequestQueue,也可以使用以下方法解决问题。

- (void)objectLoaderDidFinishLoading:(RKObjectLoader *)objectLoader
{
    // Send notification to tableView
    [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshTableView" object:self];
}

...它的工作原理。:)

于 2012-04-12T10:17:48.860 回答