Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 快照保存在缓存/快照中_Iphone_Ios_Ios4 - Fatal编程技术网

Iphone 快照保存在缓存/快照中

Iphone 快照保存在缓存/快照中,iphone,ios,ios4,Iphone,Ios,Ios4,**大家好, 我的应用的快照正在记录到缓存/快照文件夹中。出于安全考虑,我不需要记录这些快照。 我使用了下面这段代码,这段代码是我从net获得的,用于删除保存的快照: - (void)applicationDidEnterBackground:(UIApplication *)application { UIApplication* app = [UIApplication sharedApplication]; UIBackgroundTaskIdentifier __block bg

**大家好, 我的应用的快照正在记录到缓存/快照文件夹中。出于安全考虑,我不需要记录这些快照。 我使用了下面这段代码,这段代码是我从net获得的,用于删除保存的快照:

- (void)applicationDidEnterBackground:(UIApplication *)application {
UIApplication* app = [UIApplication sharedApplication];
    UIBackgroundTaskIdentifier __block bgTask;
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];

    if(UIBackgroundTaskInvalid != bgTask) {
        // Start the long-running task to kill app after some secs and return immediately.
        dispatch_after( dispatch_time(DISPATCH_TIME_NOW, KILL_IN_BACKGROUND_AFTER_SECS * 1e09), 
                       dispatch_get_main_queue(), ^{
                           if(goingToQuit) exit(0);
                           [app endBackgroundTask: bgTask];
                       });
    }
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // cancel ongoing background suicide.
    goingToQuit = NO;

}

我不想记录这些快照,请给出建议。**

我认为您没有添加代码来删除文件:(请参阅我的代码片段

- (void) deleteFiles {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self beingBackgroundUpdateTask];
        NSError *error = nil;
        // dirPath is path to your snapshot directory 
        NSArray *directoryContents = [fileMgr contentsOfDirectoryAtPath:dirPath error:&error];
        if (error == nil) {
            for (NSString *path in directoryContents) {
                 NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:path];
                 BOOL removeSuccess = [fileMgr removeItemAtPath:fullPath error:&error];
                 if (!removeSuccess) {
                     // Error handling
                     ...
                 }
            }
        } else {
            // Error handling
        }

        // Do something with the result 
       [self endBackgroundUpdateTask];
    });
}
- (void) beingBackgroundUpdateTask {
    self.backgroundUpdateTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [self endBackgroundUpdateTask];
    }];
}

- (void) endBackgroundUpdateTask {
    [[UIApplication sharedApplication] endBackgroundTask: self.backgroundUpdateTask];
    self.backgroundUpdateTask = UIBackgroundTaskInvalid;
}

创建者…所以我需要在ApplicationIdentinterBackground中调用[self-deleteFiles]。这是你说的吗?何时需要执行删除