iOS利用iTunesLookup检查更新

来源:互联网 发布:大数据建设开展情况 编辑:程序博客网 时间:2024/06/05 22:51

原文地址:http://ayjkdev.top/2016/04/06/update-in-app-with-itunes-lookup/


iTunesLookup

iTunesLookup其实是有Apple提供的查询应用信息的接口,我们可以利用它来进行App更新提示的功能实现。

介绍

AYCheckVersion

我封装了一个用于提示更新的工具类AYCheckVersion。经过我的测试可以正常进行功能实现,iOS8以下使用UIAlertView,以上就使用UIAlertViewController。只需要调用checkVersion方法就能进行查询,无需额外的设置。

两个按钮情况三个按钮情况

Tpis:

  • 通常情况下,只要调用- (void)checkVersion;就行了,如果还需要进行进一步的自定义,可以调用类库中提供的其他方法。
  • 有些情况下,由于app销售地区不同,可能无法从Apple服务器获取数据。这时,只要设置countryAbbreviation属性就行了,赋值为你销售地区的英文缩写。
  • 跳转AppStore有两种方式,一种为模态形式弹出AppStore,另一种常规跳转AppStore。通过openAPPStoreInsideAPP设置布尔值来选择。默认为No,常规跳转。

数据分析

下图是我公司的App这里当做一个示例,从服务器获取到的JSON数据如下:

{  "resultCount": 1,  "results": [    {      "screenshotUrls": [        "http://a5.mzstatic.com/us/r30/Purple7/v4/ee/78/33/ee7833bc-9a8a-6abe-99de-04d842e75b03/screen1136x1136.jpeg",        "http://a5.mzstatic.com/us/r30/Purple49/v4/20/74/78/20747895-29a2-0507-587b-57204a91aa5d/screen1136x1136.jpeg",        "http://a5.mzstatic.com/us/r30/Purple69/v4/f7/16/b7/f716b7f1-b67f-cd60-3017-1e59ee4b1e10/screen1136x1136.jpeg",        "http://a1.mzstatic.com/us/r30/Purple49/v4/b7/bd/cc/b7bdcc4e-3366-560a-3e7b-1c82e2d07faf/screen1136x1136.jpeg",        "http://a1.mzstatic.com/us/r30/Purple49/v4/f8/f9/4d/f8f94ddf-12f0-343d-52a3-f64790db1e5e/screen1136x1136.jpeg"      ],      "ipadScreenshotUrls": [],      "artworkUrl60": "http://is4.mzstatic.com/image/thumb/Purple69/v4/08/d1/60/08d16090-68af-6590-d820-13164a940057/source/60x60bb.jpg",      "artworkUrl512": "http://is4.mzstatic.com/image/thumb/Purple69/v4/08/d1/60/08d16090-68af-6590-d820-13164a940057/source/512x512bb.jpg",      "artworkUrl100": "http://is4.mzstatic.com/image/thumb/Purple69/v4/08/d1/60/08d16090-68af-6590-d820-13164a940057/source/100x100bb.jpg",      "artistViewUrl": "https://itunes.apple.com/cn/developer/hangzhou-yitou-outsource-financial/id1067515154?uo=4",      "kind": "software",      "supportedDevices": [        "iPad2Wifi",        "iPad23G",        "iPhone4S",        "iPadThirdGen",        "iPadThirdGen4G",        "iPhone5",        "iPodTouchFifthGen",        "iPadFourthGen",        "iPadFourthGen4G",        "iPadMini",        "iPadMini4G",        "iPhone5c",        "iPhone5s",        "iPhone6",        "iPhone6Plus",        "iPodTouchSixthGen"      ],      "features": [],      "advisories": [],      "isGameCenterEnabled": false,      "averageUserRatingForCurrentVersion": 5,      "trackCensoredName": "宜投金服",      "languageCodesISO2A": [        "EN",        "ZH"      ],      "fileSizeBytes": "19505964",      "sellerUrl": "http://www.yitoujf.com/",      "contentAdvisoryRating": "4+",      "userRatingCountForCurrentVersion": 1,      "trackViewUrl": "https://itunes.apple.com/cn/app/yi-tou-jin-fu/id1067515155?mt=8&uo=4",      "trackContentRating": "4+",      "minimumOsVersion": "8.0",      "currency": "CNY",      "wrapperType": "software",      "version": "1.4.0",      "artistId": 1067515154,      "artistName": "HangZhou YiTou Outsource Of Financial Services Co., Ltd.",      "genres": [        "财务"      ],      "price": 0,      "trackName": "宜投金服",      "trackId": 1067515155,      "description": "【产品特点】\n1.低门槛  高收益\n100元即可投资宜投理财产品,尊享9%+的年化收益率。满标后次日开始计息。投资期限短,投资灵活。让你的小投入也能收获大回报!\n2.操作便捷,快速理财\n使用掌上宜投,能够随时随进行查看、投资。独创的投资金额一键拖动模式,轻松玩转指尖理财。\n3.账单明细,一手“掌”握\n投资成功后,即可在个人中心查看“投资”、“收益”、“回款”、”提现”,所有资金明细一目了然,轻松理财、尽在“掌”握。\n4.GSP定位,保障到位\n宜投金服全国首创债权物GPS实时追踪系统。在投资期间,满足您24小时对债权物的实时监控。不论何时何地,都能清晰掌握债权物动向,真正做到放心理财、“坐”享其成。\n\n【安全保障】\n1.合作机构严格准入机制\n2.多重项目审核,严格控制风险\n3.第三方资金全托管,账户专款专用\n4.非银行金融机构100%本息保障\n5.风险准备金中信银行监管",      "bundleId": "com.yitoujf.YiTouJF",      "releaseDate": "2016-01-08T00:28:10Z",      "primaryGenreName": "Finance",      "formattedPrice": "免费",      "isVppDeviceBasedLicensingEnabled": true,      "currentVersionReleaseDate": "2016-03-29T23:09:29Z",      "releaseNotes": "本次更新:\n--调整操作逻辑,提升用户体验",      "sellerName": "HangZhou YiTou Outsource Of Financial Services Co., Ltd.",      "primaryGenreId": 6015,      "genreIds": [        "6015"      ]    }  ]}

