Pergunta

I want to replace all my old PDFs for new ones in my iPhone app (that I put in my proyect), but I can not do it. In some cases the app still is showing me old files.... what can be the problem? I need to delete the old ones from iPhone memory by code to do the update...

any help is really appreciated

    NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];
    NSArray *contenido = [fileManager contentsOfDirectoryAtPath: appFolderPath error:nil];

    NSEnumerator *e = [contenido objectEnumerator];
    NSString *filename;
    while ((filename = [e nextObject])) {

        if ([[filename pathExtension] isEqualToString:@"pdf"]) {
            //NSLog(@"Archivo %@", filename); me da el nomber SCEL VAC.pdf
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectoryPath = [paths objectAtIndex:0];

            NSString *myFilePath = [documentsDirectoryPath stringByAppendingPathComponent:filename];
            //NSLog(@"path archivo %@", myFilePath);// me da dentro de documents

            if ([fileManager fileExistsAtPath:myFilePath] == NO) {
                NSString *resourcePath = [[NSBundle mainBundle] pathForResource:filename ofType:nil];
                bool success = [fileManager copyItemAtPath:resourcePath toPath:myFilePath error:&error1];
                if (success){
                    NSLog(@"instalado %@", myFilePath);
                }
            }else if ([fileManager fileExistsAtPath:myFilePath] == YES)
            {
                bool success = [fileManager removeItemAtPath:myFilePath error:&error1];
                if (success){
                NSLog(@"borrado %@", myFilePath);
                }

                NSString *resourcePath = [[NSBundle mainBundle] pathForResource:filename ofType:nil];

                bool success2 = [fileManager copyItemAtPath:resourcePath toPath:myFilePath error:&error1];
                if (success2){
                NSLog(@"copiado %@", myFilePath);
                }
            }

        }
    }
Foi útil?

Solução

You can not change any files in the a main bundle it is readonly.

Thus in your update, you should remove the old PDFS from you project and then they are no longer available in the main bundle.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top