【问题标题】:Objective-c load BIO from bundleObjective-c 从包中加载 BIO
【发布时间】:2012-03-07 18:16:34
【问题描述】:

我想在objective-c 中使用BIO_new_file(myPath, "r") 加载一个文本文件。 作为路径,我从包中获取当前文档目录。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"%@/test.txt", documentsDirectory];

NSLog(@"%@", fileName);

const char* cString = [fileName cStringUsingEncoding:NSUTF8StringEncoding];

BIO *temp = BIO_new_file(cString, "r");
if (!temp) {
    NSLog(@"Could not load file!");
    assert(false);
}

但该方法无法加载文件,我收到了Could not load file!

在 Objective-c 中使用 Openssl 的 BIO 时,这是一个已知问题吗?有什么解决方法吗?

【问题讨论】:

    标签: iphone objective-c ios openssl


    【解决方案1】:

    您的应用程序的文档目录中可能没有名为test.txt 的文件。尝试记录错误代码:

    NSLog(@"error code = %s (%d)", strerror(errno), errno);
    

    【讨论】:

    • 谢谢。我非常确定该文件必须存在,但它位于捆绑包根目录中而不是文档目录中。这样的转储失败花费了我 2 个小时...但那是软件开发... ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-19
    • 2015-10-11
    • 2013-03-04
    • 2020-01-19
    • 1970-01-01
    相关资源
    最近更新 更多