1. Openurl
We know that we can set the URL scheme for the application so that other applications can open our application through this address. In fact, there is another API called canopenurl. If we know the URL scheme of the IOS Application List to be checked, we can use canopenurl to check it.
2. Get the running program list
//. H
@ Interface uidevice (processesadditions)
-(Nsarray *) runningprocesses;
@ End
//. M
# Import <sys/sysctl. h>
@ Implementation uidevice (processesadditions)
-(Nsarray *) runningprocesses {
Int MIB [4] = {ctl_kern, kern_proc, kern_proc_all, 0 };
Size_t miblen = 4;
Size_t size;
Int ST = sysctl (MIB, miblen, null, & size, null, 0 );
Struct kinfo_proc * process = NULL;
Struct kinfo_proc * newprocess = NULL;
Do {
Size + = size/10;
Newprocess = realloc (process, size );
If (! Newprocess ){
If (process ){
Free (process );
}
Return nil;
}
Process = newprocess;
St = sysctl (MIB, miblen, process, & size, null, 0 );
} While (ST =-1 & errno = enomem );
If (ST = 0 ){
If (size % sizeof (struct kinfo_proc) = 0 ){
Int nprocess = size/sizeof (struct kinfo_proc );
If (nprocess ){
Nsmutablearray * array = [[nsmutablearray alloc] init];
For (INT I = nprocess-1; I> = 0; I --){
Nsstring * processid = [[nsstring alloc] initwithformat: @ "% d", process [I]. kp_proc.p_pid];
Nsstring * processname = [[nsstring alloc] initwithformat: @ "% s", process [I]. kp_proc.p_comm];
Nsdictionary * dict = [[nsdictionary alloc] initwithobjects: [nsarray arraywithobjects: processid, processname, nil]
Forkeys: [nsarray arraywithobjects: @ "processid", @ "processname", nil];
[Processid release];
[Processname release];
[Array addobject: dict];
[Dict release];
}
Free (process );
Return [array autorelease];
}
}
}
Return nil;
}
@ End
// Example usage.
Nsarray * processes = [[uidevice currentdevice] runningprocesses];
For (nsdictionary * dict in processes ){
Nslog (@ "% @-% @", [dict objectforkey: @ "processid"], [dict objectforkey: @ "processname"]);
}
This method is used to obtain the list of running applications. If the application has not been run or is not in the background, the application will not be available.
Private APIs are a little more reliable than the above two methods.
Bool apcheckifappinstalled (nsstring * bundleidentifier ){
Static nsstring * const cachefilename = @ "com. Apple. Mobile. Installation. plist ";
Nsstring * relativecachepath = [[@ "library" stringbyappendingpathcomponent: @ "caches"] stringbyappendingpathcomponent: cachefilename];
Nsdictionary * cachedict = nil;
Nsstring * Path = nil;
Nslog (@ "relativecachepath: % @", relativecachepath );
// Loop through all possible paths the cache cocould be in
For (short I = 0; 1; I ++ ){
Switch (I ){
Case 0: // jailbroken apps will find the cache here; their home directory is/var/mobile
Path = [nshomedirectory () stringbyappendingpathcomponent: relativecachepath];
Break;
Case 1: // App Store apps and simulator will find the cache here; Home (/var/mobile/) is 2 directories above sandbox folder
Path = [[nshomedirectory () stringbyappendingpathcomponent: @ "..."] stringbyappendingpathcomponent: relativecachepath];
Break;
Case 2: // If the app is anywhere else, default to hardcoded/var/mobile/
Path = [@ "/var/mobile" stringbyappendingpathcomponent: relativecachepath];
Break;
Default: // cache not found (loop not broken)
Return no;
Break;
}
Bool isdir = no;
Nslog (@ "Path: % @", PATH );
// Ensure that file exists
If ([[nsfilemanager defaultmanager] fileexistsatpath: path isdirectory: & isdir] &! Isdir ){
Cachedict = [nsdictionary dictionarywithcontentsoffile: path];
}
// If cache is loaded, then break the loop. If the loop is not "broken," it will return no later (default: Case)
If (cachedict ){
Nslog (@ "cachedict: % @", cachedict );
Break;
}
}
Nslog (@ "GGGG ");
// First check all system (jailbroken) apps
Nsdictionary * system = [cachedict objectforkey: @ "system"];
Nslog (@ "system: % @", system );
If ([system objectforkey: bundleidentifier]) {
Return yes;
}
// Then all the user (App Store/var/mobile/applications) apps
Nsdictionary * user = [cachedict objectforkey: @ "user"];
Nslog (@ "User: % @", user );
If ([user objectforkey: bundleidentifier]) {
Return yes;
}
// If nothing returned Yes already, we'll return no now
Return no;
}
Code Method
There is another way to get the App list, the code in the https://github.com/danielamitay/iHasApp
It uses the Openurl function of the application to traverse a list of 5000 app IDs and try to open these apps one by one on your iPhone. This implementation will soon turn your iPhone into a treasure, it can only be a joke.
Original article: Click to open the link
However, this method requires that the machine has been jailbroken and your application is not included in the sandbox. Since the last article is not approved by the author, I did not try it :)