Objective-C: NSCommand "airport -s" returning empty

411 views Asked by At

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

There are 1 answers

0
Marcelo On

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!