iOS 강제 버전 업데이트

2522 단어

버전 강제 업데이트

NSString *url = UPDATEVERSION(@"0");
    [BaseRequest be_baseRequestModel:nil url:url finishBlock:^(id responseObject, NSError *error) {
        if ([responseObject[@"status"] integerValue] == 200) {
            if ([responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
                NSDictionary *dataDic = responseObject[@"data"];
                int backgroundVerison ;
                if ([dataDic[@"version"] isKindOfClass:[NSNull class]]) {
                    backgroundVerison = 100;
                }else {
                    // 
                    backgroundVerison = [self versionExchangeType:dataDic[@"version"]];
                }
                // url
                _updateUrl = dataDic[@"url"];
                // 
                int localVersion = [self versionExchangeType:[self getSystemVersion]];
                // 
                if ( localVersion< backgroundVerison) {
                    NSLog(@" :%@",dataDic[@"version"]);
                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@" " message:@" " delegate:self cancelButtonTitle:@" " otherButtonTitles:nil, nil];
                    alertView.tag = 100;
                    [alertView show];
                }else {
                    NSLog(@" 。。");
                }
            }
        }
    }];

// 
- (NSString *)getSystemVersion {
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    return currentVersion;
}
// 
- (int)versionExchangeType:(NSString *)version {
    
    //modify dingyouyou 2017-05-06
    NSArray * subArr = [version componentsSeparatedByString:@"."];
    if (subArr.count > 0) {
        NSString * value = @"";
        for (int i = 0; i< subArr.count;i++ ) {
            value = [value stringByAppendingString:subArr[i]];
        }
        return value.intValue;
    }else{
        return 0;
    }
}

강제 업데이트는 앱이 프론트에 들어갈 때 다시 네트워크 요청을 호출하는 방법입니다
- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    // 
    [self checkVerisonRequest];
}

좋은 웹페이지 즐겨찾기