简体   繁体   English

如何在iOS上获取Unzip文件夹的唯一路径

[英]How to get unique path for Unzip folder on iOS

On iOS: 在iOS上:

How to fix this entire problume of unziping file, getting uniqe path name, use this path in other views and deleting catch files once view did unload? 如何解决整个问题的解压缩文件,获取唯一路径名,在其他视图中使用此路径以及在视图卸载后删除捕获文件?

Create a unique temporary directory using mkdtmp (declared in unistd.h ), then expand to that dir. 使用mkdtmp (在unistd.h声明)创建一个唯一的临时目录,然后扩展到该目录。

Then if you need it someplace more specific, move safely (eg in a way that is guaranteed not to replace existing files/directories). 然后,如果需要在更特定的地方使用它,请安全移动(例如,以确保不会替换现有文件/目录的方式)。 -[NSFileManager replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:] seems capable of the move, if you prefer a Foundation API. -[NSFileManager replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:]似乎可以移动,如果您更喜欢Foundation API。

I will suggest you to use the timestamp, store it in NSUserDefaults. 我建议您使用时间戳记,并将其存储在NSUserDefaults中。

On applicationWillTerminate method of your AppDelegate, you check if NSUserDefaults has the key you set, if it have, then you delete the file, and remove the key. 在AppDelegate的applicationWillTerminate方法上,检查NSUserDefaults是否具有设置的密钥,如果已设置,则删除文件,然后删除密钥。

- (void)applicationWillTerminate:(UIApplication *)application
{
    if([[NSUserDefaults standardUserDefaults] objectForKey:@"KEY_FOR_PATH"] != nil)
    {
        [[NSFileManager defaultManager] removeItemAtPath:[[NSUserDefaults standardUserDefaults] objectForKey:@"KEY_FOR_PATH"] error:nil];
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"KEY_FOR_PATH"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM