我的应用程序中有一个版本检查器,我将当前版本号存储在服务器上的plist中。出于某种原因,当我确认它是1.21时,当它一直说1.2时,它会一直返回旧的值。我相信它是某种缓存,因为我的浏览器做同样的事情。
如何防止这种情况发生?我将cachePolicy设置为NSURLRequestReloadIgnoringCacheData
,但当它为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];
}];
答案 0 :(得分:1)
implementation of AFPropertyListRequestOperation不会执行与缓存相关的任何操作。以下是一些选项:
NSURLRequestReloadIgnoringLocalAndRemoteCacheData
。[[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"]
的回复可能不是您所期望的(我注意到您没有记录它。)我还建议您查看两个库:
第一个将绕过你编写任何代码的需要。如果你需要更多的控制/定制,第二个将更容易。