苹果版本跟新的提示

来源:互联网 发布:mgcp对接时默认端口号 编辑:程序博客网 时间:2024/04/27 05:38

static NSString *appid = @"1160216987"; //苹果上架的app id

static NSString *appurl = @"http://itunes.apple.com/lookup?id=%@";

//网络请求

-(void)updatasApp

{

    NSString *appurlStr = [NSStringstringWithFormat:appurl,appid];

    NSURL *url = [NSURLURLWithString:appurlStr];

    

    NSURLRequest *requet = [[NSURLRequestalloc]initWithURL:urlcachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheDatatimeoutInterval:10];

    

    __weakAppDelegate *blockself = self;

    

    [NSURLConnectionsendAsynchronousRequest:requet queue:[NSOperationQueuemainQueue] completionHandler:^(NSURLResponse *_Nullable response, NSData *_Nullable data, NSError *_Nullable connectionError)

     {

         if (connectionError ==nil)

         {

             //这里应该刷新UI

             //1.给数据源数组赋值

             //2,赋值结束之后.刷新UI([self.tableView reloadData])

             NSDictionary *appInfoDict = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingAllowFragmentserror:nil];

             NSArray *resultArray = [appInfoDictobjectForKey:@"results"];

             

             if (resultArray.count )

             {

                 NSDictionary *infoDict = [resultArrayobjectAtIndex:0];

                 NSString *updateVersion = infoDict[@"version"];

                 dispatch_async(dispatch_get_main_queue(), ^{

                     blockself.UpdatesString  = infoDict[@"trackViewUrl"];

                     [blockself getVersion:updateVersion];

                 });

             }

         }

     }];

}


-(void)getVersion:(NSString *)version

{

    NSDictionary *infodic = [[NSBundlemainBundle] infoDictionary];

    NSString *CurrentVersion = [infodicobjectForKey:@"CFBundleShortVersionString"];

//获取本地的版本号

    

    if ([CurrentVersionisEqualToString:version])

    {

    }

    else{

        UIAlertView *alertView = [[UIAlertViewalloc]initWithTitle:@"新版本更新"message:nildelegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"升级",nil];

        alertView.tag =999;

        [alertView show];

    }

}


//判断用户点击了哪一个按钮

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:      (NSInteger)buttonIndex

{

    if (alertView.tag ==999) {

        if (buttonIndex ==1) { //点击升级按钮,就从打开app store上应用的详情页面

            [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:self.UpdatesString]];

        }

    }

}



0 0
原创粉丝点击