ios开发之应用程序检查更新功能的实现
2017-09-28 11:11
375 查看
[objc] view
plain copy
前几周,凡是包含了“检查更新”按钮的iOS应用程序均被拒绝上架了,探其原因,发现iOS8之后的系统都可以自动给应用程序升级。大概是苹果方面认为让软件开发商再做一个“检查更新”功能有点多余。不过站在程序员的角度上讲,“检查更新”功能被认为是用户使用次数最少,但偏偏pm们特别钟爱的一个功能。pm非要加,但苹果审核非要拒绝你的app,怎么办呢?其实,苹果现在还没有严苛到不能在程序中出现一丁点和检查更新功能的代码,经过我的大胆尝试,只要不把“检查更新”几个字显示出来就行。那。。。问题来了,没有这个按钮,该如何检查更新呢?傻呀~在app每启动一次,就去检查更新一次不就完了吗?哈哈哈哈,耍个小聪明,成功的将app上线了。
[objc] view
plain copy
#pragma mark 检查更新
-(void)onCheckVersion:(UIButton *)sender
{
_actV.hidden = NO;
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
//CFShow((__bridge CFTypeRef)(infoDic));
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
NSString *URL = @"http://itunes.apple.com/lookup?id=518966501";
// 1. 准备url地址
NSString *urlStr = URL;
NSURL *url = [NSURL URLWithString:urlStr];
// 2. 创建请求对象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
// 2.1 请求方式(默认方式为GET,可不写)
[request setHTTPMethod:@"GET"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
_actV.hidden = YES;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSArray *infoArray = [dic objectForKey:@"results"];
if ([infoArray count]) {
NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
NSString *lastVersion = [releaseInfo objectForKey:@"version"];
// 有新版本
if ([lastVersion compare:currentVersion] > 0) {
// 根据主版本号判断是否需要强制更新
NSMutableString *cur1 = [NSMutableString stringWithString:currentVersion];
NSMutableString *cur2 = [NSMutableString stringWithString:currentVersion];
NSRange range = NSMakeRange(1, 4);
[cur1 deleteCharactersInRange:range];
NSInteger curFirst1 = [cur1 integerValue];
NSRange range3 = NSMakeRange(0, 4);
[cur2 deleteCharactersInRange:range3];
NSInteger curLast = [cur2 intValue];
NSMutableString *last1 = [NSMutableString stringWithString:lastVersion];
NSMutableString *last2 = [NSMutableString stringWithString:lastVersion];
[last1 deleteCharactersInRange:range];
NSInteger lastFirst1 = [last1 integerValue];
[last2 deleteCharactersInRange:range3];
NSInteger lastLast = [last2 integerValue];
// 主版本号更新大于1,强制更新
if (lastFirst1 - curFirst1 >=1 || (curFirst1 == lastFirst1 && curLast != lastLast)) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本更新" message:@"发现新版本,强烈建议您更新到最新版本,否则会影响您的正常使用" delegate:self cancelButtonTitle:@"更新" otherButtonTitles:nil, nil nil];
alert.tag = 100001;
[alert show];
}
// 祝版本号没有更新,不强制更新
else {
//trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"有新的版本更新,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil nil];
alert.tag = 100002;
[alert show];
}
}
// 没有新版本
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"此版本为最新版本" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil nil];
alert.tag = 100003;
[alert show];
}
}
}];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// 强制更新
if (alertView.tag == 100001) {
if (buttonIndex == 0) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/cn/app/id518966501"]];
}
}
// 非强制更新
else if (alertView.tag == 100002) {
if (buttonIndex == 0) {
} else if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/cn/app/lan-bi-tou/id935232659?mt=8"]];
}
}
// 不需要更新
else if (alertView.tag == 100003) {
}
}
plain copy
前几周,凡是包含了“检查更新”按钮的iOS应用程序均被拒绝上架了,探其原因,发现iOS8之后的系统都可以自动给应用程序升级。大概是苹果方面认为让软件开发商再做一个“检查更新”功能有点多余。不过站在程序员的角度上讲,“检查更新”功能被认为是用户使用次数最少,但偏偏pm们特别钟爱的一个功能。pm非要加,但苹果审核非要拒绝你的app,怎么办呢?其实,苹果现在还没有严苛到不能在程序中出现一丁点和检查更新功能的代码,经过我的大胆尝试,只要不把“检查更新”几个字显示出来就行。那。。。问题来了,没有这个按钮,该如何检查更新呢?傻呀~在app每启动一次,就去检查更新一次不就完了吗?哈哈哈哈,耍个小聪明,成功的将app上线了。
[objc] view
plain copy
#pragma mark 检查更新
-(void)onCheckVersion:(UIButton *)sender
{
_actV.hidden = NO;
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
//CFShow((__bridge CFTypeRef)(infoDic));
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
NSString *URL = @"http://itunes.apple.com/lookup?id=518966501";
// 1. 准备url地址
NSString *urlStr = URL;
NSURL *url = [NSURL URLWithString:urlStr];
// 2. 创建请求对象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
// 2.1 请求方式(默认方式为GET,可不写)
[request setHTTPMethod:@"GET"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
_actV.hidden = YES;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSArray *infoArray = [dic objectForKey:@"results"];
if ([infoArray count]) {
NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
NSString *lastVersion = [releaseInfo objectForKey:@"version"];
// 有新版本
if ([lastVersion compare:currentVersion] > 0) {
// 根据主版本号判断是否需要强制更新
NSMutableString *cur1 = [NSMutableString stringWithString:currentVersion];
NSMutableString *cur2 = [NSMutableString stringWithString:currentVersion];
NSRange range = NSMakeRange(1, 4);
[cur1 deleteCharactersInRange:range];
NSInteger curFirst1 = [cur1 integerValue];
NSRange range3 = NSMakeRange(0, 4);
[cur2 deleteCharactersInRange:range3];
NSInteger curLast = [cur2 intValue];
NSMutableString *last1 = [NSMutableString stringWithString:lastVersion];
NSMutableString *last2 = [NSMutableString stringWithString:lastVersion];
[last1 deleteCharactersInRange:range];
NSInteger lastFirst1 = [last1 integerValue];
[last2 deleteCharactersInRange:range3];
NSInteger lastLast = [last2 integerValue];
// 主版本号更新大于1,强制更新
if (lastFirst1 - curFirst1 >=1 || (curFirst1 == lastFirst1 && curLast != lastLast)) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本更新" message:@"发现新版本,强烈建议您更新到最新版本,否则会影响您的正常使用" delegate:self cancelButtonTitle:@"更新" otherButtonTitles:nil, nil nil];
alert.tag = 100001;
[alert show];
}
// 祝版本号没有更新,不强制更新
else {
//trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"有新的版本更新,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil nil];
alert.tag = 100002;
[alert show];
}
}
// 没有新版本
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"此版本为最新版本" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil nil];
alert.tag = 100003;
[alert show];
}
}
}];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// 强制更新
if (alertView.tag == 100001) {
if (buttonIndex == 0) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/cn/app/id518966501"]];
}
}
// 非强制更新
else if (alertView.tag == 100002) {
if (buttonIndex == 0) {
} else if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/cn/app/lan-bi-tou/id935232659?mt=8"]];
}
}
// 不需要更新
else if (alertView.tag == 100003) {
}
}
相关文章推荐
- ios开发之应用程序检查更新功能的实现
- iOS 用其他应用程序打开文件功能如何实现的iOS开发 - CocoaChina CocoaChina_让移动开发更简单
- IOS开发笔记(Swift):利用开源类库实现检测更新功能
- IOS中打开应用实现检查更新的功能
- iOS 6.0开发框架及功能更新小结
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-6-25日更新iap恢复详解】
- iOS 6.0开发框架及功能更新小结
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!2012-6-25日更新iap恢复
- WindowsPhone7开发简单豆瓣网应用程序之主页面功能实现 推荐
- [ios开发]利用有道翻译API实现简单的翻译功能
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-12-11日更新获取”产品付费数量等于0的问题”】
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-12-11日更新获取"产品付费数量等于0的问题"】
- IOS开发 实现电话呼叫功能以及监听电话状态
- 地址方法[ios开发]利用有道翻译API实现简单的翻译功能地址方法
- iOS 开发 初级:应用内实现 更新提醒
- android应用程序更新功能实现
- iOS 6.0开发框架及功能更新小结
- iOS开发_iphone 实现剪贴板操作_iphone 复制粘贴功能(转)
- (iPhone/iPad开发)iOS应用检查更新的最优方法
- (iPhone/iPad开发)在iOS设备上实现摇晃手机体验的相关功能