iOS-检查版本更新

1、

// FIR.im的自动更新

  

 NSString *bundleId = [[NSBundlemainBundle]infoDictionary][@"CFBundleIdentifier"];

    NSString *bundleIdUrlString = [NSStringstringWithFormat:@"http://api.fir.im/apps/latest/%@?api_token=71eb982be4f093719d2b7d985b236fb7&type=ios", bundleId];

    NSURL *requestURL = [NSURLURLWithString:bundleIdUrlString];

    NSURLRequest *request = [NSURLRequestrequestWithURL:requestURL];

    [NSURLConnectionsendAsynchronousRequest:requestqueue :[NSOperationQueuecurrentQueue]completionHandler:^(NSURLResponse *response,NSData *data,NSError *connectionError) {

        if (connectionError) {

            //do something

            XNLog(@"版本检查失败");

        }else {

            NSError *jsonError =nil;

            id object = [NSJSONSerializationJSONObjectWithData:dataoptions:0error:&jsonError];

            if (!jsonError && [objectisKindOfClass:[NSDictionaryclass]]) {

                //do something

                //NSString * version=object[@"version"]; //对应 CFBundleVersion,对应Xcode项目配置"General"中的 Build

                NSString * versionShort=object[@"versionShort"];//对应 CFBundleShortVersionString,对应Xcode项目配置"General"中的 Version

                

                //NSString * localVersion=[[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];

                NSString * localVersionShort=[[NSBundlemainBundle]infoDictionary][@"CFBundleShortVersionString"];

                nss_updateURL=object[@"update_url"];//如果有更新需要用Safari打开的地址

                //NSString *changelog=object[@"changelog"]; //如果有更新需要用Safari打开的地址

                if (![localVersionShort isEqualToString:versionShort]) {

                    [[AlertHandlersingleton]showConfirm_default_title:@"发现新版本"message:[NSStringstringWithFormat:@"发现新版本v%@",versionShort]delegate:self

                                                     cancelButtonTitle:@"忽略"otherButtonTitle:@"点击更新"tag:1];

                }

            }

        }

    }];

 

 

 

 

 

 

2、

 

<span style="font-size:18px;">if ([[CommFunsingleton]event_updateVersion] ==YES) {

            UIApplication *application = [UIApplicationsharedApplication];

            [applicationopenURL:[NSURLURLWithString:[UesrInfosingleton].updateURL]];

        }else{

            NSString * localVersionShort=[[NSBundlemainBundle]infoDictionary][@"CFBundleShortVersionString"];

            [[AlertHandlersingleton]showConfirm_default_title:[NSStringstringWithFormat:@"当前版本v%@", localVersionShort]message:@"当前已是最新版本"delegate:selfcancelButtonTitle:@"确定"otherButtonTitle:niltag:1];

        }


-(BOOL)event_updateVersion{

    // TODO:去掉版本检查(苹果审核不通过)

    [UesrInfosingleton].needUpdate =NO;

    returnNO;

    [UesrInfosingleton].needUpdate =YES;

    NSString *bundleId = [[NSBundlemainBundle]infoDictionary][@"CFBundleIdentifier"];

    NSString *bundleIdUrlString = [NSStringstringWithFormat:@"http://api.fir.im/apps/latest/%@?api_token=71eb982be4f093719d2b7d985b236fb7&type=ios", bundleId];

    NSURL *requestURL = [NSURLURLWithString:bundleIdUrlString];

    NSURLRequest *request = [NSURLRequestrequestWithURL:requestURL];

    [NSURLConnectionsendAsynchronousRequest:requestqueue :[NSOperationQueuecurrentQueue]completionHandler:^(NSURLResponse *response,NSData *data,NSError *connectionError) {

        if (connectionError) {

            //do something

            XNLog(@"版本检查失败");

        }else {

            NSError *jsonError =nil;

            id object = [NSJSONSerializationJSONObjectWithData:dataoptions:0error:&jsonError];

            if (!jsonError && [objectisKindOfClass:[NSDictionaryclass]]) {

                //do something

                //NSString * version=object[@"version"]; //对应 CFBundleVersion,对应Xcode项目配置"General"中的 Build

                NSString * versionShort=object[@"versionShort"];//对应 CFBundleShortVersionString,对应Xcode项目配置"General"中的 Version

                

                //NSString * localVersion=[[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];

                NSString * localVersionShort=[[NSBundlemainBundle]infoDictionary][@"CFBundleShortVersionString"];

                NSString *nss_updateURL=object[@"update_url"];//如果有更新需要用Safari打开的地址

                //NSString *changelog=object[@"changelog"]; //如果有更新需要用Safari打开的地址

                if (![localVersionShort isEqualToString:versionShort]){

                    [UesrInfosingleton].needUpdate =YES;

                }else{

                    [UesrInfosingleton].needUpdate =NO;

                }

                [[UesrInfosingleton]setUpdateURL:nss_updateURL];

            }

        }

    }];

    

    return [UesrInfosingleton].needUpdate;

}

-(void)setUpdateURL:(NSString *)updateURL{

    NSMutableDictionary *updateURLDic = [[NSMutableDictionaryalloc]initWithObjectsAndKeys:updateURL,@"updateURL",nil];

    

    [PlistReaderdoWrite:@"updateURL"dic:updateURLDic];

}</span>

 

 

 

       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值