如果iOS SDK没有这方面的功能,那么如果我有一个基本(静态)网站,并且在该网站的某个地方我手动设置一段数据,每次在应用商店中指定我的应用程序的最新版本,该怎么办?我发布了更新?如何让我的应用程序在网站上查询该版本数据并根据iOS设备上运行的版本进行检查?
Red*_*ing 12
你走在正确的轨道上.您需要向静态版本网页发出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];
Run Code Online (Sandbox Code Playgroud)
然后在你的委托实现中:
(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
}
Run Code Online (Sandbox Code Playgroud)
因此,在您的connectionDidFinishLoading中,您可以查看已收集的mData.解析版本号并将其与您的软件包版本号进行比较:
[self infoValueForKey:@"CFBundleVersion"];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4852 次 |
| 最近记录: |