NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"http://dn-xxxxxxxxx/HappyFaie-iphone.plist"]];
NSArray* list = [dict objectForKey:@"items"];
NSDictionary* dict2 = [list objectAtIndex:0];
NSDictionary* dict3 = [dict2 objectForKey:@"metadata"];
NSString* newVersion = [dict3 objectForKey:@"bundle-version"];
NSString *myVersion = [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]];
NSLog(@"版本号%@=====%@",newVersion,myVersion);
if (![newVersion isEqualToString:myVersion]) {
UIAlertView * aler = [[UIAlertView alloc] initWithTitle:@"提示" message:@"发现新版本,是否更新?" delegate:self cancelButtonTitle:@"立即更新" otherButtonTitles:@"暂不更新", nil];
[aler show];
}
我用这段代码获取的版本号 有时候跟写在文件里的值不一样,请问有大神知道是为什么吗?
这个有可能是cdn缓存,导致了你访问到的文件仍然是旧的文件,所以获取的版本号会是原来文件的版本号,你可以到空间设置的高级设置中,将新资源的url刷新一下。