【问题标题】:Sharing multiple files on App Via iTunes File Sharing (Code shows 1 file)通过 iTunes 文件共享在 App 上共享多个文件(代码显示 1 个文件)
【发布时间】:2011-11-05 14:09:52
【问题描述】:

我正在尝试使用 iTunes 文件共享文件共享多个文件。

这是当前代码。

委托.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;
}

目前只有 1 个文件被共享。

谢谢

【问题讨论】:

    标签: iphone objective-c cocoa-touch itunes


    【解决方案1】:

    我假设你想在 NSArray 中添加一堆文件?然后像这样循环遍历它:

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

    【讨论】:

    • 我试过了,但没有显示任何文件。我认为必须显示文件名?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多