【发布时间】:2017-10-29 01:27:07
【问题描述】:
我解释了我的问题:我的计算机中有一些文件,我想通过我的 iPhone 读取它们,这要归功于 Wi-fi(Wi-fi 开始,然后是 3G 网络)。
我在我的计算机上打开了 WebServer(也许它不是解决我的问题的更好解决方案,我不知道),所以我成功地读取了具有如下确切路径的文件:
NSURL *serverFile = [NSURL URLWithString:@"http://192.168.1.9/AccountNumber.txt"]; NSString *number = [NSString stringWithContentsOfURL:serverFile encoding:NSUTF8StringEncoding error:nil]; NSLog(@"%@",number); // It works-
为了检查一个文件是否存在,我在这里使用 NSURLSession:
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:dossierDevice]; request.HTTPMethod = @"HEAD"; NSURLSession* session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]]; NSURLSessionDataTask* task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){ NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode]; if (statusCode == 200 || statusCode == 403) { NSLog(@"EXIST");// success } else { NSLog(@"DON'T EXIST");// failure } }]; [task resume]; 但现在我的问题是列出文件夹的文件。之前,当我从我的电脑对自己(使用模拟器)进行测试时,我使用了
contentsOfDirectoryAtPath,它工作得很好。 但是现在,当我使用像NSMutableArray *allAccounts = [[NSMutableArray alloc] initWithArray:[[NSFileManager defaultManager] contentsOfDirectoryAtURL:AccountFolder includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsHiddenFiles error:nil]];这样的东西时,它会返回一个空的 NSMutableArray。
我该如何解决这个问题?谢谢。
PS:我在枚举文件夹中的文件列表时遇到同样的问题
【问题讨论】:
标签: ios webserver nsurl nsfilemanager enumerator