How to determine whether an app is installed on an ios device

Source: Internet
Author: User

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

For Xcode 4.2

1. Add a URL Schemes: XXX to info. plist.

The details are as follows:

1.1 open info. plist and add one under the Information Property List: URL types

1.2 then add an Item 0 under URL Types, which is a Dictionary

1.3 add an Array of the URL Schemes type under Item0

1.4 then add a URL identifier under the URL Schemes. The String value can be left blank.

Add Item0 under Item0, and the String value is XXX.


I started to see Adding URL Schemes on the Internet. I thought it would be an item directly added to the Information Property List. The key is URL Schemes and the value is XXX. Later I found that it does not work. Only the specified type can be added, and the related type is automatically displayed. The correct method is the above process.


If it is Xcode 4.6, add the following method:

Solution:

From 91SDK3. 2.5, the access party must set a URL Scheme. The setting method is as follows: select the Target in the project, select the Info tab, and find the URL below.
Types, expand, and click the plus sign to create a new URL Scheme.

 

After clicking, enter your software Identifier in the Identifier Field, and enter the URL Schemes field in the format of 91-xxxxx, where xxxx is your software Identifier. The Role field can be set to None, and the Icon field can be left empty. Example:


 




2. Then, in app a of the active device, use this method to determine whether app B exists in the mobile phone.
[[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString: @ "XXX: //"];
If YES is returned, the application has been installed on the mobile phone, and vice versa.


The 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 check whether application B is installed.


This method takes effect for jailbroken iOS devices or devices that have not been jailbroken.


You can also view

Com. apple. mobile. installation. the plist system file method can be determined by bundle identifier, but only the jailbreaking machine can be identified, because the jailbreaking machine can access this file, in a non-jailbreaking machine, because applications are not allowed to access directories outside the sandbox environment, they cannot read the file or even judge whether the file exists.

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 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;        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, then break the loop. If the loop is not "broken," it will 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;}

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.