如果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];
然后在您的委托实施中:
(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"];