日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

如何判断ios设备中是否安装了某款应用

發布時間:2025/4/14 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何判断ios设备中是否安装了某款应用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如果是Xcode 4.6 ,那么按照下面的方法添加:

解決方案:

從91SDK3.2.5開始要求接入方需要設置一個URL Scheme,設置方法如下:選中工程中的Target,選中Info標簽頁,找到底下的URL Types,展開,點擊加號,創建一個新的URL Scheme。

171300xkniiaxbbnwq9yzy.png.thumb.jpg

點擊后,Identifier字段填入你的軟件標識符,URL Schemes字段填入格式為:91-xxxxx,其中xxxx為你的軟件標識符。Role字段可以設置為None,Icon字段可以不填。示例如下:

1713376wx166ne1r66aqw6.png

2. 然后 在主動設備的應用程序A中,通過? 這個方法判斷手機中是否存在這個應用B

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString"XXX://"]];

復制代碼

如果返回YES則表示此應用在手機中安裝過,反之則沒有安裝過.

具體代碼如下:

-(BOOL) APCheckIfAppInstalled2:(NSString *)urlSchemes

{

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlSchemes]])

{

NSLog(@" installed");

return YES;

}

else

{

return NO;

}

}

調用? APCheckIfAppInstalled2:XXX? 就可以判斷 是否安裝了應用程序B 了。

這個方法不管對越獄過的iOS設備還是沒有越獄過的設備都生效。

還有另外一個 查看

com.apple.mobile.installation.plist? 系統文件的方法,通過 bundle identifier 來判斷,但是只能判斷越獄機,因為越獄機才能訪問到這個文件,在非越獄的機器中,因為不允許應用程序訪問沙盒環境以外的目錄,所以不能讀取這個文件,甚至判斷這個文件是否存在都會失敗。

代碼如下:

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

}

轉載于:https://www.cnblogs.com/CJH5209/p/6027444.html

總結

以上是生活随笔為你收集整理的如何判断ios设备中是否安装了某款应用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。