Objective c 使用阵列,将声音加载到iTunes应用程序
我正在尝试使用iTunes文件共享来共享多个文件 这是当前的代码 代表,mObjective c 使用阵列,将声音加载到iTunes应用程序,objective-c,ios,xcode,cocoa-touch,itunes,Objective C,Ios,Xcode,Cocoa Touch,Itunes,我正在尝试使用iTunes文件共享来共享多个文件 这是当前的代码 代表,m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // file sharing trying
- (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;
}
目前只有一个声音文件被共享
谢谢将您的每个文件名放入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循环之前(获取路径、创建文件管理器等) 虽然不是你问题的答案,但在iTunes中添加歌曲通常是由用户完成的 您应该通过在终端中运行以下命令来生成iTunes.h头文件:
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];
这段代码将单个文件从捆绑包复制到documents目录。您遇到问题的代码在哪里?你想做什么?我想共享多个文件。我有5个mp3想要共享,但代码只共享1个mp3。谢谢,我试过密码了。但是,这些项目现在没有在iTunes中显示。该应用程序显示但不显示任何项目。