1. 程式人生 > >根據bundle ID獲取App Store的APP資訊(可用來檢測新版本,可以不考慮APP ID了)

根據bundle ID獲取App Store的APP資訊(可用來檢測新版本,可以不考慮APP ID了)

首先,自問自答:

問:為什麼不使用APP ID呢?

答:APP ID沒有儲存在 -info.plist 檔案,不方便嘛。Bundle ID 儲存在 -info.plist檔案。

我要做通用性的功能,所以,查詢時,以Bundle ID做搜尋條件。

下面,搜尋APP資訊:

(1 ) 這是很重要的:

(千萬要注意:下面的bundleId必須寫成bundleId,不能寫成 bundleid或者bundleID)

https://itunes.apple.com/lookup?bundleId=你APP的Bundle ID

(你也可以用http,不用https, 但是貌似最近http經常獲取不到)

(2) 如果找到了,返回json格式的資料:

比如:

{
 "resultCount":1,
 "results": [
{"kind":"software", "features":[], 
"supportedDevices":["iPhone5s", "iPhone4", "iPadFourthGen", "iPadWifi", "iPadFourthGen4G", "iPodTouchourthGen", "iPad2Wifi", "iPhone4S", "iPadMini4G", "iPhone-3GS", "iPhone5", "iPodTouchFifthGen", "iPhone5c", "iPad3G", "iPadThirdGen4G", "iPadMini", "iPodTouchThirdGen", "iPadThirdGen", "iPad23G"], "isGameCenterEnabled":false, "screenshotUrls":["http://a2.mzstatic.com/us/r30/Purple6/v4/65/d9/f4/65d9f4c8-83aa-aedc-7d33-17bfcd95f329/screen1136x1136.jpeg"], "ipadScreenshotUrls":[], "artworkUrl60":"http://a637.phobos.apple.com/us/r30/Purple/v4/f9/c6/d2/f9c6d227-bab9-3008-88b6-ea74e48510a7/57.png", "artworkUrl512":"http://a157.phobos.apple.com/us/r30/Purple4/v4/c7/77/dd/c777dd5f-a1c2-e0fa-6a6f-1c4e3db98c12/mzl.tqbteywq.png", "artistViewUrl":"https://itunes.apple.com/us/artist/shenzhen-reecam-tech.-ltd./id479468962?uo=4", "artistId":479468962, "artistName":"Shenzhen Reecam Tech. Ltd.", "price":0.00, "version":"1.1.9", 
"description":"1, play video and audio via IP Camera \n2, it can directly access camera in LAN or internet \n3, get a snapshot from video and save it into the album \n4, search cameras in LAN \n5, it can control a camera via WIFI \n6, play video in full-screen \n7, reconnect to camera automaticly \n8, smart connection", "currency":"USD", "genres":["Business", "Photo & Video"], "genreIds":["6000", "6008"], "releaseDate":"2014-01-28T19:57:38Z", "sellerName":"Shen Zhen Rui Cai TECH.LTD", "bundleId":"net.reecam.uccamPush", "trackId":805363884, "trackName":"UCCAM.", "primaryGenreName":"Business", "primaryGenreId":6000, "releaseNotes":"(1) new notice interface\n(2) get alarm pictures when click  the \"OK\" button on notice interface", "formattedPrice":"Free", "wrapperType":"software", "trackCensoredName":"UCCAM.", "languageCodesISO2A":["EN", "ZH"], "fileSizeBytes":"16497902", "sellerUrl":"http://www.reecam.net", "contentAdvisoryRating":"4+", "artworkUrl100":"http://a157.phobos.apple.com/us/r30/Purple4/v4/c7/77/dd/c777dd5f-a1c2-e0fa-6a6f-1c4e3db98c12/mzl.tqbteywq.png", "trackViewUrl":"https://itunes.apple.com/us/app/uccam./id805363884?mt=8&uo=4", "trackContentRating":"4+"}]
}

版本號:找到那個"version",它的值就是版本號

URL:找到那個“trackViewUrl", 它的值就是介紹這個APP的連結網址

你可以對比本地APP的版本號和APP Store上釋出的版本號,如果有新版本,可以提示使用者要更新...

(3)如果沒找到:

{
 "resultCount":0,
 "results": []
}

(4)這裡順便告訴大家用 JSONKit 取出版本號,

//注意:這裡是示例,用阻塞操作,不考慮異常情況

//下面讀取的是本地APP的Bundle ID:

NSString* bundleID = [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString*) kCFBundleIdentifierKey];

NSString* strURL = [ NSString stringWithFormat:@"https://itunes.apple.com/lookup?bundleId=%@",bundleID ];

NSData* data = [ NSData dataWithContentsOfURL:[ NSURL URLWithString: strURL ]];

NSDictionary* dic = [data objectFromJSONData ];

NSArray* resultArray = [ dic objectForKey:@"results"];

NSDictionary* subDict = [resultArray objectAtIndex: 0 ];
NSString* strVersion = [subDict objectForKey: @"version"];

這個strVersion就是版本號啦