app 版本的更新

本文介绍了一个iOS应用程序如何实现自动检查新版本并提示用户进行更新的方法。通过发送异步请求到iTunes API来获取最新的应用版本信息,并与当前运行的应用版本进行对比,如果发现有新版本,则弹出对话框提示用户更新。
部署运行你感兴趣的模型镜像
static NSString *appid = @"1159247524"
static  NSString *appurl =@"http://itunes.apple.com/lookup?id=%@";

@interface AppDelegate ()<UIAlertViewDelegate>

@property(nonatomic,copy)NSString *UpdatesString;


@end


-(void)updatasApp

{

    NSString *appurlStr = [NSStringstringWithFormat:appurl,appid];

    NSURL *url = [NSURLURLWithString:appurlStr];

    

    NSURLRequest *requet = [[NSURLRequestalloc]initWithURL:urlcachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheDatatimeoutInterval:10];

    

    __weakAppDelegate *blockself = self;

    

    [NSURLConnectionsendAsynchronousRequest:requet queue:[NSOperationQueuemainQueue] completionHandler:^(NSURLResponse *_Nullable response, NSData *_Nullable data, NSError *_Nullable connectionError)

     {

         if (connectionError ==nil)

         {

             //这里应该刷新UI

             //1.给数据源数组赋值

             //2,赋值结束之后.刷新UI([self.tableView reloadData])

             NSDictionary *appInfoDict = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingAllowFragmentserror:nil];


             NSArray *resultArray = [appInfoDictobjectForKey:@"results"];

             

             if (resultArray.count )

             {

                 NSDictionary *infoDict = [resultArrayobjectAtIndex:0];

                 NSString *updateVersion = infoDict[@"version"];  //获取网络的版本号

                 

                 dispatch_async(dispatch_get_main_queue(), ^{

                     blockself.UpdatesString  = infoDict[@"trackViewUrl"];  //下载链接

                     [blockself getVersion:updateVersion];

                 });

             }

             }

    }];

}


-(void)getVersion:(NSString *)version

{

    NSDictionary *infodic = [[NSBundlemainBundle] infoDictionary];

    NSString *CurrentVersion = [infodicobjectForKey:@"CFBundleShortVersionString"];//获取当前版本

    if ([CurrentVersionisEqualToString:version])

    {

    }

    else{

        UIAlertView *alertView = [[UIAlertViewalloc]initWithTitle:@"新版本更新"message:nildelegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"升级",nil];

        alertView.tag = 666;

        [alertView show];

    }

}


//判断用户点击了哪一个按钮

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:      (NSInteger)buttonIndex

{

    if (alertView.tag == 666) {

        if (buttonIndex ==1) { //点击升级按钮,就从打开app store上应用的详情页面

            [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:self.UpdatesString]];

        }

    }

}



您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值