2017-03-16 108 views
1

在我的应用我检查在AppStore上的版本的显示器更新正确的消息。
的问题是相同的URL http://itunes.apple.com/lookup?bundleId=my_app_bundle我称之为邮差以及在应用这样的:应用版本不同的响应

- (void)checkForNewVersion 
{ 
    appIsLastVersion = YES; 

    NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier]; 
    NSString *currentAppVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; 

    NSString *appInfoUrl = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", bundleIdentifier]; 

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 
    [request setURL:[NSURL URLWithString:appInfoUrl]]; 
    [request setHTTPMethod:@"GET"]; 

    NSURLSession *sesion = [NSURLSession sharedSession]; 
    NSURLSessionDataTask *task = [sesion dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { 

     NSString *output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 

     NSError *e = nil; 
     NSData *jsonData = [output dataUsingEncoding:NSUTF8StringEncoding]; 
     NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&e]; 

     NSArray *results = [jsonDict objectForKey:@"results"]; 
     if (results.count > 0) { 
      NSString *version = [[[jsonDict objectForKey:@"results"] objectAtIndex:0] objectForKey:@"version"]; 
      appIsLastVersion = [version isEqualToString:currentAppVersion]; 

      [self.tableView reloadData]; 
     } 
    }]; 

    [task resume]; 
} 

我接收上邮差2不同的响应:

"currentVersionReleaseDate": "2017-03-15T23:14:08Z" 
"version": "2.0.1" 

和应用

currentVersionReleaseDate = "2017-03-13T07:37:19Z" 
version = "2.0.0" 

任何解决方案?

+0

对我来说也是这个问题发生。您需要至少等待一天才能让苹果服务器同步您的新应用版本详情。 –

回答

2

好了,主要的原因是,数据高速缓存,所以我改变了NSURLSession

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; 
configuration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData; 

NSURLSession *sesion = [NSURLSession sessionWithConfiguration:configuration]; 

source