您的位置:首页 > 移动开发

iOS app版本监测升级

2016-06-08 09:09 274 查看
//从Appstore监测版本

-(void)onCheckVersion

{

//本地短版本号

    NSDictionary *infoDic = [[NSBundlemainBundle]
infoDictionary];

    //CFShow((__bridge CFTypeRef)(infoDic));

    NSString *currentVersion = [infoDic
objectForKey:@"CFBundleShortVersionString"];

    //itunes版本号

    NSString *URL =@"http://itunes.apple.com/lookup?id=1102364142";

    NSMutableURLRequest *request = [[NSMutableURLRequestalloc]
init];

    [request setURL:[NSURLURLWithString:URL]];

    [request setHTTPMethod:@"POST"];

    NSHTTPURLResponse *urlResponse =
nil;

    NSError *error =
nil;

    NSData *recervedData = [NSURLConnectionsendSynchronousRequest:request
returningResponse:&urlResponse
error:&error];

    

    NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:recervedData
options:kNilOptionserror:&error];

    NSArray *infoArray = [dic
objectForKey:@"results"];

    if ([infoArray
count]) {

        NSDictionary *releaseInfo = [infoArrayobjectAtIndex:0];

        NSString *lastVersion = [releaseInfo
objectForKey:@"version"];

        

        if (![lastVersion
isEqualToString:currentVersion]) {

            UIAlertView *alert = [[UIAlertViewalloc]
initWithTitle:@"更新"message:@"有新的版本更新,是否前往更新?"delegate:selfcancelButtonTitle:@"关闭"otherButtonTitles:@"更新",nil];

            alert.tag =
10000;

            [alert show];

        }

    }

}

//更新地址

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

{

    if (alertView.tag==10000) {

        if (buttonIndex==1) {

            NSURL *url = [NSURLURLWithString:@"https://itunes.apple.com/us/app/coband/id1102364142?mt=8"];

下载地址类似:http://itunes.apple.com/app/id1166090758

            [[UIApplicationsharedApplication]openURL:url];

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: