fir.im 上企业版IPA版本更新

- (void)updateVersion
{
//appid 是上传IPA的ID APIToken 查看文档如何生成
    NSString *idUrlString = @"http://api.fir.im/apps/latest/APPID?api_token=XXX";
    NSURL *requestURL = [NSURL URLWithString:idUrlString];
    NSURLRequest *request = [NSURLRequest requestWithURL:requestURL];
    NSURLResponse *response = nil;
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
    
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    NSDictionary *version = [dic objectForKey:@"versionShort"];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        //在线版本与本地版本比较
        if (version > currentVersion) {
            //do something
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本有更新" message:[NSString stringWithFormat:@"检测到新版本(%@),是否更新?",version] delegate:self cancelButtonTitle:nil otherButtonTitles:@"更新",nil];
            [alert show];
        }else
        {
        
        }
            
    }];
}

- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //5实现跳转更新
    if(buttonIndex==0)
    {
        //获取下载token 转码生成plist文件,完成下载跳转URL 直接openURL
        NSString * urlString = @"https://download.fir.im/v2/app/install/APPID?download_token=XXX";
        NSString *URLencodeString = CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)urlString, NULL, CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)));
        NSString *installURL = [NSString stringWithFormat:@"itms-services://?action=download-manifest&url=%@", URLencodeString];
        NSURL *openURL = [NSURL URLWithString:installURL];
        [[UIApplication sharedApplication] openURL:openURL];
    }
}



你可能感兴趣的:(fir.im 上企业版IPA版本更新)