Skip to content

Commit

Permalink
Add --json support for list_bundle_id (ios-control#457)
Browse files Browse the repository at this point in the history
* add --json support for list_bundle_id

* only get result's keys when --json is not set

Co-authored-by: ryan.luo <[email protected]>
Co-authored-by: Gabe Giosia <[email protected]>
  • Loading branch information
3 people authored Apr 5, 2020
1 parent 575cd60 commit 72cbd8d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/ios-deploy/ios-deploy.m
Original file line number Diff line number Diff line change
Expand Up @@ -1580,18 +1580,28 @@ void list_bundle_id(AMDeviceRef device)
check_error(AMDeviceValidatePairing(device));
check_error(AMDeviceStartSession(device));

NSArray *a = [NSArray arrayWithObjects:@"CFBundleIdentifier", nil];
NSArray *a = [NSArray arrayWithObjects:
@"CFBundleIdentifier",
@"CFBundleName",
@"CFBundleDisplayName",
@"CFBundleVersion",
@"CFBundleShortVersionString", nil];
NSDictionary *optionsDict = [NSDictionary dictionaryWithObject:a forKey:@"ReturnAttributes"];
CFDictionaryRef options = (CFDictionaryRef)optionsDict;
CFDictionaryRef result = nil;
check_error(AMDeviceLookupApplications(device, options, &result));

CFIndex count;
count = CFDictionaryGetCount(result);
const void *keys[count];
CFDictionaryGetKeysAndValues(result, keys, NULL);
for(int i = 0; i < count; ++i) {
NSLogOut(@"%@", (CFStringRef)keys[i]);
if (_json_output) {
NSLogJSON(@{@"Event": @"ListBundleId",
@"Apps": (NSDictionary *)result});
} else {
CFIndex count;
count = CFDictionaryGetCount(result);
const void *keys[count];
CFDictionaryGetKeysAndValues(result, keys, NULL);
for(int i = 0; i < count; ++i) {
NSLogOut(@"%@", (CFStringRef)keys[i]);
}
}

check_error(AMDeviceStopSession(device));
Expand Down

0 comments on commit 72cbd8d

Please sign in to comment.