iOS开发 app版本更新, 提醒

/**
     * 
检测版本升级需要用到的参数
     */
   iFeverAPPID = @"1076057848”; //appId;
//调用检测版本更新的方法
    [selfcheckVersion];

*
 * 
检测软件是否需要升级
 */

-(
void)checkVersion
{
   
//获取当前应用版本号
   
NSDictionary *appInfo = [[NSBundlemainBundle] infoDictionary];
   
NSString *currentVersion = [appInfoobjectForKey:@"CFBundleVersion"];
   
//  __block才能在局部作用域中改变变量的值
   
__block NSString *newVersion = @"";
   
NSString *updateUrlString = [NSStringstringWithFormat:@"http://itunes.apple.com/lookup?id=%ld",(long)[iFeverAPPIDintegerValue]];
   
   
NSString * str = [updateUrlStringstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
   
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];
    [manager
GET:str parameters:nil success:^(AFHTTPRequestOperation*operation, id responseObject) {
       
NSLog(@"123 + %@", operation);
       
NSDictionary *resultDic = responseObject;
       
NSArray *resultArray = [resultDicobjectForKey:@"results"];
       
       
for (idconfig in resultArray) {
            newVersion = [config
valueForKey:@"version"];
        }
       
if (newVersion) {
           
NSLog(@"通过AppStore获取的版本号是:%@", newVersion);
        }
       

result == 1

        NSComparisonResult result = [newVersion compare:currentVersion];


        if ( result == 1 ) { //appstore 版本大于当前版本
           
NSString *versionMessageStr = [ NSString stringWithFormat : @" 当前版本 %@, 最新版本为 %@, 请升级 ." ,currentVersion,newVersion];
           
UIAlertView *alert = [[ UIAlertView alloc ] initWithTitle : @" 升级提示 !" message : versionMessageStr delegate : self cancelButtonTitle : @" 下次再说 " otherButtonTitles : @" 现在升级 " , nil ];
            alert.
tag = kVersionNeedUpdateAlertTag ;
            [alert
show ];
        }
       
    }
failure :^( AFHTTPRequestOperation *operation, NSError *error) {
       
NSLog ( @"234 + %@" , error);
    }];
}


#pragma mark - UIAlertDelegate Method
// 收到推送时程序正在前台运行,则给出一个 alert ,用户选择查看,执行这个方法,并且跳转到指定页面
-(
void )alertView:( UIAlertView *)alertView clickedButtonAtIndex:( NSInteger )buttonIndex
{
   
if (buttonIndex == 1 ) {
       
// 软件需要更新提醒
       
if (alertView. tag == kVersionNeedUpdateAlertTag ) {
           
NSURL *url = [ NSURL URLWithString :[ NSString stringWithFormat : @"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%@?mt=8" , iFeverAPPID ]];
            [[UIApplicationsharedApplication]openURL:url];
           
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值