Не удалось загрузить UIDocuments на отдельных устройствах

Я создал UIDocument, чтобы обернуть пользовательский объект. UIDocument успешно сохраняется в iCloud, и я успешно загружаю каждый UIDocument при каждом запуске приложения. Тем не менее, когда я пытаюсь запустить приложение на новом устройстве (iPhone 5), оно не загружает какой-либо UIDocument из iCloud, но я могу проверить iCloud в разделе "Настройки" и увидеть файлы, сохраненные в моем приложении. У кого-нибудь есть какие-то шаги, чтобы проверить, почему одно устройство (iPhone 4) может загружаться, а другое (iPhone 5) - нет? Я также не могу создать новый UIDocument с устройства iPhone 5.

РЕДАКТИРОВАТЬ

- (void)loadObjects
{
    if (!self.objects)
    {
        self.objects = [[NSMutableArray alloc] init];
    }

    NSURL *baseURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];

    if (baseURL)
    {
        self.query = [[NSMetadataQuery alloc] init];
        [self.query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];

        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like 'Object_*'", NSMetadataItemFSNameKey];
        [self.query setPredicate:predicate];

        NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
        [nc addObserver:self selector:@selector(queryDidFinish:) name:NSMetadataQueryDidFinishGatheringNotification object:self.query];
        [nc addObserver:self selector:@selector(queryDidUpdate:) name:NSMetadataQueryDidUpdateNotification object:self.query];

        [self.query startQuery];
    }
}

- (void)queryDidFinish:(NSNotification *)notification
{
    [self processQueryResults:notification.object];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:notification.object];

    self.query = nil;
}

- (void)queryDidUpdate:(NSNotification *)notification
{
    [self processQueryResults:notification.object];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:notification.object];

    self.query = nil;
}

- (void)processQueryResults:(NSMetadataQuery *)query
{
    [query disableUpdates];

    [query stopQuery];

    [self.objects removeAllObjects];

    [query.results enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
    {
        NSURL *documentURL = [(NSMetadataItem *)obj valueForAttribute:NSMetadataItemURLKey];

        ObjectDocument *document = [[ObjectDocument alloc] initWithFileURL:documentURL];

        [document openWithCompletionHandler:^(BOOL success) {
            if (success) {
                [self.objects addObject:document];

                [self sortObjects];

                [self.tableView reloadData];
            }
        }];
    }];

    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)save:(Object *)object
{
    NSURL *baseURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];

    if (baseURL)
    {
        NSURL *documentsURL = [baseURL URLByAppendingPathComponent:@"Documents"];

        NSURL *documentURL = [documentsURL URLByAppendingPathComponent:[NSString stringWithFormat:@"Object_%f", [object.date timeIntervalSince1970]]];

        TVBFlightDocument *document = [[ObjectDocument alloc] initWithFileURL:documentURL];
        document.object = object;

        [document saveToURL:documentURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
            if (success) {
                NSLog(@"Save succeeded.");

                [_objects addObject:document];

                [self sortObjects];
            } else {
                NSLog(@"Save failed.");
            }
        }];
    }
}

Приложение на iPhone 5 не будет загружать объекты, хранящиеся в iCloud, но iPhone 4 будет загружать объекты из документов iCloud.

0 ответов

Другие вопросы по тегам