檢查iphone是否安裝某app 【轉】

來源:互聯網
上載者:User

標籤:

轉自http://blog.csdn.net/zengconggen/article/details/7714514#

開發中遇到一個問題:公司多個產品時,希望在一個產品A中可以直接開啟另外的某個產品B。如果使用者尚未安裝產品B, 則開啟app store下載頁面。 對於這個問題:有3個技術點: 1、產品B是否已安裝的檢測。 2、應用內開啟其他app的技術:參考:https://developer.apple.com/library/IOs/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW18

3、從應用跳轉至app下載頁面的技術:參考:http://blog.csdn.net/zengconggen/article/details/6789420 對於第2、3點,本文略過不講。現提供第1技術點方案:(說明:技術有風險,有可能導致app被拒。不過app store有類似上線作品。看RP)解決方案1:(經驗證:該方案真機ios5無效,模擬器可以)// Declaration BOOL APCheckIfAppInstalled(NSString *bundleIdentifier); // Bundle identifier (eg. com.apple.mobilesafari) used to track apps // Implementation 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] && !isDir) // Ensure that file exists 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; } 解決方案2:參考:http://blog.csdn.net/zengconggen/article/details/7714466本方案有限制:只能擷取到使用者最近運行過的app。對於已安裝但是不在最近有啟動並執行app。不適用。BOOL isExsit = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"rumtel://com.rumtel.AudioManager"]]; NSLog(@"App %@ installed", identifier); if (isExsit) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"rumtel://com.rumtel.AudioManager?a=1&b=2#sect"]]; } else { //開啟app store下載頁面 } 方案3需要知道B的開啟地址。可用。最終方案確定為3附:目前公開的app相關資料:http://wiki.akosma.com/IPhone_URL_Schemes

 

檢查iphone是否安裝某app 【轉】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.