Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.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 UIFileSharingEnabled仅保存文件_Iphone_Ios_Cocoa_Itunes_File Sharing - Fatal编程技术网

Iphone UIFileSharingEnabled仅保存文件

Iphone UIFileSharingEnabled仅保存文件,iphone,ios,cocoa,itunes,file-sharing,Iphone,Ios,Cocoa,Itunes,File Sharing,在我的iOS应用程序中,我希望用户可以通过iTunes下载一些jpg文件。所以我启用了UIFileShareingEnabled。但用户现在可以将文件放入我的应用程序中。我想阻止它。有办法吗 谢谢 不要认为你可以阻止它,但你可以在应用程序激活时删除不需要的文件 - (void) removeUnwantedFiles; { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUse

在我的iOS应用程序中,我希望用户可以通过iTunes下载一些jpg文件。所以我启用了UIFileShareingEnabled。但用户现在可以将文件放入我的应用程序中。我想阻止它。有办法吗


谢谢

不要认为你可以阻止它,但你可以在应用程序激活时删除不需要的文件

- (void) removeUnwantedFiles;
{    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSArray* directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:inboxPath error:NULL];

    if (!directoryContents || [directoryContents count] == 0)
    {
        return;
    }

    for (NSString* fileName in directoryContents)
    {
        if ( /* some test of filename to see if it's one of my kosher files */ ) continue;

        NSString* filePath = [documentsDirectory stringByAppendingPathComponent:fileName];
        NSError* error = nil;
        BOOL success = [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];
        // NSLog(@"Deleting (%@): %@", success ? @"succeeded" : @"failed", [filePath lastPathComponent]);
        if (!success)
        {
            NSLog(@"Error: %@", [error localizedDescription]);
        }
    }
}
放一些代码,有点像下面的示例-填写测试以避免删除您希望在iTunes中可用的文件

从应用程序委托的ApplicationIDBecomeActive:中调用此函数

如果你更谨慎的话,你可能需要检查用户是否丢弃了一个与你停放的jpg文件同名的jpg文件。你可以测试日期是否相同或类似,或者,如果你没有太多文件,只需删除所有内容,并在应用程序激活时再次写入即可

- (void) removeUnwantedFiles;
{    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSArray* directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:inboxPath error:NULL];

    if (!directoryContents || [directoryContents count] == 0)
    {
        return;
    }

    for (NSString* fileName in directoryContents)
    {
        if ( /* some test of filename to see if it's one of my kosher files */ ) continue;

        NSString* filePath = [documentsDirectory stringByAppendingPathComponent:fileName];
        NSError* error = nil;
        BOOL success = [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];
        // NSLog(@"Deleting (%@): %@", success ? @"succeeded" : @"failed", [filePath lastPathComponent]);
        if (!success)
        {
            NSLog(@"Error: %@", [error localizedDescription]);
        }
    }
}