一.需求
公司之前一直在用企業證書開發和發布,App一直掛在官網上進行下載安裝,但是由于越到開發后期版本越多,維護版本統一越困難。所以又申請了一個公司發布到AppStore的版本。所以又把以前老的的流程梳理整理一下。開發中我們可能會遇到這樣的需求,當AppStore中有新版本迭代更新,在用戶點開APP的時候彈框提醒客戶去AppStore更新APP。這里有兩點要做的事情:
1.獲取AppStore的版本和本地的版本做對比
2.如果本地版本比較低的話 提示用戶是否到AppStore下載更新。
3.不能顯示的在app中提示,否則上傳會被拒,可以放在App啟動的時候彈出提示框
二、實現
1.通過網絡請求獲取AppStore中的版本和本地版本做對比:以QQ為例
返回Json:
{
resultCount = 1;
results = (
{
primaryGenreName = Social Networking;
// App Store上的app版本
version = 6.3.16;
formattedPrice = Free;
genreIds = (
6005,
6007,
);
artworkUrl60 = http://is5.mzstatic.com/image/thumb/Purple49/v4/23/31/14/233114f8-2e8d-7b63-8dc5-85d29893061e/source/60x60bb.jpg;
userRatingCountForCurrentVersion = 282;
minimumOsVersion = 7.0;
appletvScreenshotUrls = (
);
sellerName = Tencent Technology (Shenzhen) Company Limited;
supportedDevices = (iPhone4,iPad2Wifi,iPad23G,iPhone4S,iPadThirdGen,iPadThirdGen4G,iPhone5,iPodTouchFifthGen,iPadFourthGen,iPadFourthGen4G,iPadMini,iPadMini4G,iPhone5c,iPhone5s,iPhone6,iPhone6Plus,iPodTouchSixthGen,)
genres = (
Social Networking,
Productivity,
);
currentVersionReleaseDate = 2016-04-20T06:58:12Z;
trackName = WeChat;
isVppDeviceBasedLicensingEnabled = 1;
description = Over half a billion people use WeChat, the free messaging & calling app that allows you to easily connect with family & friends across countries. It’s the all-in-one communications app for free text (SMS/MMS), voice & video calls, moments, photo sharing, and games.
WHY USE WECHAT:
? ALWAYS FREE: No annual subscription fee. Absolutely free for life.
? FREE VOICE & VIDEO CALLS: High-quality free calls to anywhere in the world.
? GROUP CHAT: Create group chats with up to 500 people.
? MULTIMEDIA MESSAGING: Send video, image, text, and voice messages.
? STICKER GALLERY: Hundreds of free fun, animated stickers to express your feelings from some of your favorite cartoons and movies.
? MOMENTS: Share your best moments on your personal photo stream.
? BETTER PRIVACY: WeChat gives you the highest level of control over your privacy. It’s the only messaging app to be certified by TRUSTe.
? MEET NEW FRIENDS: Use “Friend Radar”, “People Nearby” and “Shake” to meet others.
? ADDICTIVE GAMES: Compete with your friends on some of the hottest games.
? REALTIME LOCATION: Instead of having to tell others where you are, just use real-time location sharing.
? LANGUAGE SUPPORT: Localized in 20 different languages and can translate messages to any language
? AND MORE: Desktop app, custom wallpaper, custom notifications, group walkie-talkie, official accounts.
? WeRun-WeChat: Aceess HealthKit data and challenge friends tobeat their scores via the "WeRun-WeChat" Official Account.;
price = 0;
trackId = 414478124;
releaseDate = 2011-01-21T01:32:15Z;
advisories = (
Infrequent/Mild Sexual Content and Nudity,
);
screenshotUrls = (
http://a4.mzstatic.com/us/r30/Purple69/v4/c5/da/c4/c5dac444-2bb7-0ef1-5e59-c86820d3bffa/screen1136x1136.jpeg,
http://a2.mzstatic.com/us/r30/Purple49/v4/8b/79/7c/8b797ce2-330a-0d46-1eac-17e706da4341/screen1136x1136.jpeg,
http://a1.mzstatic.com/us/r30/Purple69/v4/87/71/c1/8771c1a2-7af4-7cf2-6e15-0356420123d8/screen1136x1136.jpeg,
http://a5.mzstatic.com/us/r30/Purple69/v4/5e/79/be/5e79befa-5aef-cbab-30af-277ecc9928e1/screen1136x1136.jpeg,
http://a1.mzstatic.com/us/r30/Purple69/v4/b2/88/81/b28881b3-99e2-ccf6-ed30-112c60e83578/screen1136x1136.jpeg,
);
artistViewUrl = https://itunes.apple.com/us/developer/wechat/id614694882?uo=4;
primaryGenreId = 6005;
userRatingCount = 32235;
averageUserRatingForCurrentVersion = 4.5;
kind = software;
sellerUrl = http://www.wechat.com;
fileSizeBytes = 107574568;
trackContentRating = 12+;
bundleId = com.tencent.xin;
trackCensoredName = WeChat;
contentAdvisoryRating = 12+;
isGameCenterEnabled = 0;
artistName = WeChat;
languageCodesISO2A = (AR,ZH,EN,FR,DE,HE,HI,ID,IT,JA,KO,MS,PL,PT,RU,ZH,ES,TH,ZH,TR,VI,);
releaseNotes = Latest Updates
- Tagged contacts are viewable in alphabetical order .
- Support for sharing from Apple Music and iTunes to WeChat .
Recent Updates
- Search chat transcript by members or by date within a group chat .
- Keep track of your daily, weekly and monthly steps ranking in WeRun .;
features = (
iosUniversal,
);
averageUserRating = 4.5;
wrapperType = software;
artworkUrl512 = http://is5.mzstatic.com/image/thumb/Purple49/v4/23/31/14/233114f8-2e8d-7b63-8dc5-85d29893061e/source/512x512bb.jpg;
artworkUrl100 = http://is5.mzstatic.com/image/thumb/Purple49/v4/23/31/14/233114f8-2e8d-7b63-8dc5-85d29893061e/source/100x100bb.jpg;
trackViewUrl = https://itunes.apple.com/us/app/wechat/id414478124?mt=8&uo=4;
artistId = 614694882;
currency = USD;
ipadScreenshotUrls = (
http://a1.mzstatic.com/us/r30/Purple49/v4/4e/12/f7/4e12f702-e11d-5072-e142-5da0379c2361/screen480x480.jpeg,
http://a5.mzstatic.com/us/r30/Purple69/v4/5c/c9/86/5cc98635-6df4-59ba-4c5b-4a03528a4706/screen480x480.jpeg,
http://a5.mzstatic.com/us/r30/Purple69/v4/ad/cb/7e/adcb7e36-cfaa-0523-3503-9b723bc4d463/screen480x480.jpeg,
http://a5.mzstatic.com/us/r30/Purple49/v4/cf/63/88/cf6388b2-262f-9a58-53aa-f7b063c20c1c/screen480x480.jpeg,
);} , );}
從App Store 加載app版本
- (void)loadAppVersionFromAppStore{
[KitSDK tutor_postWithBaseURLString:@"http://itunes.apple.com/lookup?id=" URLString:@"1090786038" params:nil isPrint:NO success:^(id responseObject) {
NSArray *result = responseObject[@"results"];
if (result) {
NSDictionary *dict = [result firstObject];
if (dict) {
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
// NSString *appCurVersion = @"1.0.0";
NSString *newAppVersion = dict[@"version"];
if ([newAppVersion compare:appCurVersion] == NSOrderedDescending) {
NSDate *lastDate = [NSDate fs_dateFromString:[CPUserDefaultsTool getValueForKey:CPAppVersioncancelDate] format:@"yyyy-MM-dd"];
NSDate *nowDate = [NSDate date];
if ([nowDate fs_day] - [lastDate fs_day] > 1) {
self.releaseNotes = dict[@"releaseNotes"];
[self showAppHaveNewVeresion];
}
}
}
}
} failure:^(NSError *error) {
}];
}
顯示App有新版本
- (void)showAppHaveNewVeresion{
UIAlertView *sheet = [[UIAlertView alloc] initWithTitle:CPLocalizedString(@"Have a new version!") message:self.releaseNotes delegate:self cancelButtonTitle:CPLocalizedString(@"Cancel") otherButtonTitles:CPLocalizedString(@"OK"), nil];
[sheet show];
}
點擊提示信息
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (1 == buttonIndex) {
[self openAppaleShop];
}else{
NSString *cancelDate = [[NSDate date] fs_stringWithFormat:@"yyyy-MM-dd"];
[CPUserDefaultsTool saveWithValue:cancelDate forKey:CPAppVersioncancelDate];
}
[self.window endEditing:YES];
}
打開AppStore
- (void)openAppaleShop{
NSString *appleID = @"APPID";// iOS7和iOS8的打開方式不一樣
if (iOS7) {
NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@",appleID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
} else {
NSString *str = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@", appleID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}}