直接写代码
#import "AppDelegate.h"
#import "WSMovieController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *versionCache = [[NSUserDefaults standardUserDefaults] objectForKey:@"VersionCache"];//本地缓存的版本号 第一次启动的时候本地是没有缓存版本号的。
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];//当前应用版本号
if (![versionCache isEqualToString:version]) //如果本地缓存的版本号和当前应用版本号不一样,则是第一次启动(更新版本也算第一次启动)
{
WSMovieController *wsCtrl = [[WSMovieController alloc]init];
wsCtrl.movieURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"qidong"ofType:@"mp4"]];//选择本地的视屏
self.window.rootViewController = wsCtrl;
//设置上下面这句话,将当前版本缓存到本地,下次对比一样,就不走启动视屏了。
//也可以将这句话放在WSMovieController.m的进入应用方法里面
//为了让每次都可以看到启动视屏,这句话先注释掉
//[[NSUserDefaults standardUserDefaults] setObject:version forKey:@"VersionCache"];
}else{
//不是首次启动
RootTabBarController *rootTabCtrl = [[RootTabBarController alloc]init];
self.window.rootViewController = rootTabCtrl;
}
return YES;
}
#import <UIKit/UIKit.h>
@interface WSMovieController : UIViewController
@property(nonatomic,strong)NSURL *movieURL;
@end
#import "WSMovieController.h"
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import <AVKit/AVKit.h>
#import "RootTabBarController.h"
@interface WSMovieController ()
@property (strong, nonatomic) MPMoviePlayerController *player;
@end
@implementation WSMovieController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self SetupVideoPlayer];
}
- (void)SetupVideoPlayer
{
self.player = [[MPMoviePlayerController alloc] initWithContentURL:_movieURL];
[self.view addSubview:self.player.view];
self.player.shouldAutoplay = YES;
[self.player setControlStyle:MPMovieControlStyleNone];
self.player.repeatMode = MPMovieRepeatModeOne;
[self.player.view setFrame:[UIScreen mainScreen].bounds];
self.player.view.alpha = 0;
[UIView animateWithDuration:3 animations:^{
self.player.view.alpha = 1;
[self.player prepareToPlay];
}];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackStateChanged) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
[self setupLoginView];
}
- (void)setupLoginView
{
//进入按钮
UIButton *enterMainButton = [[UIButton alloc] init];
enterMainButton.frame = CGRectMake(24, [UIScreen mainScreen].bounds.size.height - 32 - 48, [UIScreen mainScreen].bounds.size.width - 48, 48);
enterMainButton.layer.borderWidth = 1;
enterMainButton.layer.cornerRadius = 24;
enterMainButton.layer.borderColor = [UIColor whiteColor].CGColor;
[enterMainButton setTitle:@"进入应用" forState:UIControlStateNormal];
enterMainButton.alpha = 0;
[self.player.view addSubview:enterMainButton];
[enterMainButton addTarget:self action:@selector(enterMainAction:) forControlEvents:UIControlEventTouchUpInside];
[UIView animateWithDuration:3.0 animations:^{
enterMainButton.alpha = 1.0;
}];
}
#pragma mark - NSNotificationCenter
- (void)playbackStateChanged
{
MPMoviePlaybackState playbackState = [self.player playbackState];
if (playbackState == MPMoviePlaybackStateStopped || playbackState == MPMoviePlaybackStatePaused) {
[self.player play];
}
}
- (void)enterMainAction:(UIButton *)btn {
NSLog(@"进入应用");
RootTabBarController *rootTabCtrl = [[RootTabBarController alloc]init];
self.view.window.rootViewController = rootTabCtrl;
}
@end