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閱讀 230,002評論 6 542
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,400評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,136評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,714評論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,452評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,818評論 1 328
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,812評論 3 446
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,997評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,552評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,292評論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,510評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,035評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,721評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,121評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,429評論 1 294
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,235評論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,480評論 2 379

推薦閱讀更多精彩內容