国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

iOS開發(fā)之檢查更新

2019-11-14 18:38:02
字體:
供稿:網(wǎng)友

iOS開發(fā)之檢查更新

#PRagma mark - 檢查更新

- (void)checkUpdateWithAPPID:(NSString *)APPID
{
    //獲取當(dāng)前應(yīng)用版本號
    NSDictionary *appInfo = [[NSBundle mainBundle] infoDictionary];    
    NSString *currentVersion = [appInfo objectForKey:@"CFBundleVersion"];
     
    NSString *updateUrlString = [NSString stringWithFormat:@",APPID];
     
    //loading view
    CustomAlertView *checkingAlertView = [[CustomAlertView alloc] initWithFrame:NAVIGATION_FRAME style:CustomAlertViewStyleDefault noticeText:@"正在檢查更新..."];
    checkingAlertView.userInteractionEnabled = YES;
    [self.navigationController.view addSubview:checkingAlertView];
    [checkingAlertView release];
     
    [versionRequest setCompletionBlock:^{
         
        [checkingAlertView removeFromSuperview];
         
        NSError *error = nil;
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[versionRequest responseData] options:NSJSONReadingMutableContainers error:&error];
        if (!error) {
            if (dict != nil) {
                //            DLog(@"dict %@",dict);
                int resultCount = [[dict objectForKey:@"resultCount"] integerValue];
                if (resultCount == 1) {
                    NSArray *resultArray = [dict objectForKey:@"results"];
                    //                DLog(@"version %@",[resultArray objectAtIndex:0]);
                    NSDictionary *resultDict = [resultArray objectAtIndex:0];
                    //                DLog(@"version is %@",[resultDict objectForKey:@"version"]);
                    NSString *newVersion = [resultDict objectForKey:@"version"];
                     
                    if ([newVersion doubleValue] > [currentVersion doubleValue]) {
                        NSString *msg = [NSString stringWithFormat:@"最新版本為%@,是否更新?",newVersion];
                        newVersionURlString = [[resultDict objectForKey:@"trackViewUrl"copy];
                        DLog(@"newVersionUrl is %@",newVersionURlString);
                        //                    if ([newVersionURlString hasprefix:@"https"]) {
                        //                         [newVersionURlString replaceCharactersInRange:NSMakeRange(0, 5) withString:@"itms-apps"];
                        //                    }
                        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"暫不" otherButtonTitles:@"立即更新"nil];
                        alertView.tag = 1000;
                        [alertView show];
                        [alertView release];
                    }else
                    {
                        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您使用的是最新版本!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"確定"nil];
                        alertView.tag = 1001;
                        [alertView show];
                        [alertView release];
                    }
                }
            }
        }else
        {
            DLog("error is %@",[error debugDescription]);
        }
    }];
     
    [versionRequest setFailedBlock:^{
        [checkingAlertView removeFromSuperview];
         
        CustomAlertView *alertView = [[CustomAlertView alloc] initWithFrame:NAVIGATION_FRAME style:CustomAlertViewStyleWarning noticeText:@"操作失敗,請稍候再試!"];
        [self.navigationController.view addSubview:alertView];
        [alertView release];
        [alertView selfRemoveFromSuperviewAfterSeconds:1.0];
    }];
     
    [versionRequest startSynchronous];  
}
 
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    DLog(@"newVersionUrl  is %@",newVersionURlString);
    if (buttonIndex) {
        if (alertView.tag == 1000) {
            if(newVersionURlString)
            {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:newVersionURlString]];
            }
        }
    }
}

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 香港 | 南皮县| 卓尼县| 沐川县| 靖宇县| 天水市| 平山县| 绥江县| 沂南县| 内江市| 尼勒克县| 汶川县| 噶尔县| 卓资县| 滨海县| 东阳市| 云和县| 广宗县| SHOW| 商洛市| 彩票| 连江县| 桃源县| 巨鹿县| 伊金霍洛旗| 胶南市| 剑河县| 临清市| 贺州市| 鄂温| 承德县| 霍州市| 合川市| 和硕县| 廊坊市| 莱阳市| 深泽县| 盐城市| 屏山县| 长白| 荣昌县|