gpt4 book ai didi

ios - 如何在 Xcode 4.3 iOS 中更改文件扩展名?

转载 作者:行者123 更新时间:2023-11-28 19:17:03 31 4
gpt4 key购买 nike

我的想法:在没有 wifi 或蓝牙的情况下同步音乐。它是一种解决方法,可以使用相机连接套件在不越狱的情况下将文件复制到 iPad 或从 iPad 复制文件!首先我得到我想要的文件,然后我将它们压缩成一个 zip 文件。然后我想将扩展名重命名为 JPG,以便 iPad 可以识别该文件。然后我将它复制到我的 SD 卡,然后使用相机连接套件将它连接到我的 iPad。

我想让我的应用复制整个 jpg 格式的 dcim,这样我就可以将文件扩展名改回 zip,然后解压它以检索我的文件。

但到目前为止,我只找到了一种将文件/jpg 复制到我的应用程序中的方法,但现在我需要将文件扩展名更改回 zip,然后将其导出到另一个应用程序,以便解压缩以检索我的文件。

Ps:我只需要弄清楚如何在应用程序中更改文件扩展名并导出它!

最佳答案

更改文件扩展名很容易,因为 iOS 不支持文件重命名。只需复制文件并将其写入包含 zip 扩展名的路径:

//get the documents directory
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

//append the name of the file in jpg form
NSString *jpgPath = [documentsDirectory stringByAppendingPathComponent:@"myFile.jpg"];

//check if the file exists (completely unnecessary).
if ([fileManager fileExistsAtPath:jpgPath]) {
//get new resource path with different extension
NSString *resourcePath = [documentsDirectory stringByAppendingPathComponent:@"myFile.zip"];
//copy it over
[fileManager copyItemAtPath:jpgPath toPath:resourcePath error:&error];
}

关于ios - 如何在 Xcode 4.3 iOS 中更改文件扩展名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11379602/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com