如何判断ios设备中是否安装了某款应用
如果是Xcode 4.6 ,那么按照下面的方法添加:
解決方案:
從91SDK3.2.5開始要求接入方需要設(shè)置一個URL Scheme,設(shè)置方法如下:選中工程中的Target,選中Info標(biāo)簽頁,找到底下的URL Types,展開,點擊加號,創(chuàng)建一個新的URL Scheme。
171300xkniiaxbbnwq9yzy.png.thumb.jpg
點擊后,Identifier字段填入你的軟件標(biāo)識符,URL Schemes字段填入格式為:91-xxxxx,其中xxxx為你的軟件標(biāo)識符。Role字段可以設(shè)置為None,Icon字段可以不填。示例如下:
1713376wx166ne1r66aqw6.png
2. 然后 在主動設(shè)備的應(yīng)用程序A中,通過? 這個方法判斷手機中是否存在這個應(yīng)用B
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString"XXX://"]];
復(fù)制代碼
如果返回YES則表示此應(yīng)用在手機中安裝過,反之則沒有安裝過.
具體代碼如下:
-(BOOL) APCheckIfAppInstalled2:(NSString *)urlSchemes
{
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlSchemes]])
{
NSLog(@" installed");
return YES;
}
else
{
return NO;
}
}
調(diào)用? APCheckIfAppInstalled2:XXX? 就可以判斷 是否安裝了應(yīng)用程序B 了。
這個方法不管對越獄過的iOS設(shè)備還是沒有越獄過的設(shè)備都生效。
還有另外一個 查看
com.apple.mobile.installation.plist? 系統(tǒng)文件的方法,通過 bundle identifier 來判斷,但是只能判斷越獄機,因為越獄機才能訪問到這個文件,在非越獄的機器中,因為不允許應(yīng)用程序訪問沙盒環(huán)境以外的目錄,所以不能讀取這個文件,甚至判斷這個文件是否存在都會失敗。
代碼如下:
-(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;
}
轉(zhuǎn)載于:https://www.cnblogs.com/CJH5209/p/6027444.html
總結(jié)
以上是生活随笔為你收集整理的如何判断ios设备中是否安装了某款应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ubuntu cocos2d-x 3.1
- 下一篇: nginx反向代理取得IP地址