Используя массив, загружая звуки в приложение для iTunes - PullRequest
0 голосов
/ 05 ноября 2011

Я пытаюсь поделиться несколькими файлами с общей папкой iTunes.

Вот текущий код.

Delegate.m

- (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;
}

В данный моментТолько 1 звуковой файл становится доступным.

Спасибо

Ответы [ 2 ]

0 голосов
/ 06 ноября 2011

Хотя это и не ответ на ваш вопрос, добавление песен в iTunes обычно выполняется с помощью Scripting Bridge .

. Вы должны сгенерировать заголовочный файл iTunes.h, запустив его в Terminal:

sdef /Applications/iTunes.app | sdp -fh --basename "iTunes"

А затем добавьте что-то вроде этого в свой код:

NSString *file = @"/path/to/test.mp3";
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier: @"com.apple.iTunes"];
iTunesTrack *track = [iTunes add: [NSArray arrayWithObject: [NSURL fileURLWithPath: file]] to: nil];
0 голосов
/ 05 ноября 2011

Поместите каждое из ваших имен файлов в NSArray:

NSArray filesToShare = [NSArray arrayWithObjects:@"Test1.mp3",@"Test2.mp3",@"Test3.mp3",@"Test4.mp3",@"Test5.mp3",nil];

for (NSString *filename in filesToShare)
{
    ... Your existing code goes here, 
}

Очевидно, что вы будете перемещать части, идентичные каждый раз перед циклом for (получение путей, создание файлового менеджера и т. Д.).

...