iOS开发之小技巧01-提示App从AppStore更新版本

一.需求

公司之前一直在用企业证书开发和发布,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]];
}}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,298评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,701评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 107,078评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,687评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,018评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,410评论 1 211
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,729评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,412评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,124评论 1 239
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,379评论 2 242
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,903评论 1 257
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,268评论 2 251
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,894评论 3 233
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,014评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,770评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,435评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,312评论 2 260

推荐阅读更多精彩内容