您的位置:首页 > 移动开发

app版本更新, 提醒

2016-02-23 15:43 260 查看
 /**

     * 
检测版本升级需要用到的参数 , 在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];

           

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios开发