Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/147.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
Ios 是否将资源plist文件复制到应用程序支持文件夹?_Ios_Plist_Nsfilemanager - Fatal编程技术网

Ios 是否将资源plist文件复制到应用程序支持文件夹?

Ios 是否将资源plist文件复制到应用程序支持文件夹?,ios,plist,nsfilemanager,Ios,Plist,Nsfilemanager,是否有办法将plist文件复制到iOS中的应用程序支持文件夹 下面的方法返回应用程序支持文件夹路径,但我需要将资源plist文件复制到该文件夹中。而不是使用CopyItemAtUrl方法,然后从捆绑包中删除 - (NSURL*)applicationDataDirectory { NSFileManager* sharedFM = [NSFileManager defaultManager]; NSArray* possibleURLs = [sharedFM URLsFor

是否有办法将plist文件复制到iOS中的应用程序支持文件夹

下面的方法返回应用程序支持文件夹路径,但我需要将资源plist文件复制到该文件夹中。而不是使用CopyItemAtUrl方法,然后从捆绑包中删除

- (NSURL*)applicationDataDirectory {

    NSFileManager* sharedFM = [NSFileManager defaultManager];

    NSArray* possibleURLs = [sharedFM URLsForDirectory:NSApplicationSupportDirectory
                                             inDomains:NSUserDomainMask];
    NSURL* appSupportDir = nil;
    NSURL* appDirectory = nil;

    if ([possibleURLs count] >= 1) {
        // Use the first directory (if multiple are returned)
        appSupportDir = [possibleURLs objectAtIndex:0];
    }

    // If a valid app support directory exists, add the
    // app's bundle ID to it to specify the final directory.

    if (appSupportDir) {
        NSString* appBundleID = [[NSBundle mainBundle] bundleIdentifier];
        appDirectory = [appSupportDir URLByAppendingPathComponent:appBundleID];
    }

    return appDirectory;
}

框架返回到应用程序支持文件夹的正确路径,但与文档文件夹不同,默认情况下不会创建该文件夹

使用NSFileManager的替代API,该API能够隐式创建文件夹

- (NSURL*)applicationDataDirectory {

    NSFileManager* sharedFM = [NSFileManager defaultManager];
    NSURL* appSupportDir = [sharedFM URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
    // add the app's bundle ID to it to specify the final directory.

    NSString* appBundleID = [[NSBundle mainBundle] bundleIdentifier];
    return [appSupportDir URLByAppendingPathComponent:appBundleID];
}
请注意,您也负责创建子文件夹

- (NSURL*)applicationDataDirectory {

    NSFileManager* sharedFM = [NSFileManager defaultManager];
    NSURL* appSupportDir = [sharedFM URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
    // add the app's bundle ID to it to specify the final directory.

    NSString* appBundleID = [[NSBundle mainBundle] bundleIdentifier];
    NSURL* appDirectory = [appSupportDir URLByAppendingPathComponent:appBundleID];
    if (![appDirectory checkResourceIsReachableAndReturnError:nil]) {
        [sharedFM createDirectoryAtURL:appDirectory withIntermediateDirectories:NO attributes:nil error:nil];
    }
    return appDirectory;
}

因此,为了澄清,您想将.plist文件从应用程序包复制到应用程序支持文件夹中吗?这样做有什么问题?没有。我可以手动将文件拖到应用程序支持中吗?。而不是将文件从捆绑包复制到应用程序文件夹,然后从捆绑包中删除文件。