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

iOS 点击检测版本更新

2015-11-19 10:39 459 查看
//检测版本更新

- (IBAction)banbengengxin:(id)sender {

    

    NSURL *url = [NSURL
URLWithString:@"https://itunes.apple.com/lookup?id=APPID"];

    NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData

                                                      
timeoutInterval:10];

    

    [request setHTTPMethod:@"POST"];

    NSOperationQueue *queue = [NSOperationQueue
new];

    

    [NSURLConnection
sendAsynchronousRequest:request queue:queue
completionHandler:^(NSURLResponse *response,NSData *data,NSError *error){

        if (data) {

            

            NSDictionary *receiveDic = [NSJSONSerialization
JSONObjectWithData:data options:NSJSONReadingMutableLeaves
error:nil];

            if ([[receiveDic
valueForKey:@"resultCount"]
intValue]>0) {

                

                NSString *currentVersion = [[[receiveDic
valueForKey:@"results"]
objectAtIndex:0]
valueForKey:@"version"];

                

                NSString *versionOnPhone = [[[NSBundle
mainBundle] infoDictionary]
objectForKey:@"CFBundleShortVersionString"];     
//获取项目版本号

            

                

                if (![versionOnPhone
isEqualToString:currentVersion]) {

                    

                    UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"提醒"

                                                                                  
message:@"有新的版本更新,是否前往下载。"
preferredStyle:UIAlertControllerStyleAlert];

                    UIAlertAction *doAction = [UIAlertAction
actionWithTitle:@"确定"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *
_Nonnull action) {

                        NSString *str = [NSString
stringWithFormat:@"itms-apps://itunes.apple.com/app/idAPPID"];

                        [[UIApplication
sharedApplication] openURL:[NSURL
URLWithString:str]];

                        

                    }];

                    UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:@"取消"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *
_Nonnull action) { }];

                    [alert addAction:doAction];

                    [alert addAction:cancelAction];

                    [self
presentViewController:alert animated:YES
completion:^{

                        

                    }];

                    

                }

                else

                {

                    UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"提醒"
message:@"已是最新版本"
preferredStyle:UIAlertControllerStyleAlert];

                    UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:@"取消"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {

                    }];

                    [alert addAction:cancelAction];

                    [self
presentViewController:alert animated:YES
completion:^{

                        

                    }];

                }

            }

            

        }

        

    }];

    

}

卸载点击事件里就行了 上边是判断版本号 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 检测版本更新