2011-11-05 5 views
0

Je suis en train de partager des fichiers multiples avec partage de fichiers iTunes.Partage de plusieurs fichiers sur l'application via le partage de fichiers iTunes (code montre 1 fichier)

Voici le code actuel.

Delegate.h

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    // Override point for customization after application launch. 

    // file sharing trying 
    { 
     NSString *fileName = @"Test.mp3"; 
     NSFileManager *fileManager = [NSFileManager defaultManager]; 
     NSError *error; 
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *documentsDirectory = [paths objectAtIndex:0]; 
     NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:fileName]; 

     if (![fileManager fileExistsAtPath:documentDBFolderPath]) 
     { 
      NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName]; 
      [fileManager copyItemAtPath:resourceDBFolderPath toPath:documentDBFolderPath error:&error]; 
     } 
    } 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

Actuellement, seulement 1 fichier est partagé.

Merci

Répondre

0

Je suppose que vous voulez ajouter un tas de fichiers dans un NSArray? puis bouclez-le comme ceci:

NSArray *names = [NSArray arrayWithObjects: @"foo", @"bar", nil]; 
for (NSString *fileName in names) 
{ 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    NSError *error; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:fileName]; 

    if (![fileManager fileExistsAtPath:documentDBFolderPath]) 
    { 
     NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName]; 
     [fileManager copyItemAtPath:resourceDBFolderPath toPath:documentDBFolderPath error:&error]; 
    } 
} 
+0

J'ai essayé ceci, mais aucun des fichiers montrés. Je pensais que les noms de fichiers devraient être affichés? –

Questions connexes