第一步++========在APPdelegate中didfinishilaunch方法中
- (void)setupRootViewController {
//**********************/wofubao//*********************************************
// app版本当前版本
NSDictionary * infoDictionary=[[NSBundle mainBundle] infoDictionary];
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSLog(@"app当前版本----%@",app_Version);
NSString *appStoreVersion=@"1.0.0";
Reachability *reach = [Reachability reachabilityForInternetConnection];
if([reach isReachable]){//网络可用才查询APPstore版本
appStoreVersion=[self getAPPstoreInfo];
NSLog(@"appdelegate有网");
if([appStoreVersion compare:app_Version] ==NSOrderedDescending ){//有新版本就提示引导页
LYGuideloopVC *guideloopvc=[[LYGuideloopVC alloc]init];
self.window.rootViewController=guideloopvc;
}else {
SPLoginViewController *loginVC=[[SPLoginViewController alloc]init];
UINavigationController *loginnav=[[UINavigationController alloc]initWithRootViewController:loginVC];
self.window.rootViewController=loginnav;
}
}else{
SPLoginViewController *loginVC=[[SPLoginViewController alloc]init];
UINavigationController *loginnav=[[UINavigationController alloc]initWithRootViewController:loginVC];
self.window.rootViewController=loginnav;
}
}
//获取App Store版本
-(NSString *)getAPPstoreInfo{
NSString *appID=@"1077712062";//appID---id=1077712062
NSString *idurlStr=[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",appID];
NSURL *url = [NSURL URLWithString:idurlStr];
NSData *json = [NSData dataWithContentsOfURL:url];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:json options:0 error:NULL];//解析json文件
NSArray *results = [dict objectForKey:@"results"];
NSDictionary *result = [results objectAtIndex:0];
NSString *versionStr = [result objectForKey:@"version"];//获得AppStore中的app的版本
NSLog(@"--versionStr-%@__",versionStr);
return versionStr;
}
第二步:在控制器类中:
---
#import "LYBaseVC.h"
@interface LYGuideloopVC : LYBaseVC
@end
====
#import "LYGuideloopVC.h"
#import "Header.h"
#import "Masonry.h"
#import "SPLoginViewController.h"
#define GUIDELOOPCOUNT 3
@interface LYGuideloopVC ()<UIScrollViewDelegate>
@property(nonatomic,strong)NSArray *loopImageArr;
@property(nonatomic,strong)UIScrollView *scroll;
@property(nonatomic,strong)UIPageControl *pageControl;
@end
@implementation LYGuideloopVC
-(NSArray *)loopImageArr{
if(nil==_loopImageArr){
_loopImageArr=@[@"welcome01",@"welcome02",@"welcome03"];
}
return _loopImageArr;
}
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *scroll=[[UIScrollView alloc]initWithFrame:self.view.frame];
self.scroll=scroll;
scroll.delegate=self;
scroll.contentSize=CGSizeMake(GUIDELOOPCOUNT*WIDTH, HEIGHT);
scroll.showsHorizontalScrollIndicator=NO;
scroll.pagingEnabled=YES;
[self.view addSubview:scroll];
for (int i=0; i<GUIDELOOPCOUNT; i++) {
UIImageView *imagV=[[UIImageView alloc]initWithFrame:CGRectMake(i*WIDTH, 0, WIDTH, HEIGHT)];
imagV.image=[UIImage imageNamed:self.loopImageArr[i]];
[scroll addSubview:imagV];
}
[scroll mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.bottom.equalTo(self.view);
}];
UIPageControl *pagecontrol=[[UIPageControl alloc]initWithFrame:CGRectMake(WIDTH/2-50, HEIGHT-130, 100, 50)];
self.pageControl=pagecontrol;
[self.view addSubview:pagecontrol];
//不能自动布局,自动布局后就pagecontrol就不显示
// [pagecontrol mas_makeConstraints:^(MASConstraintMaker *make) {
//
// make.left.right.equalTo(self.view).offset(100);
// make.bottom.equalTo(self.view.mas_bottom).offset(50);
// make.height.mas_equalTo(50);
//
// }];
// 设置总共有几个点
pagecontrol.numberOfPages =GUIDELOOPCOUNT;
// 设置指示器的颜色
// 非当前的指示器
pagecontrol.pageIndicatorTintColor = [UIColor grayColor];
// 设置当前指示器的颜色
pagecontrol.currentPageIndicatorTintColor = [UIColor redColor];
// 设置当前在第几个点 , 取值范围是 0 .. (numberOfPages - 1)
// 设置的currentPage如果超出最大的范围,就在最后一个显示(numberOfPages - 1)
// 设置的currentPage如果超出最小的范围就在第一个显示0
pagecontrol.currentPage =0;
//------添加一个按钮
UIButton *enterBtn=[[UIButton alloc]initWithFrame:CGRectMake(WIDTH-100, 50, 100, 50)];
[enterBtn setTitle:@"进入" forState:UIControlStateNormal];
enterBtn.layer.cornerRadius=5;
enterBtn.layer.borderColor=[UIColor grayColor].CGColor;
enterBtn.layer.borderWidth=1;
[self.view addSubview:enterBtn];
[enterBtn addTarget:self action:@selector(enterBtnClick) forControlEvents:UIControlEventTouchUpInside];
}
//进入应用
-(void)enterBtnClick{
SPLoginViewController *loginvc=[[SPLoginViewController alloc]init];
[UIApplication sharedApplication].delegate.window.rootViewController=loginvc;
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
self.pageControl.currentPage = scrollView.contentOffset.x / WIDTH;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end