Ios 现有项目上的Azure移动服务脱机同步

Ios 现有项目上的Azure移动服务脱机同步,ios,azure-mobile-services,Ios,Azure Mobile Services,我在示例应用程序中遵循了这一点,它工作得很好,但在我现有的项目中,相同的代码并没有达到预期的效果。代码如下: 家长服务: -(MSCoreDataStore *)store{ if (_store == nil) { NSManagedObjectContext * context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];

我在示例应用程序中遵循了这一点,它工作得很好,但在我现有的项目中,相同的代码并没有达到预期的效果。代码如下:

家长服务:

-(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;
}
此外,调用insert函数时不会出现错误,自动生成的id随结果字典一起给出,调用syncData时不会在服务器端进行更新。也无法从本地存储检索数据。我无法验证记录是否已添加到存储,因为.sqlite要求输入密码


我花了几个小时才弄明白,但运气不好。奇怪的是,我没有得到任何错误,这告诉我,我可能遗漏了一些我需要在你的帮助下找出的东西

我猜您没有在客户端上初始化syncContext。能否将客户端初始化代码添加到代码段中。@phillipv我已更新了问题。谢谢,您的init未使用自定义get存储,不确定这是否会导致您的问题。当您说无法从本地存储检索时,您的意思是调用syncTable insert:后该记录不在搜索表中?该搜索与您提供的MSSyncContext在同一个NSManagedObject上?哦,是的,如果您想创建一个工作区,您可以使用代码并逐步查看可能发生的情况,这可能会更快: