How to tell if an app is installed on your iOS device

Source: Internet
Author: User

The main idea is to info.plist in the Xcode of application B to be recognized

If it is Xcode 4.2, then

1. Add a URL to Info.plist schemes:xxx

The specific details to add are:

1.1 Open Info.plist, add an entry under the Information property list: URL types

1.2 then add an item 0 below the URL Types, which is a dictionary

1.3 Add a URL schemes type Array below ITEM0

1.4 then add a URL identifier below the URL schemes, and the string value can be blank

Add a Item0 below the Item0, and the string value is XXX.

Start to see on the internet said add URL schemes, thought to add directly to the Information property List under an item, key is URL schemes, the value of XXX is OK, later found not working. This can only add the specified type, will automatically prompt the relevant type, the correct method is the above procedure.

In the case of Xcode 4.6, add the following method:

Solution:

Starting from 91sdk3.2.5 requires the provider to set a URL scheme, set the method as follows: Select Target in the project, select the Info tab, locate the URL below Types, expand, click the plus sign to create a new URL scheme.



After clicking on the identifier field fill in your software identifier, the URL schemes field is populated in the format: 91-xxxxx, where xxxx is your software identifier. The role field can be set to None,icon field can not be filled. Examples are as follows:


2. Then in application A of the active device, this method is used to determine if the application B is present in the phone.
[[UIApplication sharedapplication] canopenurl:[nsurl urlwithstring:@ "xxx://"];
If you return yes, the app is installed on your phone and not installed.

The specific code is as follows:

-(BOOL) APCheckIfAppInstalled2: (NSString *) Urlschemes

{

if ([[[UIApplication sharedapplication] Canopenurl:[nsurl Urlwithstring:urlschemes])

{

NSLog (@"Installed");   return YES;

} Else

{

return NO;

}

}

Call Apcheckifappinstalled2:xxx to determine if Application B is installed.

This method takes effect regardless of whether the jailbroken iOS device or the device is not jailbroken.

There is another way to view com.apple.mobile.installation.plist system files, through the bundle identifier to judge, but can only judge the jailbreak machine, because the jailbreak machine can access to this file, in the non-jailbroken machine, Because the application is not allowed to access directories other than the sandbox environment, the file cannot be read or even the existence of the file will fail.

The code is as follows:

-(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;

Loop through all possible paths the cache could is in

For (shorti = 0; 1; i++)

{

switch (i) {  

Case 0: //Jailbroken apps would find the cache here; their home directory Is/var/mobile

Path = [Nshomedirectory () Stringbyappendingpathcomponent:relativecachepath];

Break

Case 1: //App Store apps and Simulator'll find the cache here, Home (/var/mobile/) is 2 directories above sandbox F Older

Path = [[Nshomedirectory () stringByAppendingPathComponent: @". /.."]  Stringbyappendingpathcomponent:relativecachepath];

Break

Case 2: //If the app was 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;

if ([[Nsfilemanager Defaultmanager] fileexistsatpath:path isdirectory: &isdir]) //Ensure that file exists

{

if (Isdir = = YES)

{

NSLog (@"Dir");

}

Else

{

Cachedict = [Nsdictionary Dictionarywithcontentsoffile:path];

}

}

if (cachedict) //If cache is loaded and then break the loop. If the loop is not "broken," it'll return NO later (default:case)

Break

}

Nsdictionary *system = [cachedict objectforkey: @"System"]; //First Check all system (jailbroken) Apps

if ([System Objectforkey:bundleidentifier])

return YES;

Nsdictionary *user = [cachedict objectforkey: @"user"]; //Then all the user (App store/var/mobile/applications) apps

if ([user Objectforkey:bundleidentifier])

return YES;

If Nothing returned YES already, we'll return NO now

return NO;

}

How to tell if an app is installed on your iOS device

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.