这里我们需要用到的数据:

trackViewUrl:常规方式下跳转AppStore的链接。
version:最新的版本号。
trackId:应用内模态AppStore需要的应用id。
APPReleaseNotes:应用更新的内容。

方法实现

数据请求

刚开始的时候公司的App请求更新数据中,一直请求不到数据,返回的一直是

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

着实让我郁闷了很久,google了很久一直没找到正确的应对方法,最后在StackOverFlow上查到了答案。
iTunes api, lookup by bundle ID?
在请求的URL后边加上你想要查询的销售地就行了,比如我的App就设置了

checkManger.countryAbbreviation = @"cn";

AppStore的跳转方式

常规跳转

很简单,只要获取到trackViewUrl后,通过

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[userDefault objectForKey:APP_TRACK_VIEW_URL]]];

进行跳转就OK。

模态弹出

这里需要导入

#import <StoreKit/StoreKit.h>

然后进行初始化和赋值操作、设置代理

SKStoreProductViewController *storeViewController = [[SKStoreProductViewController alloc] init];storeViewController.delegate = self;NSDictionary *parametersDic = @{SKStoreProductParameterITunesItemIdentifier:[userDefault objectForKey:TRACK_ID]};[storeViewController loadProductWithParameters:parametersDic completionBlock:^(BOOL result, NSError * _Nullable error) {        if (result) {        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:storeViewController animated:YES completion:^{                    }];    }}];

实现代理方法

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {        [[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:YES completion:^{            }];}

关于审核

苹果方便其实是不会让你进行更新提示的,一方面这样会对UE有一点损失,另一方面,你当我AppStore不会提示更新是吗?苹果如是说。
所以这里,我进行了判断处理,比如你当前上架版本是1.0.0,你要上线1.0.1提交审核,在你应用还没上架之前,也就是开发和审核阶段,都不会弹出提示框进行提示。排除了这部分被拒的可能性。

源代码

GitHub链接:AYCheckVersion,看官大人来波star鼓励下吧。

0 0