IOS 版本升级检查 API

通常在版本发布后,有时需要查询发布的版本是否比当前使用的版本要新。然后决定是否进行升级处理。


在IOS 中可以使用itunes 查询API来进行查询。

搜索API,允许您将您的网站在搜索领域内iTunes商店,应用程序商店,iBookstore的Mac App Store的搜索内容。您可以搜索各种内容,包括应用程序,电子书,电影,播客,音乐,音乐视频,有声读物,和电视节目。您也可以拨打基于ID的查询请求,以创建内容库和数字目录之间的映射。条款及细则约束。

API:http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html


查询应用程序信息支持模糊和精确查询。

模糊使用的是应该用程序名进行查找,精确的则使用itunes id (itunes connect id)


代码:

宏定义:


#ifdef USE_PRECISE

#define APP_URL @"http://itunes.apple.com/lookup?id=284910350"  //数字部份换成自己的应用的itunes id.

#else

//#define APP_URL @"http://itunes.apple.com/search?term=UMS&entity=software" //这里的UMS为产品的名称,可根据自己的情况来换。

#if



-(void)doCheckVersion:(NSString *)currentVersion  
{  
    NSString *URL = APP_URL;  //通过来进行决定是模糊还是精确
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];  
    [request setURL:[NSURL URLWithString:URL]];  
    [request setHTTPMethod:@"POST"];  
    NSHTTPURLResponse *urlResponse = nil;  
    NSError *error = nil;  
    NSData *recervedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];  
    
    NSString *results = [[NSString alloc] initWithBytes:[recervedData bytes] length:[recervedData length] encoding:NSUTF8StringEncoding];
    
   
    NSDictionary *dic = [results JSONValue];  
    NSArray *infoArray = [dic objectForKey:@"results"];  
    if ([infoArray count]) {  
        NSDictionary *releaseInfo = [infoArray objectAtIndex:0];  
        NSString *lastVersion = [releaseInfo objectForKey:@"version"];  
        
        if (![lastVersion isEqualToString:currentVersion]) {  
            trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];  
            UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"更新" message:@"有新的版本更新,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil] autorelease];  
            [alert show];  
        }  
    }  
    
}


模糊查询返回JSON(其实就是平时我们在app store 中查找到的应该用所显示的信息差不多)这只是其中一项(可能有N个这样的结构),我拿来举例子罢了:

{
            "kind": "software",
            "features": [ ],
            "supportedDevices": [
                "all"
            ],
            "isGameCenterEnabled": false,
            "artistViewUrl": "https://itunes.apple.com/us/artist/megalabs-cjsc/id526339435?uo=4",
            "artworkUrl60": "http://a31.phobos.apple.com/us/r1000/076/Purple2/v4/4c/cd/51/4ccd5177-0956-5059-fa4a-c520a0de361d/logo_megafon.png",
            "screenshotUrls": [
                "http://a1110.phobos.apple.com/us/r1000/119/Purple/v4/82/ce/2c/82ce2cd0-8efe-f315-3828-0e7ece59a4d7/mzl.adcgpvey.png",
                "http://a1756.phobos.apple.com/us/r1000/084/Purple/v4/0d/de/41/0dde416b-e13d-4d5b-9288-af796ff31a85/mzl.zyqwdwnm.png",
                "http://a1528.phobos.apple.com/us/r1000/065/Purple/v4/2a/72/14/2a721489-7891-edc2-4b42-8dd0f4dfb710/mzl.oilxjhme.png",
                "http://a1859.phobos.apple.com/us/r1000/099/Purple/v4/7c/33/c8/7c33c8a1-3fba-510d-e31c-45110b706db5/mzl.owhphqlj.png",
                "http://a1307.phobos.apple.com/us/r1000/063/Purple/v4/1f/1e/14/1f1e1410-a1ea-4472-793f-1a81f751faa9/mzl.zdpdpkpr.png"
            ],
            "ipadScreenshotUrls": [ ],
            "artworkUrl512": "http://a622.phobos.apple.com/us/r1000/075/Purple2/v4/b9/31/a2/b931a220-5a9a-1d89-3809-347705ace5f3/mzl.ytdjodqw.png",
            "artistId": 526339435,
            "artistName": "MegaLabs CJSC",
            "price": 0,
            "version": "1.0.1.3",
            "description": "«Unified Messaging» – это концепция, подразумевающая работу с любыми (SMS, MMS, а также различные виды IM/SNS) видами сообщений через мобильный клиент, с единой адресной книгой, унифицированными функциями передачи, приёма, хранения и обработки сообщений.",
            "currency": "USD",
            "genres": [
                "Social Networking"
            ],
            "genreIds": [
                "6005"
            ],
            "releaseDate": "2012-12-15T11:19:06Z",              
            "sellerName": "MegaLabs CJSC",                         
            "bundleId": "ru.megalabs.ums",
            "trackId": 580112518,
            "trackName": "UMS",
            "primaryGenreName": "Social Networking",
            "primaryGenreId": 6005,
            "releaseNotes": "-Решена проблема со входом в приложение;
-Решена проблема с отображением сообщений во вкладке MIX.",
            "formattedPrice": "Free",
            "wrapperType": "software",
            "trackCensoredName": "UMS",
            "trackViewUrl": "https://itunes.apple.com/us/app/ums/id580112518?mt=8&uo=4",
            "contentAdvisoryRating": "4+",
            "artworkUrl100": "http://a622.phobos.apple.com/us/r1000/075/Purple2/v4/b9/31/a2/b931a220-5a9a-1d89-3809-347705ace5f3/mzl.ytdjodqw.png",
            "languageCodesISO2A": [
                "EN",
                "RU"
            ],
            "fileSizeBytes": "16437704",
            "sellerUrl": "https://messages.megafon.ru",
            "trackContentRating": "4+",
            "averageUserRating": 5,
            "userRatingCount": 1
        }

