简体   繁体   中英

How to get unique path for Unzip folder on iOS

On 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.

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.

I will suggest you to use the timestamp, store it in 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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