检查版本并去app store更新app

2019-07-02  本文已影响0人  小y想吃糖

检查应用

- (void)___checkVersion {

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?id=%@",k_app_store_app_id]] encoding:NSUTF8StringEncoding error:nil];

        NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];

        if(![dataisKindOfClass:[NSDataclass]] || !data) {

            return;

        }

        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data  options:NSJSONReadingMutableLeaves error:nil];

        /*

         "resultCount":0,

         "results": []

         */

        //获得上线版本号

        NSString *newVersion = [[[dic objectForKey:@"results"] firstObject] objectForKey:@"version"];

        NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];

        if(![newVersionisEqualToString:currentVersion]) {

            [self ___showTipForVersion];

        }

    });

    [self ___jumpToAppStore];

}

- (void)___showTipForVersion {

}

- (void)___jumpToAppStore {

    NSString *urlStr = [[NSString alloc] initWithFormat:@"https://itunes.apple.com/lookup?id=%@",k_app_store_app_id];

    NSURL* url = [NSURLURLWithString:urlStr];

    [[UIApplication sharedApplication] openURL:url];

}

上一篇 下一篇

猜你喜欢

热点阅读