精确查询返回的json

{
    "resultCount": 1, 
    "results": [
        {
            "kind": "software", 
            "features": [
                "iosUniversal"
            ], 
            "supportedDevices": [
                "all"
            ], 
            "isGameCenterEnabled": false, 
            "artistViewUrl": "https://itunes.apple.com/us/artist/yelp/id284910353?uo=4", 
            "artworkUrl60": "http://a1154.phobos.apple.com/us/r1000/093/Purple2/v4/df/d2/d1/dfd2d173-7901-1c41-fcc3-ea953e698961/57.png", 
            "screenshotUrls": [
                "http://a1283.phobos.apple.com/us/r1000/084/Purple/v4/d7/10/4e/d7104e7c-69b9-c30e-fb74-dc9ad4907e5d/mzl.qhnhnswp.png", 
                "http://a1583.phobos.apple.com/us/r1000/091/Purple/v4/f2/9e/1f/f29e1ff0-15ae-955b-9470-95e777e0d302/mzl.ehinvjli.png", 
                "http://a232.phobos.apple.com/us/r1000/080/Purple/v4/fa/be/87/fabe8765-de35-ae10-6eba-4b77dee9579c/mzl.ypncttex.png", 
                "http://a1190.phobos.apple.com/us/r1000/114/Purple2/v4/86/68/86/86688674-4540-b317-9e1f-fc2c8adede50/mzl.ekbdqwzg.png", 
                "http://a296.phobos.apple.com/us/r1000/115/Purple2/v4/b6/ca/e1/b6cae1d2-5754-d092-c2c3-09dce16a5b86/mzl.xroiibzd.png"
            ], 
            "ipadScreenshotUrls": [
                "http://a1855.phobos.apple.com/us/r1000/069/Purple2/v4/27/53/59/27535982-a8ab-752b-1352-14376dbd52fa/mzl.pzkmvqsc.1024x1024-65.jpg", 
                "http://a1384.phobos.apple.com/us/r1000/120/Purple/v4/d8/61/72/d86172b0-c012-b520-aaea-0fe405af8220/mzl.ayvdvsyz.1024x1024-65.jpg", 
                "http://a1714.phobos.apple.com/us/r1000/107/Purple/v4/d4/e6/54/d4e65417-151e-c358-cf46-67034eb1c809/mzl.cqcnsrnw.1024x1024-65.jpg", 
                "http://a668.phobos.apple.com/us/r1000/115/Purple2/v4/9f/0f/0c/9f0f0c76-86cf-5af0-7d62-e57d05cdb7d9/mzl.gdkkhahb.1024x1024-65.jpg", 
                "http://a886.phobos.apple.com/us/r1000/080/Purple2/v4/4e/2c/e8/4e2ce8be-f69d-2fd9-b79a-e9a689dd1ad6/mzl.vjffwbxj.1024x1024-65.jpg"
            ], 
            "artworkUrl512": "http://a1157.phobos.apple.com/us/r1000/108/Purple/v4/db/b7/fb/dbb7fb10-29a7-4771-e781-38fffee81c85/mzl.atjqxuth.png", 
            "artistId": 284910353, 
            "artistName": "Yelp", 
            "price": 0, 
            "version": "6.5.1", 
            "description": "Looking for a burrito joint open now?  An Irish pub nearby?  A gas station you can drive to before your tank hits empty?  Yelp for your iPhone or iPad is here to help.  Use us to search for places to eat, shop, drink, relax and play then read reviews from an active community of locals in the know.   

FEATURES:
★ Search for businesses near you 
★ Tap quick links to find nearby bars, restaurants, cafes and more
★ Narrow your searches by 'hood, distance, price, and what's open now
★ Browse reviews to read what's great (and not so great) in your city
★ Find great Deals offered by your favorite local businesses on iPhone
★ Add tips, photos, and draft reviews for your favorite businesses
★ Check-in and share on Facebook and Twitter
★ Make reservations on OpenTable without leaving the Yelp app
★ Look up addresses and phone numbers for thousands of businesses, then call or map them from your iPhone or iPad
★ Yelp does augmented reality with Monocle. Overlay business information onto the world around you.", 
            "currency": "USD", 
            "genres": [
                "Travel", 
                "Navigation"
            ], 
            "genreIds": [
                "6003", 
                "6010"
            ], 
            "releaseDate": "2008-07-11T07:00:00Z", 
            "sellerName": "Yelp, Inc.", 
            "bundleId": "com.yelp.yelpiphone", 
            "trackId": 284910350, 
            "trackName": "Yelp", 
            "primaryGenreName": "Travel", 
            "primaryGenreId": 6003, 
            "releaseNotes": "New in 6.5.1:
Just to show how much we love our Yelpers, we're knocking out two big feature requests with this release:
☆ Apparently 300 characters per Tip wasn't enough for you to fully express yourself. We dig that. This release gives you 200 more.
☆ From the \"More Reviews\" list on iPhone, pull down to expose a review search box. Now you can skip the other stuff and find out exactly what people think about the \"carne asada burrito\" at that new Mexican spot down the street.

New in 6.5:
☆ We gave our iPad business page a whole lot of love. It's now more streamline and clear, with more emphasis on business photos. In addition, we're now showing Yelp Deals and our new \"Explore the Menu\" feature.
☆ Yelp search just got more social: Now you can see which friends are checked in to businesses directly from your search results.
☆ Getting to a restaurant just after closing is a major bummer. Now we'll indicate if a business will be closing soon or is just about to open.
☆ We also got in a TON of bug fixes and enhancements: showing your review first in the reviews list, supporting updated reviews on iPad, swipe-able photos on the business page, and huge speed improvements on iPhone5!", 
            "formattedPrice": "Free", 
            "wrapperType": "software", 
            "trackCensoredName": "Yelp", 
            "trackViewUrl": "https://itunes.apple.com/us/app/yelp/id284910350?mt=8&uo=4", 
            "contentAdvisoryRating": "12+", 
            "artworkUrl100": "http://a1157.phobos.apple.com/us/r1000/108/Purple/v4/db/b7/fb/dbb7fb10-29a7-4771-e781-38fffee81c85/mzl.atjqxuth.png", 
            "languageCodesISO2A": [
                "SV", 
                "TR", 
                "NB", 
                "DA", 
                "DE", 
                "EN", 
                "ES", 
                "FI", 
                "FR", 
                "IT", 
                "NL", 
                "PL"
            ], 
            "fileSizeBytes": "18176675", 
            "averageUserRatingForCurrentVersion": 4.5, 
            "userRatingCountForCurrentVersion": 1356, 
            "trackContentRating": "12+", 
            "averageUserRating": 3.5, 
            "userRatingCount": 171885
        }
    ]
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

边缘998

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值