NSDictionary *infoDictionary = [[NSBundle mainBundle]infoDictionary];
CFShow(CFBridgingRetain(infoDictionary));//打印出infoDictionary的详细信息
//bundelID
NSString *bundelID= [[NSBundle mainBundle]bundleIdentifier];
NSLog(@"bundelID---%@",bundelID);
// app名称displayName
NSString *app_Name = [infoDictionaryobjectForKey:@"CFBundleDisplayName"];
NSLog(@"app名称displayname---%@",app_Name);
// app名称name,当displayname存在时,name显示为override,displayname不存在时,name正常显示
NSString *name = [infoDictionaryobjectForKey:@"CFBundleName"];
NSLog(@"app名称name---%@",name);
// app版本
NSString *app_Version = [infoDictionaryobjectForKey:@"CFBundleShortVersionString"];
NSLog(@"app当前版本----%@",app_Version);
// app build版本
NSString *app_build = [infoDictionaryobjectForKey:@"CFBundleVersion"];
NSLog(@"app的构建版本---%@",app_build);
//手机序列号(唯一标识)
NSString* identifierNumber =[[[UIDevice currentDevice]identifierForVendor]UUIDString];
NSLog(@"手机序列号: %@",identifierNumber);
//手机别名:用户定义的名称
NSString* userPhoneName = [[UIDevice currentDevice]name];
NSLog(@"手机别名: %@", userPhoneName);
//设备名称
NSString* deviceName = [[UIDevice currentDevice]systemName];
NSLog(@"设备名称: %@",deviceName );
//手机系统版本
NSString* phoneVersion = [[UIDevice currentDevice]systemVersion];
NSLog(@"手机系统版本: %@", phoneVersion);
//手机型号
NSString* phoneModel = [[UIDevice currentDevice]model];
NSLog(@"手机型号: %@",phoneModel );
//地方型号 (国际化区域名称)
NSString* localPhoneModel = [[UIDevice currentDevice]localizedModel];
NSLog(@"国际化区域名称: %@",localPhoneModel );
CGFloat width= [UIScreen mainScreen].bounds.size.width;
NSLog(@"当前屏幕宽度--%f",width);
=======================================
//从appstore解析得到的数据
// {
// resultCount= 1;
// results= (
// {
// artistId= 开发者ID;
// artistName= 开发者名称;
// price= 0;
// isGameCenterEnabled= 0;
// kind= software;
// languageCodesISO2A= (
// EN
// );
// trackCensoredName= 审(我们的)查名称;
// trackContentRating= 评级;
// trackId= 应用程序 ID;
// trackName= 应用程序名称";
// trackViewUrl= 应用程序介绍网址;
// userRatingCount= 用户评级;
// userRatingCountForCurrentVersion= 1;
// version= 版本号;
// wrapperType= software;
// }
// );
// }
//版本更新
-(void)updateVersion{
//App Store版本号
//https://appstoreconnect.apple.com/apps/1123526409/appstore/ios/version/deliverable
//方法一:
NSString *appID=@"1123526409"; //appID取的是上面的中间的10位数字
NSString *urlStr=[NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?id=%@",appID];
[[QMWNHttpRequestManager sharedManager] normaldownloadWithUrl:urlStr params:@{} successBlock:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
SLog(@"appstore信息--%@",responseObject);
NSLog(@"version---%@",dict);
NSString *versionStr=@"1.0";
if([[dict allKeys]containsObject:@"results"]){
NSArray *results = [dict objectForKey:@"results"];
if(results.count>0){
NSDictionary *result = [results objectAtIndex:0];
if([[result allKeys]containsObject:@"version"]){
versionStr = [result objectForKey:@"version"];//获得AppStore中的app的版本
self.versionStr=versionStr;
}
}
}
} failureBlock:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
}];
//方法二
NSString *appID=@"1123526409"; //appID---id=1123526409。。。。1260861998
NSString *urlStr=[NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?id=%@",appID];
NSURL *url=[NSURL URLWithString:urlStr];
NSData *json = [NSData dataWithContentsOfURL:url];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:json options:0 error:NULL];//解析json文件
NSLog(@"version---%@",dict);
NSString *versionStr=@"1.0";
if([[dict allKeys]containsObject:@"results"]){
NSArray *results = [dict objectForKey:@"results"];
if(results.count>0){
NSDictionary *result = [results objectAtIndex:0];
if([[result allKeys]containsObject:@"version"]){
versionStr = [result objectForKey:@"version"];//获得AppStore中的app的版本
self.versionStr=versionStr;
}
}
}
// 当前版本
NSDictionary *infoDictionary = [[NSBundle mainBundle]infoDictionary];
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
//版本比较
BOOL isupdate=NO;
NSArray *appstoreversionseparr=[versionStr componentsSeparatedByString:@"."];//App Store版本号分割
NSArray *localversionseparr=[app_Version componentsSeparatedByString:@"."];//本地版本分割
if(appstoreversionseparr.count>0 && localversionseparr.count>0){
if( [appstoreversionseparr[0] intValue]>[localversionseparr[0] intValue]){
//第一位版本不一致,升级
isupdate=YES;
}else if([appstoreversionseparr[0] intValue]==[localversionseparr[0] intValue]){
// 第一位版本一致,继续比较第二位版本
if(appstoreversionseparr.count>1 && localversionseparr.count>1){
if( [appstoreversionseparr[1] intValue]>[localversionseparr[1] intValue]){
//第二位版本不一致,升级
isupdate=YES;
}else if( [appstoreversionseparr[1] intValue]==[localversionseparr[1] intValue]){
//第二位版本一致,继续比较第三位版本
if(appstoreversionseparr.count>2 && localversionseparr.count>2){
if( [appstoreversionseparr[2] intValue]>[localversionseparr[2] intValue]){
//第三位版本号不一致,升级
isupdate=YES;
}else if( [appstoreversionseparr[2] intValue]==[localversionseparr[2] intValue]){
//第三位版本号一致,不升级
isupdate=NO;
}
}
}
}
}
}
//appstore评价页面
NSString *appID=@"1123526409"; //appID---id=1123526409。。。。1260861998
NSString *gotoappstorecommentlinkstr = [NSString stringWithFormat:@"https://itunes.apple.com/us/app/itunes-u/id%@?action=write-review&mt=8", appID];
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:gotoappstorecommentlinkstr] options:@{UIApplicationOpenURLOptionUniversalLinksOnly : @NO
} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:gotoappstorecommentlinkstr]];
}
//appstore下载页面
if(!isupdate){
[[LYCommonMBprogresshud sharedManager]showProgresshudTextWith:self.view title:@"当前已经是最新版本" detailtitle:@"" isOnDismissbg:NO hideAfterdelay:YES];
}else{
NSString *appID=@"1123526409"; //appID---id=1123526409。。。。1260861998
NSString *gotoappstoredetailurlstr = [NSString
stringWithFormat:@"https://itunes.apple.com/us/app/itunes-u/id%@",
appID];
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:gotoappstoredetailurlstr] options:@{UIApplicationOpenURLOptionUniversalLinksOnly : @NO
} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:gotoappstoredetailurlstr]];
}
}
}
=======================
首页提示更新
//跟服务器版本比较
-(void)compareServiceVertion{
// // app版本当前版本
NSDictionary * infoDictionary=[[NSBundlemainBundle] infoDictionary];
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSString *serviceVersion=@"1.0.0";
if([LYCommanManagersharedManager].isreachable){//网络可用才查询APPstore版本
serviceVersion=[LYCommanManager sharedManager].finaceString;
// 版本跟新提示
// 1.新增信用卡垫付功能
// 2.理财功能下架
// 3.优化了我的详情页面
// 4.优化了启动页面
// 5.优化了积分详情页面(安卓)
// 6.优化了分享模块中邀请模板和视频教程
// 7.优化了消息详情页面
// 8.对上一版本1.1.3进行了bug修复
NSString * updateStr = [[LYCommanManagersharedManager].updateStringstringByReplacingOccurrencesOfString:@"\\n"withString:@"\r\n"];
if([serviceVersion compare:app_Version] ==NSOrderedDescending){
UIAlertController *controller=[UIAlertControlleralertControllerWithTitle:@"有新版本更新" message:updateStrpreferredStyle:UIAlertControllerStyleAlert];
UIView *subView1 = controller.view.subviews[0];
UIView *subView2 = subView1.subviews[0];
UIView *subView3 = subView2.subviews[0];
UIView *subView4 = subView3.subviews[0];
UIView *subView5 = subView4.subviews[0];
//取title和message:
// UILabel *title = subView5.subviews[0];
UILabel *message = subView5.subviews[1];
message.textAlignment = NSTextAlignmentLeft;
UIAlertAction *sure=[UIAlertActionactionWithTitle:@"确定"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *_Nonnull action) {
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"http://www.ddb.cn/index.php/Kaifa/Index/appReg"]];///跳转到更新页面
}];
UIAlertAction *cancel=[UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction *_Nonnull action) {
}];
[controller addAction:sure];
[controller addAction:cancel];
[selfpresentViewController:controller animated:YEScompletion:nil];
}
}
}
///获取appstore信息
NSString * str =[NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?id=%@",APPStoreID];
AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
[manager POST:str parameters:@{} progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *array = responseObject[@"results"];
NSDictionary *dict = [array lastObject];
NSString * version = dict[@"version"];
NSString * relaseNotes = dict[@"releaseNotes"];
self.releaseNotes = relaseNotes;
BOOL isNeedUpdate = [self isNeedUpdateWithCurrentVersion:dict[@"version"]];
if(isNeedUpdate){
//有新版本
}else{
//当前就是最新版本
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
//版本比较
(BOOL) isNeedUpdateWithCurrentVersion:(NSString *) currentVersion{
if(!currentVersion){
return NO;
}
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSArray * locVs = [app_Version componentsSeparatedByString:@"."];
NSArray * storeVs = [currentVersion componentsSeparatedByString:@"."];
if(locVs.count>=storeVs.count){
BOOL isNew = NO;
for (NSInteger index = 0;index<locVs.count ;index ++) {
NSString * num = locVs[index];
if(index<= storeVs.count -1){
NSString * sNum = storeVs[index];
if(num.integerValue< sNum.integerValue){
isNew = YES;
return YES;
}else if (num.integerValue> sNum.integerValue){
return NO;
}else{
}
}else{//
return NO;
}
}
return isNew;
}else{
BOOL isNew = NO;
for (NSString * sNum in storeVs) {
NSInteger index = [storeVs indexOfObject:sNum];
if(index<= locVs.count -1){
NSString * num = locVs[index];
if(num.integerValue < sNum.integerValue){
return YES;
}else if (num.integerValue > sNum.integerValue){
return NO;
}else{
}
}else{
return YES;
}
}
return isNew;
}
}
//前往appstore更新
NSString *str = [NSString stringWithFormat:
@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@",
APPStoreID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];