Fir平台上自动更新app的版本

来源:互联网 发布:音频矩阵 编辑:程序博客网 时间:2024/05/29 06:44
<span style="font-size:18px;">- (void)versionUpdate {        NSString *firAppID = @"自己填写"; //Fir平台上你app对应的ID    NSString *strApp = [NSString stringWithFormat:@"%@%@",@"http://fir.im/api/v2/app/version/",firAppID];        [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:strApp]] queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {                if (data) {            @try {                NSDictionary *result= [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];                                //Fir上的版本                NSString * version=result[@"version"]; //对应 CFBundleVersion, 对应Xcode项目配置"General"中的 Build                              //本地的版本                NSString * localVersion=[[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];                                //更新下载的地址                downURL = result[@"update_url"]; //如果有更新 需要用Safari打开的地址                                //如果有更新版本则前往下载                if ([version integerValue] > [localVersion integerValue]) {                    UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"发现新的版本,是否更新" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];                    [alter show];                                    }else {                    NSLog(@"无新的版本");                }                                        }            @catch (NSException *exception) {                //返回格式错误 忽略掉            }        }            }];}- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    //前往appstore下载最新版本    if (buttonIndex==1) {        NSURL *url = [NSURL URLWithString:downURL];        [[UIApplication sharedApplication] openURL:url];    }}@end</span>

0 0
原创粉丝点击