0

I have a version checker inside my app and I have the current version number stored in a plist on the server. For some reason it keeps returning the old value when I have confirmed that it is 1.21 when it keeps saying 1.2. I believe it's some sort of caching as my browsers do the same thing.

How do I prevent this from happening? I set the cachePolicy to NSURLRequestReloadIgnoringCacheData, but it's still returning 1.2 when it's 1.21

NSURL *url = [NSURL URLWithString:@"https://somewebsite.com/iosapp/CurrentVersion.plist"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.cachePolicy = NSURLRequestReloadIgnoringCacheData;

[request setHTTPMethod:@"GET"];

[AFPropertyListRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/xml"]];
AFPropertyListRequestOperation *operation = [AFPropertyListRequestOperation propertyListRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id propertyList) {
    NSString *currentVersion = [[[NSArray alloc] initWithArray:propertyList] objectAtIndex:0];
    NSLog(@"Current Version %@", currentVersion);
    NSString *deviceVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
    if (![currentVersion isEqualToString:deviceVersion]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Update Available" message:[NSString stringWithFormat:@"App %@ is available. Please update.", currentVersion] delegate:self cancelButtonTitle:@"Later" otherButtonTitles:@"Update", nil];
        [alert show];
    }


    [self finalCheck];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id propertyList) {
    [self finalCheck];
}];
4

1 回答 1

1

AFPropertyListRequestOperation的实现不做任何与缓存相关的事情。这里有几个选项:

  1. 代理或中介可能正在缓存它。试试NSURLRequestReloadIgnoringLocalAndRemoteCacheData吧。
  2. 对的响应[[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"]可能不是您所期望的(我注意到您没有记录它。)

我还想建议您查看两个库:

  • Harpy是一个易于添加、维护成本低的库,它使用 iTunes API 检查最新版本,并以您指定的时间间隔唠叨您的用户。
  • Ground Control是 NSUserDefaults 上的一个简单类别,它异步下载、读取和保存远程 plist 文件。

第一个将避免您编写任何此代码的需要。如果您需要更多控制/自定义,第二个会更容易。

于 2013-08-30T00:17:35.327 回答