forked from bored-engineer/iOS-sbutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbtoggle.mm
43 lines (31 loc) · 1.32 KB
/
sbtoggle.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#import <Foundation/Foundation.h>
#import <AppSupport/CPDistributedMessagingCenter.h>
#import <stdio.h>
void usage() {
fprintf(stderr, "Usage: sbtoggle [-w] [-b] [-l] [-a] [-g] [-d]\n"
" -w: toggle Wi-Fi (on/off)\n"
" -b: toggle Bluetooth (on/off)\n"
" -l: toggle Location Services (on/off)\n"
" -a: toggle Airplane Mode (on/off)\n"
" -g: toggle 3G (on/off)\n"
" -d: toggle Data (on/off)\n"
);
}
int main(int argc, char **argv, char **envp) {
if(!argv[1]){
usage();
return 1;
}
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *identifier = [[[NSString alloc] initWithUTF8String:argv[1]] autorelease];
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:identifier forKey:@"options"];
CPDistributedMessagingCenter *messagingCenter = [CPDistributedMessagingCenter centerNamed:@"com.innoying.sbserver"];
NSDictionary *status = [messagingCenter sendMessageAndReceiveReplyName:@"sbtoggle" userInfo:userInfo];
int returnValue = [[status objectForKey:@"status"] intValue];
[pool release];
if(returnValue == -1){
fprintf(stderr, "There was an error. Please try again\n\n");
usage();
}
return returnValue;
}