iOS appStore中的应用 实现版本升级功能

iOS appStore中的应用 实现升级功能

.h文件中

#import "SBJson.h" //解析sbjson 数据

- (void)viewDidLoad
{
    [super viewDidLoad];
    
      ⋯⋯    
    
    [self checkVersion];   //检测升级

}

.m文件中

#pragma mark - 实现升级功能

//检测软件是否需要升级
-(void)checkVersion
{
    NSString *newVersion;
    NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/cn/lookup?id=692579125"];
    
    //通过url获取数据
    NSString *jsonResponseString =   [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"通过appStore获取的数据是:%@",jsonResponseString);
    
    //解析json数据为数据字典
    NSDictionary *loginAuthenticationResponse = [self dictionaryFromJsonFormatOriginalData:jsonResponseString];
    
    //从数据字典中检出版本号数据
    NSArray *configData = [loginAuthenticationResponse valueForKey:@"results"];
    for(id config in configData) 
    {
        newVersion = [config valueForKey:@"version"];
    }
    
    NSLog(@"通过appStore获取的版本号是:%@",newVersion);
    
    //获取本地软件的版本号
    NSString *localVersion = [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleVersion"];
    
    NSString *msg = [NSString stringWithFormat:@"你当前的版本是V%@,发现新版本V%@,是否下载新版本?",localVersion,newVersion];
    
    //对比发现的新版本和本地的版本
    if ([newVersion floatValue] > [localVersion floatValue])
    {
        UIAlertView *createUserResponseAlert = [[UIAlertView alloc] initWithTitle:@"升级提示!" message:msg delegate:self cancelButtonTitle:@"下次再说" otherButtonTitles: @"现在升级", nil];
        [createUserResponseAlert show];   
        [createUserResponseAlert release];  
    }
}

//响应升级提示按钮
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {  
    //如果选择“现在升级” 
    if (buttonIndex == 1)  
    {  
        //打开iTunes  方法一
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id692579125?mt=8"]];
        
        /*
         // 打开iTunes 方法二:此方法总是提示“无法连接到itunes”,不推荐使用
         NSString *iTunesLink = @"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=692579125&mt=8";  
         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];  
         */
    }  
} 

#pragma mark - 辅助方法:将json 格式的原始数据转解析成数据字典
//将json 格式的原始数据转解析成数据字典
-(NSMutableDictionary *)dictionaryFromJsonFormatOriginalData:(NSString *)str
{
    SBJsonParser *sbJsonParser = [[SBJsonParser alloc]init];
    NSError *error = nil;
    
    //添加autorelease 解决 内存泄漏问题
    NSMutableDictionary *tempDictionary = [[[NSMutableDictionary alloc]initWithDictionary:[sbJsonParser objectWithString:str error:&error]]autorelease];
    return tempDictionary;
}


参考:

//基于企业级证书的IOS应用打包升级功能介绍

http://blog.csdn.net/sbvfhp/article/details/10336715

//另一种代码实现思路

http://hi.baidu.com/wwssttt/item/7446105e3c98fa3933e0a9d5

//向appStore获取软件版本的代码,有步骤

http://blog.csdn.net/wave_1102/article/details/7463697

//向 appstore 查询已发布 APP 的信息--纯思路

http://hi.baidu.com/yanh105/item/7378a98ffca6a8804414cfa0

//官方帮助文档

http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html

//如何改进iOS客户端的升级提醒功能

http://www.cocoachina.com/applenews/devnews/2013/0108/5495.html

//ios项目如何实现版本更新?

http://blog.csdn.net/mad1989/article/details/8130013

//解决向appStore 发送请求获取版本,没有返回信息的问题

http://www.cocoachina.com/ask/questions/show/56158


原文: http://www.cnblogs.com/ygm900/p/3334586.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值