相關Bug已經解決,如有問題請在下方評論,謝謝。
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鼓勵下吧。