美文网首页
App 内更新提醒

App 内更新提醒

作者: zwing | 来源:发表于2020-10-20 17:39 被阅读0次
- (void)checkUpdateVersion {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSString *url = @"https://itunes.apple.com/lookup?id=yourAppleId";
    NSString *encodingUrl = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [manager GET:encodingUrl parameters:nil headers:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *resultDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        // App Store最新版本号
        NSString *latestVersion = resultDict[@"results"][0][@"version"];
        
        // 本地当前版本号
        NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
        
        NSString *latestVersionInt = [latestVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
        NSString *currentVersionInt = [currentVersion stringByReplacingOccurrencesOfString:@"." withString:@""];

        if (latestVersionInt.integerValue > currentVersionInt.integerValue) {
            // 弹出更新弹框
        }

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
}

相关文章

网友评论

      本文标题:App 内更新提醒

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