Objective-C: NSCommand “airport -s” returning empty

本小妞迷上赌 提交于 2019-12-02 10:57:58

问题


I'm trying to run airport command to scan my wireless networks. Right now, the approach is to use NSTask. I'm running it as follow:

NSString *command = [NSString stringWithFormat:@"/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s"];
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/sh"];
NSArray *args = [NSArray arrayWithObjects:@"-c", command, nil];
[task setArguments: args];
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
[task launch];
[task waitUntilExit];
NSData *data = [[pipe fileHandleForReading] readDataToEndOfFile];
NSString *string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"RESULT: %@", string);

The problem is that its output comes as "RESULT:" (empty output). Additionally, when I run the same command with "-I" option, it correctly lists my current network statuses. So, I suppose that I'm mistaking on how to proper read the output of the airport command with -s option. Can someone give a hint on how to proper read it?


回答1:


Ok. By deeply investigating issues here, I've found this in my Console logs:

PMsandboxd: ([57108]) <MyApp>(57108) deny mach-lookup com.apple.airport
PMsandboxd: ([57108]) <MyApp>(57108) deny system-socket
PMsandboxd: ([57120]) sh(57120) deny file-read-data /dev/ttys003
PMairportd: Error: Scan failed (1)
PMsandboxd: ([57120]) airport(57120) deny system-socket

Well... looks like it is a permission issue. I'm still investigating here.

EDITED #1: Ok. If your app is sandboxed for Apple Store, sandbox deny NSTask from using airport scan!



来源:https://stackoverflow.com/questions/30874250/objective-c-nscommand-airport-s-returning-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!