IOS 版本升级提示

传入APPID 到此 https://itunes.apple.com/lookup?id=794869798 苹果会返回关于APP的json数据,如下所示

{
    "resultCount": 1,
    "results": [
        {
            "screenshotUrls": [
                "http://a1.mzstatic.com/us/r30/Purple4/v4/3b/fb/bf/3bfbbf5c-fdf2-164b-e8b8-8bd0416a2a17/screen1136x1136.jpeg",
                "http://a2.mzstatic.com/us/r30/Purple4/v4/9a/58/4a/9a584ad5-606b-999f-9c9a-ddec208a9250/screen1136x1136.jpeg",
                "http://a5.mzstatic.com/us/r30/Purple3/v4/6b/58/46/6b5846a3-451c-54af-1a56-af839893f81b/screen1136x1136.jpeg",
                "http://a5.mzstatic.com/us/r30/Purple4/v4/a1/13/c5/a113c576-782f-ade2-15cc-584a31075573/screen1136x1136.jpeg",
                "http://a3.mzstatic.com/us/r30/Purple3/v4/94/27/31/9427313b-e5f4-8a90-adcd-0e49f2775162/screen1136x1136.jpeg"
            ],
            "ipadScreenshotUrls": [],
            "artworkUrl512": "http://is3.mzstatic.com/image/thumb/Purple4/v4/f5/3c/d3/f53cd3ac-4df1-8dea-aecc-d1a6d97c175d/mzl.yolxgjjz.png/0x0ss-85.jpg",
            "artistViewUrl": "https://itunes.apple.com/us/developer/sha-men-hong-xiang-shu-xin/id1055104603?uo=4",
            "artworkUrl60": "http://is2.mzstatic.com/image/thumb/Purple4/v4/85/31/57/853157c3-2677-b915-2c1e-9bdbaefe2c24/Icon.png/0x0ss-85.jpg",
            "isGameCenterEnabled": false,
            "kind": "software",
            "features": [],
            "supportedDevices": [
                "iPhone-3GS",
                "iPhone4",
                "iPodTouchFourthGen",
                "iPad2Wifi",
                "iPad23G",
                "iPhone4S",
                "iPadThirdGen",
                "iPadThirdGen4G",
                "iPhone5",
                "iPodTouchFifthGen",
                "iPadFourthGen",
                "iPadFourthGen4G",
                "iPadMini",
                "iPadMini4G",
                "iPhone5c",
                "iPhone5s",
                "iPhone6",
                "iPhone6Plus",
                "iPodTouchSixthGen"
            ],
            "advisories": [],
            "languageCodesISO2A": [
                "EN"
            ],
            "fileSizeBytes": "17783486",
            "trackContentRating": "4+",
            "trackCensoredName": "康桥红橡树",
            "trackViewUrl": "https://itunes.apple.com/us/app/kang-qiao-hong-xiang-shu/id794869798?mt=8&uo=4",
            "contentAdvisoryRating": "4+",
            "artworkUrl100": "http://is3.mzstatic.com/image/thumb/Purple4/v4/f5/3c/d3/f53cd3ac-4df1-8dea-aecc-d1a6d97c175d/mzl.yolxgjjz.png/0x0ss-85.jpg",
            "currency": "USD",
            "wrapperType": "software",
            "version": "1.5",
            "artistId": 1055104603,
            "artistName": "厦门红橡树信息咨询服务有限公司",
            "genres": [
                "Education",
                "Business"
            ],
            "price": 0,
            "description": "应用系由厦门红橡树信息咨询服务有限公司为旗下康桥红橡树幼儿园投资开发的家园互动平台。无须设置,家长即可以看到孩子在园生活学习状况,并实现与教职人员的即时互动,及时了解园所的最新动态。平台完全量身定作,由后台针对对应账户提供孩子信息,用户只需登录个人账户即可。",
            "genreIds": [
                "6017",
                "6000"
            ],
            "releaseDate": "2014-01-16T03:57:50Z",
            "sellerName": "Xiamen Red Oak Information Consulting Service Co., Ltd.",
            "bundleId": "com.kangyou.kindergarten",
            "releaseNotes": "新增首页让版块更加丰富多彩,宝宝评语版块随时随地查看宝宝最新动态情况,修复部分小错误,提升整体稳定性。",
            "trackId": 794869798,
            "trackName": "康桥红橡树",
            "primaryGenreName": "Education",
            "primaryGenreId": 6017,
            "isVppDeviceBasedLicensingEnabled": true,
            "minimumOsVersion": "6.0",
            "formattedPrice": "Free"
        }
    ]
}

做了一个iOS下的App,普通情况下,AppStore会提示更新的,但是用户如果没开推送,或者不打开AppStore,是不知道有新版本的,所以要做版本更新提醒,当AppStore上有新的版本时,提示用户进行更新。如何关键是如何获得AppStore上的版本信息,可以通过苹果提供的REST接口进行查询。REST接口如下

http://itunes.apple.com/lookup?id=appid;

用自己的appid替换id的内容,就可以得到一个json的内容,内容很明了,一看就知道了,其中有一个版本信息,还有相应的更新信息,app地址等等。

顺便说一下如何获得本产品的版本信息。

NSString* thisVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString*)kCFBundleVersionKey];

可以参照下面的代码

https://github.com/jacobsologub/appdate

跳转到AppStore产品页,直接得到json中的trackViewUrl,通过下面的方式跳转过去。

        NSURL * url = [NSURL URLWithString:itunesURL];//itunesURL = trackViewUrl的内容

        [[UIApplication sharedApplication] openURL:url];


/////////////////////////////////////////////////////

-(void)checkVersion

{

    NSURL *url = [NSURL URLWithString:MY_APP_URL];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    [request setHTTPMethod:@"GET"];

    [request setTimeoutInterval:10.0];

    

    NSOperationQueue *queue = [[NSOperationQueue alloc]init];

    [NSURLConnection sendAsynchronousRequest:request

                                       queue:queue

                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

                               if (connectionError) {

                               }

                               else {

                                   NSError* jasonErr = nil;

                                   

                                   // jason 解析

                                   NSDictionary* responseDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&jasonErr];

                                   if (responseDict && [responseDict objectForKey:@"results"]) {

                                       NSDictionary* results = [[responseDict objectForKey:@"results"] objectAtIndex:0];;

                                       if (results) {

                                           CGFloat  fVeFromNet = [[results objectForKey:@"version"] floatValue];

                                           strVerUrl = [results objectForKey:@"trackViewUrl"];

                                           

                                           if (0 < fVeFromNet && strVerUrl) {

                                               CGFloat fCurVer = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] floatValue];

                                               if (fCurVer < fVeFromNet) {

                                                   dispatch_async(dispatch_get_main_queue(), ^{

                                                       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本更新"

                                                                                                       message:@"发现一个新版本,立即去更新吧!"

                                                                                                      delegate:self

                                                                                             cancelButtonTitle:@"不了,谢谢"

                                                                                             otherButtonTitles:@"立即更新", nil];

                                                       [alert show];

                                                   });

                                               }

                                           }

                                       }

                                   }

                               }

    }];

}

#define MY_APP_URL              @"http://itunes.apple.com/lookup?id=794869798"


转自:http://blog.sina.com.cn/s/blog_9564cb6e0101w7wy.html

你可能感兴趣的:(IOS 版本升级提示)