简体   繁体   English

从捆绑中加载Objective-C BIO

[英]Objective-c load BIO from bundle

I would like to load a text file using BIO_new_file(myPath, "r") in objective-c. 我想在Objective-C中使用BIO_new_file(myPath, "r")加载文本文件。 As path I obtain the current document directory from the bundle. 作为路径,我从分发包中获取当前文档目录。

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);
}

But the method couldn't load the file and I receive the Could not load file! 但是该方法无法加载文件,并且我收到Could not load file! .

Is this a known issue when using Openssl's BIO in objective-c? 在Objective-C中使用Openssl的BIO时,这是一个已知问题吗? Are there any workarounds? 有什么解决方法吗?

Perhaps there is no file named test.txt in your application's documents directory. 您的应用程序的文档目录中可能没有名为test.txt的文件。 Try logging the error code: 尝试记录错误代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM