iOS怎样做版本更新,获取Appstore上的版本号和项目中的版本号

本文介绍了一种通过发送异步请求到iTunes API来获取指定应用在AppStore上最新版本号的方法,并展示了如何将该版本号与当前应用版本进行对比。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//获取AppStore上的版本号

NSString *url = [[NSStringalloc]initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"1063983037"];//后数字修改成自己项目的APPID

[self Postpath:url];

#pragma mark -- 获取AppStore上的版本号

-(void)Postpath:(NSString *)path

{


    NSURL *url = [NSURLURLWithString:path];

    NSMutableURLRequest *request = [NSMutableURLRequestrequestWithURL:url

                                                           cachePolicy:NSURLRequestReloadIgnoringCacheData

                                                       timeoutInterval:10];


    [request setHTTPMethod:@"POST"];



    NSOperationQueue *queue = [NSOperationQueuenew];


    [NSURLConnectionsendAsynchronousRequest:requestqueue:queuecompletionHandler:^(NSURLResponse *response,NSData *data,NSError *error){

        NSMutableDictionary *receiveStatusDic=[[NSMutableDictionaryalloc]init];

        if (data) {


            NSDictionary *receiveDic = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingMutableLeaveserror:nil];

            if ([[receiveDicvalueForKey:@"resultCount"]intValue]>0) {


                [receiveStatusDic setValue:@"1"forKey:@"status"];

                [receiveStatusDic setValue:[[[receiveDicvalueForKey:@"results"]objectAtIndex:0]valueForKey:@"version"]  forKey:@"version"];

            }else{


                [receiveStatusDic setValue:@"-1"forKey:@"status"];

            }

        }else{

            [receiveStatusDic setValue:@"-1"forKey:@"status"];

        }


        [selfperformSelectorOnMainThread:@selector(receiveData:)withObject:receiveStatusDicwaitUntilDone:NO];

    }];


}

-(void)receiveData:(id)sender

{

    NSLog(@"receiveData=%@",sender);

    //从字典中取出AppStore中的版本号

    NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:senderoptions:NSJSONReadingMutableLeaveserror:nil];

    NSString *version = [dicobjectForKey:@"version"];

}

//获取当前项目的版本号

NSDictionary *infoDictionary = [[NSBundlemainBundle]infoDictionary];

    CFShow((__bridgeCFTypeRef)(infoDictionary));

    NSString *app_Version = [infoDictionaryobjectForKey:@"CFBundleShortVersionString"];

//打开AppStore

NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/us/app/id%@",@1063983037];

            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值