app版本更新, 提醒

  /**
     * 
检测版本升级需要用到的参数 , 在appdelegate里边填写
     */
    iFeverAPPID = @"1076057848”; //appId;
//调用检测版本更新的方法
    [self checkVersion];

 *
 * 
检测软件是否需要升级
 */

-(
void)checkVersion
{
   
//获取当前应用版本号
   
NSDictionary *appInfo = [[NSBundle mainBundle] infoDictionary];
   
NSString *currentVersion = [appInfo objectForKey:@"CFBundleVersion"];
   
//  __block才能在局部作用域中改变变量的值
   
__block NSString *newVersion = @"";
   
NSString *updateUrlString = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%ld",(long)[iFeverAPPID integerValue]];
   
   
NSString * str = [updateUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
   
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager
GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
       
NSLog(@"123 + %@", operation);
       
NSDictionary *resultDic = responseObject;
       
NSArray *resultArray = [resultDic objectForKey:@"results"];
       
       
for (id config in resultArray) {
            newVersion = [config
valueForKey:@"version"];
        }
       
if (newVersion) {
           
NSLog(@"通过AppStore获取的版本号是:%@", newVersion);
        }
       
       
if ([newVersion floatValue] > [currentVersion floatValue]) {
           
NSString *versionMessageStr = [NSString stringWithFormat:@"当前版本%@,最新版本为%@,请升级.",currentVersion,newVersion];
           
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"升级提示!" message: versionMessageStr delegate:self cancelButtonTitle:@"下次再说" otherButtonTitles:@"现在升级", nil];
            alert.
tag = kVersionNeedUpdateAlertTag;
            [alert
show];
        }
       
    }
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
       
NSLog(@"234 + %@", error);
    }];
}


#pragma mark - UIAlertDelegate Method
//收到推送时程序正在前台运行,则给出一个alert,用户选择查看,执行这个方法,并且跳转到指定页面
-(
void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   
if (buttonIndex == 1) {
       
//软件需要更新提醒
       
if (alertView.tag == kVersionNeedUpdateAlertTag) {
           
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%@?mt=8",iFeverAPPID]];
            [[UIApplication sharedApplication]openURL:url];
           
        }
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值