我已按照此article对示例应用中的字母进行了正常工作,但在我现有的项目中,相同的代码并没有按照预期的那样做。这是代码:
ParentService:
-(MSCoreDataStore *)store{
if (_store == nil) {
NSManagedObjectContext * context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
context.parentContext=[[DataBaseDao sharedDao] managedObjectContext];
_store = [[MSCoreDataStore alloc] initWithManagedObjectContext:context];
}
return _store;
}
-(ParentService *) init
{
self = [super init];
if (self) {
// Initialize the Mobile Service client with your URL and key
self.client = [MSClient clientWithApplicationURLString:kApplicationURL
applicationKey:kApplicationKey];
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = delegate.managedObjectContext;
MSCoreDataStore *store = [[MSCoreDataStore alloc] initWithManagedObjectContext:context];
self.client.syncContext = [[MSSyncContext alloc] initWithDelegate:nil dataSource:store callback:nil];
}
return self;
}
以下是继承父服务的SearchService代码:
static SearchService *singletonInstance;
+ (SearchService*)getInstance{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
singletonInstance = [[super alloc] init];
});
return singletonInstance;
}
-(SearchService *) init
{
self = [super init];
if (self) {
_searchTable = [self.client syncTableWithName:@"Search"];
}
return self;
}
在addItem函数中,对insert进行调用时没有错误,并且自动生成的id与结果字典一起给出,并且调用syncData但服务器端没有更新。也无法从本地商店检索数据。我无法验证是否已将记录添加到商店,因为.sqlite要求输入密码。
我花了好几个小时搞清楚但没有运气。奇怪的是,我没有收到任何错误,这些错误告诉我,我可能会遗漏一些我需要在你的帮助下找出的东西。