当前位置:   article > 正文

iOS--OC获取app应用版本的信息和当前设备的各种信息,跳转到appstore(二)_ios oc 获取app版本

ios oc 获取app版本

    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; 

//                     }  

//                     );  

//    }  

  1. //版本更新
  2. -(void)updateVersion{
  3. //App Store版本号
  4. //https://appstoreconnect.apple.com/apps/1123526409/appstore/ios/version/deliverable
  5. //方法一:
  6. NSString *appID=@"1123526409"; //appID取的是上面的中间的10位数字
  7. NSString *urlStr=[NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?id=%@",appID];
  8. [[QMWNHttpRequestManager sharedManager] normaldownloadWithUrl:urlStr params:@{} successBlock:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
  9. SLog(@"appstore信息--%@",responseObject);
  10. NSLog(@"version---%@",dict);
  11. NSString *versionStr=@"1.0";
  12. if([[dict allKeys]containsObject:@"results"]){
  13. NSArray *results = [dict objectForKey:@"results"];
  14. if(results.count>0){
  15. NSDictionary *result = [results objectAtIndex:0];
  16. if([[result allKeys]containsObject:@"version"]){
  17. versionStr = [result objectForKey:@"version"];//获得AppStore中的app的版本
  18. self.versionStr=versionStr;
  19. }
  20. }
  21. }
  22. } failureBlock:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
  23. }];
  24. //方法二
  25. NSString *appID=@"1123526409"; //appID---id=1123526409。。。。1260861998
  26. NSString *urlStr=[NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?id=%@",appID];
  27. NSURL *url=[NSURL URLWithString:urlStr];
  28. NSData *json = [NSData dataWithContentsOfURL:url];
  29. NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:json options:0 error:NULL];//解析json文件
  30. NSLog(@"version---%@",dict);
  31. NSString *versionStr=@"1.0";
  32. if([[dict allKeys]containsObject:@"results"]){
  33. NSArray *results = [dict objectForKey:@"results"];
  34. if(results.count>0){
  35. NSDictionary *result = [results objectAtIndex:0];
  36. if([[result allKeys]containsObject:@"version"]){
  37. versionStr = [result objectForKey:@"version"];//获得AppStore中的app的版本
  38. self.versionStr=versionStr;
  39. }
  40. }
  41. }
  42. // 当前版本
  43. NSDictionary *infoDictionary = [[NSBundle mainBundle]infoDictionary];
  44. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  45. //版本比较
  46. BOOL isupdate=NO;
  47. NSArray *appstoreversionseparr=[versionStr componentsSeparatedByString:@"."];//App Store版本号分割
  48. NSArray *localversionseparr=[app_Version componentsSeparatedByString:@"."];//本地版本分割
  49. if(appstoreversionseparr.count>0 && localversionseparr.count>0){
  50. if( [appstoreversionseparr[0] intValue]>[localversionseparr[0] intValue]){
  51. //第一位版本不一致,升级
  52. isupdate=YES;
  53. }else if([appstoreversionseparr[0] intValue]==[localversionseparr[0] intValue]){
  54. // 第一位版本一致,继续比较第二位版本
  55. if(appstoreversionseparr.count>1 && localversionseparr.count>1){
  56. if( [appstoreversionseparr[1] intValue]>[localversionseparr[1] intValue]){
  57. //第二位版本不一致,升级
  58. isupdate=YES;
  59. }else if( [appstoreversionseparr[1] intValue]==[localversionseparr[1] intValue]){
  60. //第二位版本一致,继续比较第三位版本
  61. if(appstoreversionseparr.count>2 && localversionseparr.count>2){
  62. if( [appstoreversionseparr[2] intValue]>[localversionseparr[2] intValue]){
  63. //第三位版本号不一致,升级
  64. isupdate=YES;
  65. }else if( [appstoreversionseparr[2] intValue]==[localversionseparr[2] intValue]){
  66. //第三位版本号一致,不升级
  67. isupdate=NO;
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. //appstore评价页面
  75. NSString *appID=@"1123526409"; //appID---id=1123526409。。。。1260861998
  76. NSString *gotoappstorecommentlinkstr = [NSString stringWithFormat:@"https://itunes.apple.com/us/app/itunes-u/id%@?action=write-review&mt=8", appID];
  77. if (@available(iOS 10.0, *)) {
  78. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:gotoappstorecommentlinkstr] options:@{UIApplicationOpenURLOptionUniversalLinksOnly : @NO
  79. } completionHandler:nil];
  80. } else {
  81. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:gotoappstorecommentlinkstr]];
  82. }
  83. //appstore下载页面
  84. if(!isupdate){
  85. [[LYCommonMBprogresshud sharedManager]showProgresshudTextWith:self.view title:@"当前已经是最新版本" detailtitle:@"" isOnDismissbg:NO hideAfterdelay:YES];
  86. }else{
  87. NSString *appID=@"1123526409"; //appID---id=1123526409。。。。1260861998
  88. NSString *gotoappstoredetailurlstr = [NSString
  89. stringWithFormat:@"https://itunes.apple.com/us/app/itunes-u/id%@",
  90. appID];
  91. if (@available(iOS 10.0, *)) {
  92. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:gotoappstoredetailurlstr] options:@{UIApplicationOpenURLOptionUniversalLinksOnly : @NO
  93. } completionHandler:nil];
  94. } else {
  95. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:gotoappstoredetailurlstr]];
  96. }
  97. }
  98. }

