iOS开发之检测App更新

本文介绍了一个用于检测iOS应用商店中应用程序新版本的方法,并提供了跳转到App Store更新页面的实现方式。

//下方https中的s不要漏写,不然可能会得不到想要的数据

#define  appStoreCheckUrlStr  @"https://itunes.apple.com/cn/lookup?id=0123456789"

#define  appStoreUrlStr       @"https://itunes.apple.com/cn/app/appName/id0123456789?mt=8"

#define  nowVersion           [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]


//检测App新版本

-(void)judgeAPPVersion

{

    [NetworkUtils httpDoPOST:appStoreCheckUrlStr timeoutInterval:10 parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSArray *infoArray = [responseObject valueForKey:@"results"];

        NSDictionary *infoDict = [infoArray lastObject];

        NSString *iTunesVersion = [infoDict valueForKey:@"version"];

        DebugLog(@"最新版本iTunesVersion-->%@, 当前版本-->%@",iTunesVersion,nowVersion);

        if (iTunesVersion != nil && ![iTunesVersion isEqualToString:nowVersion]) {

            NSArray *Array1 = [iTunesVersion componentsSeparatedByString:@"."];

            NSArray *Array2 = [nowVersion componentsSeparatedByString:@"."];

            for (int i =0; i<Array1.count; i++) {

                if (i < Array2.count) {

                    if ([Array1[i] integerValue] > [Array2[i] integerValue]) {

                        //有新版本

                        return;

                    }else if ([Array1[i] integerValue] == [Array2[i] integerValue]){

                        continue;

                    }else{

                        return ;

                    }

                }else{

                    //有新版本

                    return;

                }

            }

        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        DebugLog(@"检测app更新请求失败");

    }];

}



//前往AppStore更新页面

   NSURL *url = [NSURL URLWithString:appStoreUrlStr];

   [[UIApplication sharedApplication] openURL:url];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值