日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

iOS检测更新功能

發布時間:2025/5/22 81 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS检测更新功能 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

//
// ?LBViewController.m
// ?LiveBroadcast
//
// ?Created by gz on 16/9/14.
// ?Copyright ? 2016年
//

#import "LBViewController.h"


#define kAPP_URL @"http://itunes.apple.com/lookup?id="
#define kAppID @"112125"

[@interface](https://my.oschina.net/u/996807) LBViewController () {
? ? NSString * _trackViewUrl;
}

[@end](https://my.oschina.net/u/567204)

@implementation LBViewController

- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
? ? [super didReceiveMemoryWarning];
? ? // Dispose of any resources that can be recreated.
}
- (void)checkUpdateApp {
? ? NSError *error;
? ? //kAPP_URL : http://itunes.apple.com/lookup?id=
? ? //kAppId : 在iTunes connect上申請的APP ID
? ? NSString *urlStr = [NSString stringWithFormat:@"%@%@", kAPP_URL, kAppID];
? ? NSURL *url = [NSURL URLWithString:urlStr];
? ? NSURLRequest *request = [NSURLRequest requestWithURL:url];
? ? NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
? ??
? ? NSDictionary *appInfoDict = [NSJSONSerialization JSONObjectWithData:response
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?options:NSJSONReadingAllowFragments
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?error:&error];
// ? ?NSDictionary *appInfoDict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
? ??
? ? if (error) {
? ? ? ? NSLog(@"%@", error.description);
? ? ? ? return;
? ? }
? ??
? ? NSArray *resultArray = [appInfoDict objectForKey:@"results"];
? ??
? ? if (![resultArray count]) {
? ? ? ? NSLog(@"error : resultArray == nil");
? ? ? ? return;
? ? }
? ??
? ? NSDictionary *infoDict = [resultArray objectAtIndex:0];
? ? //獲取服務器上應用的最新版本號
? ? NSString *appleV = infoDict[@"version"];
? ? NSString *aV = [appleV copy];
? ??
? ? NSString *trackName = infoDict[@"trackName"];
? ??
? ? _trackViewUrl = infoDict[@"trackViewUrl"];
? ??
? ? //獲取當前設備中應用的版本號
? ? NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
? ? NSString *cV = [infoDic objectForKey:@"CFBundleShortVersionString"];
? ??
? ? cV = [cV stringByReplacingOccurrencesOfString:@"." withString:@""];
? ? aV = [aV stringByReplacingOccurrencesOfString:@"." withString:@""];
? ??
? ? NSInteger length = MIN(cV.length, aV.length);

? ? cV = [cV substringToIndex:length];
? ? aV = [aV substringToIndex:length];

? ? CGFloat updateVersion = [aV doubleValue];
? ? CGFloat currentVersion = [cV doubleValue];
? ? //判斷兩個版本是否相同
? ? if (currentVersion <= updateVersion) {
? ? ? ? UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"%@",trackName] message:[NSString stringWithFormat:@"發現新版本(%@),是否更新", appleV] preferredStyle:UIAlertControllerStyleAlert];
? ? ? ? UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
? ? ? ? }];
? ? ? ? [alertController addAction:cancelAction];
? ? ? ? UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"升級" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
? ? ? ? ? ? [[UIApplication sharedApplication] openURL:[NSURL URLWithString:_trackViewUrl]];
? ? ? ? }];
? ? ? ? [alertController addAction:sureAction];
? ? ? ? [self presentViewController:alertController animated:YES completion:nil];
? ? ? ??
? ? } else { ?//版本號和app store上的一致
? ? }
}

@end

轉載于:https://my.oschina.net/gdxz111/blog/746902

總結

以上是生活随笔為你收集整理的iOS检测更新功能的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。