iOS檢查更新

#pragma -mark  檢查更新

-(void)CheckVersionUpdate

{

    

    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];

    

    NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];

    

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    

    //設置 響應解析對象

    manager.responseSerializer = [AFHTTPResponseSerializer serializer];

    //設置數據 支持類型

    [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/css", @"text/plain",@"application/x-javascript", nil]];

    

    

    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];

    

    //接口地址  1038827292

    NSString *url = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", AppVeision];

    //發送請求

    [manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

        

        

        NSData *data = operation.responseObject;

        

        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

        

        NSArray *infoArray = [dic objectForKey:@"results"];

        

        if ([infoArray count]) {

            

            NSDictionary *releaseInfo = [infoArray objectAtIndex:0];

            

            NSString *lastVersion = [releaseInfo objectForKey:@"version"];

//            NSLog(@"77777777777版本更新 ====== %@",lastVersion);

            if (![lastVersion isEqualToString:currentVersion]) {

                

                //trackViewURL = [releaseInfo objectForKey:@trackVireUrl];

                

                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"有新的版本更新,是否前往更新?" delegate:self cancelButtonTitle:@"關閉" otherButtonTitles:@"更新", nil];

                

                alert.tag = 10000;

                

                [alert show];

                

            }

            

        }

        

        

        

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        

        NSLog(@"Error: %@", error);

        

        

    }];


發佈了49 篇原創文章 · 獲贊 2 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章