=======================

首页提示更新

//跟服务器版本比较

-(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信息

  1. NSString * str =[NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?id=%@",APPStoreID];
  2. AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
  3. [manager POST:str parameters:@{} progress:^(NSProgress * _Nonnull uploadProgress) {
  4. } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  5. NSArray *array = responseObject[@"results"];
  6. NSDictionary *dict = [array lastObject];
  7. NSString * version = dict[@"version"];
  8. NSString * relaseNotes = dict[@"releaseNotes"];
  9. self.releaseNotes = relaseNotes;
  10. BOOL isNeedUpdate = [self isNeedUpdateWithCurrentVersion:dict[@"version"]];
  11. if(isNeedUpdate){
  12. //有新版本
  13. }else{
  14. //当前就是最新版本
  15. }
  16. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  17. }];
  18. //版本比较
  19. (BOOL) isNeedUpdateWithCurrentVersion:(NSString *) currentVersion{
  20. if(!currentVersion){
  21. return NO;
  22. }
  23. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  24. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  25. NSArray * locVs = [app_Version componentsSeparatedByString:@"."];
  26. NSArray * storeVs = [currentVersion componentsSeparatedByString:@"."];
  27. if(locVs.count>=storeVs.count){
  28. BOOL isNew = NO;
  29. for (NSInteger index = 0;index<locVs.count ;index ++) {
  30. NSString * num = locVs[index];
  31. if(index<= storeVs.count -1){
  32. NSString * sNum = storeVs[index];
  33. if(num.integerValue< sNum.integerValue){
  34. isNew = YES;
  35. return YES;
  36. }else if (num.integerValue> sNum.integerValue){
  37. return NO;
  38. }else{
  39. }
  40. }else{//
  41. return NO;
  42. }
  43. }
  44. return isNew;
  45. }else{
  46. BOOL isNew = NO;
  47. for (NSString * sNum in storeVs) {
  48. NSInteger index = [storeVs indexOfObject:sNum];
  49. if(index<= locVs.count -1){
  50. NSString * num = locVs[index];
  51. if(num.integerValue < sNum.integerValue){
  52. return YES;
  53. }else if (num.integerValue > sNum.integerValue){
  54. return NO;
  55. }else{
  56. }
  57. }else{
  58. return YES;
  59. }
  60. }
  61. return isNew;
  62. }
  63. }
  64. //前往appstore更新
  65. NSString *str = [NSString stringWithFormat:
  66. @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@",
  67. APPStoreID];
  68. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/421013
推荐阅读
相关标签
  

闽ICP备14008679号