【作者前言】:13年入圈这敬,分享些本人工作中遇到的點點滴滴那些事兒航夺,17年剛開始寫博客,高手勿噴崔涂!以分享交流為主阳掐,歡迎各路豪杰點評改進!
1.應用場景:
Paste_Image.png
2.實現(xiàn)目標:
蘋果審核規(guī)則里已經(jīng)明確規(guī)定不允許 出現(xiàn)如下按鈕冷蚂,因為APPStore會自動更新
版本更新
但是因為某些項目要求缭保,在需要更新的時候就需要我們彈窗提示一下,原理很簡單蝙茶,就是先獲取APPStore對應產(chǎn)品的版本信息涮俄,與用戶所安裝的版本信息就行對比,如果APPStore版本信息高于用戶當前使用的版本尸闸,則給出彈窗提示信息
3.代碼說明:
Tips:獲取App Store上產(chǎn)品對應的APPID,如圖所示
Paste_Image.png
#pragma mark -
#pragma mark - yp_checkoutUpdateAppVersion 校驗是否需要前往APPStore更新
const NSString *appStoreAppID = @"414478124";//AppStore上面對應的APPID孕锄,獲取方式如上圖
- (void)yp_checkoutUpdateAppVersion {
NSString *getAppStoreInfo = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",appStoreAppID];
//用AFNetwork網(wǎng)絡(luò)請求方式發(fā)起Post請求
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:getAppStoreInfo parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *resultsArr = responseObject[@"results"];
NSDictionary *dict = [resultsArr lastObject];
/** 得到AppStore的應用的版本信息*/
NSString *appStoreCurrentVersion = dict[@"version"];
/** 獲取當前安裝的應用的版本信息*/
NSString *appCurrentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
if ([appCurrentVersion compare:appStoreCurrentVersion options:NSNumericSearch] == NSOrderedAscending){//有更新版本吮廉,需要提示前往更新
UIAlertView *updateAlertV = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"您有新版本更新(%@)", appStoreCurrentVersion] message:@"" delegate:self cancelButtonTitle:@"我在看看" otherButtonTitles:@"馬上更新", nil];
[updateAlertV show];
}else{//沒有更新版本,不進行操作
NSLog(@"當前為最新版本畸肆,暫無更新版本");
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
}
#pragma mark -
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *updateUrlString = [NSString stringWithFormat:@"https://itunes.apple.com/cn/app/id%@?mt=8",appStoreAppID];
if (buttonIndex) {//馬上更新
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:updateUrlString]];
}else {//我在看看
}
}