美文网首页
fir.im 上企业版IPA版本更新

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

作者: 青砂玥 | 来源:发表于2017-05-12 10:19 被阅读105次
    - (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版本更新

          本文链接:https://www.haomeiwen.com/subject/wrdztxtx.html