如果 iOS SDK 没有这方面的功能,那么如果我有一个基本(静态)网站,并且在该网站的某处我手动设置了一条数据,用于在应用程序中指定我的应用程序的最新版本每次我发布更新时存储?如何让我的应用在网站上查询该版本数据并将其与 iOS 设备上运行的版本进行核对?
最佳答案
您走在正确的轨道上。您需要向静态版本网页发出 HTTP 请求。为此,您可以使用 NSURLConnection目的。所以像这样:
NSURL * url = [NSURL URLWithString:@"http://yourweb.com/version.txt"];
NSURLRequest * request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60];
_connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
然后在您的委托(delegate)实现中:
(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSHTTPURLResponse*)response
{
if(response.statusCode != 200)
// you got an error
}
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
{
// again with the errors ...
}
// you got some data ... append it to your chunk
// in your case all the data should come back in one callback
- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data
{
[mData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// your request finished ... check the version here
}
因此,在您的 connectionDidFinishLoading 中,您可以查看已收集的 mData。解析版本号并将其与您的包版本号进行比较:
[self infoValueForKey:@"CFBundleVersion"];
关于iphone - 将应用程序的当前版本与应用程序商店中的最新版本进行比较的最简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4674588/