0711日记

好久没写日志了

1、导航颜色

设置导航栏颜色是常用到这个方法,但会修改不了

- (UIStatusBarStyle)preferredStatusBarStyle {    
    return UIStatusBarStyleLightContent;
}

这个时候设置navigationBar的BarStyle属性就妥妥的可以了

[self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
2、版本检查

版本检查提示更新主要用于重大更新,小版本的更新App Store会帮我们自动更新;版本检查的方式有两种,一种是在自己的服务器上方一个版本号,通过每次获取该版本号与当前安装版本号对比,这种就比较自主一点,但也相对麻烦一点,第二种是获取App Store上的版本号与当前进行比较,这种方法就较为简单,但是定制性就较差,而且审核时间不确定,不太好控制,我这儿主要使用的是第二种方法。
获取当前安装的版本

    // app版本 获取
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];

获取App Store版本号

  NSString *path = [NSString stringWithFormat:@"https://itunes.apple.com/lookup?id=%@",@"应用的id"];
    NSURL *url = [NSURL URLWithString:path];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
                                                           cachePolicy:NSURLRequestReloadIgnoringCacheData
                                                       timeoutInterval:10];

    [request setHTTPMethod:@"POST"];

    NSOperationQueue *queue = [NSOperationQueue new];

    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response,NSData *data,NSError *error){
        NSMutableDictionary *receiveStatusDic=[[NSMutableDictionary alloc]init];
        if (data) {

            NSDictionary *receiveDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
            if ([[receiveDic valueForKey:@"resultCount"] intValue] > 0) {

                [receiveStatusDic setValue:@"1" forKey:@"status"];
                [receiveStatusDic setValue:[[[receiveDic valueForKey:@"results"] objectAtIndex:0] valueForKey:@"version"]   forKey:@"version"];
            }else{

                [receiveStatusDic setValue:@"-1" forKey:@"status"];
            }
        }else{
            [receiveStatusDic setValue:@"-1" forKey:@"status"];
        }

        [self performSelectorOnMainThread:@selector(receiveData:) withObject:receiveStatusDic waitUntilDone:NO];
    }];

进行版本对比

-(void)receiveData:(id)sender{
    //最新版本(线上版本)
    NSString  *Newversion = [NSString stringWithFormat:@"%@",sender[@"version"]];
    NSInteger newVersion = [[Newversion stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
    //手机版本
    NSInteger appVersion = [[_app_Version stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
    //如果线上的版本大于当前安装版本  那就提示更新
    if (newVersion > appVersion) {

        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"更新提示" message:@"发现新版本,是否更新 ?" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *download = [UIAlertAction actionWithTitle:@"立即更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:DOWNLOAD_URL] options:@{} completionHandler:^(BOOL success) {
                
            }];
        }];
        
        [alertVC addAction:cancel];
        [alertVC addAction:download];
        [self presentViewController:alertVC animated:YES completion:nil];
    }
}

这个东西要是被审核员看到那你这次提交的版本基本算是跪了

你可能感兴趣的:(0711日记)