Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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
Objective c 验证安全范围的书签数据_Objective C_Cocoa_Osx Mountain Lion_Sandbox - Fatal编程技术网

Objective c 验证安全范围的书签数据

Objective c 验证安全范围的书签数据,objective-c,cocoa,osx-mountain-lion,sandbox,Objective C,Cocoa,Osx Mountain Lion,Sandbox,问谷歌“有效的安全范围书签”,我没有得到一个好结果。无论如何,我在保存和阅读安全范围的书签方面没有问题。我有一个XML文件,它保存了一个NSMutableArray,其中只列出了用户选择的导出路径的一个安全范围的书签。应用程序使用以下方法读取此书签 - (void)loadBookmarks { if ([self fileExists:[self filePath1]]) { // function NSMutableArray *items = [[NSMutable

问谷歌“有效的安全范围书签”,我没有得到一个好结果。无论如何,我在保存和阅读安全范围的书签方面没有问题。我有一个XML文件,它保存了一个NSMutableArray,其中只列出了用户选择的导出路径的一个安全范围的书签。应用程序使用以下方法读取此书签

- (void)loadBookmarks {
    if ([self fileExists:[self filePath1]]) { // function
        NSMutableArray *items = [[NSMutableArray alloc] initWithContentsOfFile:[self filePath2]];
        key2a = @"KEY2a";
        for (NSInteger i5 = 0; i5 < items.count; i5++) {
            NSData *k1 = [[items objectAtIndex:i5] objectForKey:@"KEY2a"]; // bookmark

            // Start Security-scoped bookmark //
            NSURL *bookmarkFileURL;
            bookmarkFileURL = [self convertBookmarktoURL:k1]; // function
            [bookmarkFileURL startAccessingSecurityScopedResource]; // <<< no error
            // End Security-scoped bookmark //

            dict2 = [NSDictionary dictionaryWithObjectsAndKeys:k1,key2a,nil];
            [bookmarkArray1 addObject:dict2];
        } // End for
    }
}
-(无效)加载书签{
if([self-fileExists:[self-filePath1]]){//函数
NSMutableArray*items=[[NSMutableArray alloc]initWithContentsOfFile:[self-filePath2]];
key2a=@“key2a”;
对于(NSInteger i5=0;i5[bookmarkFileURL startAccessingSecurityScopedResource];//我似乎需要检查nsurlbookmarksolutionwithsecurityscope返回的错误

- (NSURL *)convertBookmarktoURL:(NSData *)bookmarkData {
    NSError *error = nil;
    BOOL bookmarkDataIsStale;
    if (error != NULL) {
        return NULL;
    } else {
        return [NSURL URLByResolvingBookmarkData:bookmarkData options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&bookmarkDataIsStale error:&error];
    }
}


// data is NSData
if ([self convertBookmarktoURL:data] != NULL) {
    // valid
} else {
    // invalid bookmark
}

《应用程序沙盒设计指南》中说:“当您以后需要访问书签资源时,请通过调用NSURL类的URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:method来解析其安全范围内的书签。”