Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added options --list_bundle_id #136

Merged
merged 3 commits into from
May 17, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions ios-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,7 @@ int app_exists(AMDeviceRef device)
CFDictionaryRef result = nil;
check_error(AMDeviceLookupApplications(device, options, &result));

CFDictionaryRef app_dict = CFDictionaryGetValue(result, cf_bundle_id);
bool appExists = (app_dict == NULL) ? false : true;
bool appExists = CFDictionaryContainsKey(result, cf_bundle_id);
printf("%s", appExists ? "true\n" : "false\n");
CFRelease(cf_bundle_id);

Expand All @@ -1319,6 +1318,33 @@ int app_exists(AMDeviceRef device)
return -1;
}

void list_bundle_id(AMDeviceRef device)
{
AMDeviceConnect(device);
assert(AMDeviceIsPaired(device));
check_error(AMDeviceValidatePairing(device));
check_error(AMDeviceStartSession(device));

NSArray *a = [NSArray arrayWithObjects:@"CFBundleIdentifier", 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) {
CFStringRef test = (CFStringRef)keys[i];
const char * key = CFStringGetCStringPtr((CFStringRef)keys[i], kCFStringEncodingASCII);
printf("%s\n", key);
}

check_error(AMDeviceStopSession(device));
check_error(AMDeviceDisconnect(device));
}

void copy_file_callback(afc_connection* afc_conn_p, const char *name,int file)
{
const char *local_name=name;
Expand Down Expand Up @@ -1570,6 +1596,8 @@ void handle_device(AMDeviceRef device) {
exit(app_exists(device));
} else if (strcmp("uninstall_only", command) == 0) {
uninstall_app(device);
} else if (strcmp("list_bundle_id", command) == 0) {
list_bundle_id(device);
}
exit(0);
}
Expand Down Expand Up @@ -1752,7 +1780,8 @@ void usage(const char* app) {
" -D, --mkdir <dir> make directory on device\n"
" -R, --rm <path> remove file or directory on device (directories must be empty)\n"
" -V, --version print the executable version \n"
" -e, --exists check if the app with given bundle_id is installed or not \n",
" -e, --exists check if the app with given bundle_id is installed or not \n"
" -B, --list_bundle_id list bundle_id \n",
app);
}

Expand Down Expand Up @@ -1786,11 +1815,12 @@ int main(int argc, char *argv[]) {
{ "mkdir", required_argument, NULL, 'D'},
{ "rm", required_argument, NULL, 'R'},
{ "exists", no_argument, NULL, 'e'},
{ "list_bundle_id", no_argument, NULL, 'B'},
{ NULL, 0, NULL, 0 },
};
char ch;

while ((ch = getopt_long(argc, argv, "VmcdvunrILeD:R:i:b:a:t:g:x:p:1:2:o:l::w::9::", longopts, NULL)) != -1)
while ((ch = getopt_long(argc, argv, "VmcdvunrILeD:R:i:b:a:t:g:x:p:1:2:o:l::w::9::B::", longopts, NULL)) != -1)
{
switch (ch) {
case 'm':
Expand Down Expand Up @@ -1880,6 +1910,10 @@ int main(int argc, char *argv[]) {
command_only = true;
command = "exists";
break;
case 'B':
command_only = true;
command = "list_bundle_id";
break;
default:
usage(argv[0]);
return exitcode_error;
Expand Down