//
这一步是获取
LaunchScreen.storyboard
里的
UIViewController,UIViewController
的
identifer
是
LaunchScreen
UIViewController *viewController = [[ UIStoryboard storyboardWithName : @"LaunchScreen" bundle :[ NSBundle mainBundle ]] instantiateViewControllerWithIdentifier : @"LaunchScreen" ];
UIView *launchView = viewController. view ;
UIImageView * Imageview= [[ UIImageView alloc ] initWithFrame :[ UIScreen mainScreen ]. bounds ];
[launchView addSubview :Imageview];
[ self . view addSubview :launchView];
// 这一步是获取上次网络请求下来的图片,如果存在就展示该图片,如果不存在就展示本地保存的名为 test 的图片
NSMutableData * data = [[ NSUserDefaults standardUserDefaults ] objectForKey : @"imageu" ];
if (data. length > 0 ) {
Imageview. image = [ UIImage imageWithData :data];
} else {
Imageview. image = [ UIImage imageNamed : @"Test" ];
}
// 下面这段代码,是调用 AFN 下载文件的方法,异步
NSURLSessionConfiguration *configuration = [ NSURLSessionConfiguration defaultSessionConfiguration ];
AFURLSessionManager *manager = [[ AFURLSessionManager alloc ] initWithSessionConfiguration :configuration];
NSURL *URL = [ NSURL URLWithString : @"http://s16.sinaimg.cn/large/005vePOgzy70Rd3a9pJdf&690" ];
NSURLRequest *request = [ NSURLRequest requestWithURL :URL];
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest :request progress : nil destination :^ NSURL *( NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryURL = [[ NSFileManager defaultManager ] URLForDirectory : NSDocumentDirectory inDomain : NSUserDomainMask appropriateForURL : nil create : NO error : nil ];
return [documentsDirectoryURL URLByAppendingPathComponent :[response suggestedFilename ]];
} completionHandler :^( NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog ( @"File downloaded to: %@" , filePath);
NSData * image = [ NSData dataWithContentsOfURL :filePath];
[[ NSUserDefaults standardUserDefaults ] setObject :image forKey : @"imageu" ];
}];
[downloadTask resume ];
// 这段代码,可以实现第二张图片有 3D 的动画效果,动画结束后,进行同步的网络请求,请求的是广告页图片
[ UIView animateWithDuration :3 .0f delay : 0.0f options : UIViewAnimationOptionBeginFromCurrentState animations :^{
//launchView.alpha = 0.0f;
launchView. layer . transform = CATransform3DScale ( CATransform3DIdentity , 1.5f , 1.5f , 1.0f );
} completion :^( BOOL finished) {
NSString * ad_imgUrl = @"http://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E5%9B%BE%E7%89%87&pn=0&spn=0&di=125546894880&pi=&rn=1&tn=baiduimagedetail&ie=utf-8&oe=utf-8&cl=2&lm=-1&cs=1003704465%2C1400426357&os=4246966059%2C4277404619&simid=4210997991%2C798394471&adpicid=0&ln=30&fr=ala&fm=&sme=&cg=&bdtype=0&oriquery=&objurl=http%3A%2F%2Fpic25.nipic.com%2F20121112%2F5955207_224247025000_2.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bgtrtv_z%26e3Bv54AzdH3Ffi5oAzdH3FnAzdH3F0nAzdH3F0al8l0mhdj9v1c9n_z%26e3Bip4s&gsm=0" ;
AppDelegate *appDelegate = ( AppDelegate *)[[ UIApplication sharedApplication ] delegate ];
[ BBLaunchAdMonitor showAdAtPath :ad_imgUrl
onView :appDelegate. window . rootViewController . view
timeInterval : 5
detailParameters : @{ @"carId" : @(0001) , @"name" : @" 0007 " } ];
[launchView removeFromSuperview ];
UIViewController *viewController = [[ UIStoryboard storyboardWithName : @"LaunchScreen" bundle :[ NSBundle mainBundle ]] instantiateViewControllerWithIdentifier : @"LaunchScreen" ];
UIView *launchView = viewController. view ;
UIImageView * Imageview= [[ UIImageView alloc ] initWithFrame :[ UIScreen mainScreen ]. bounds ];
[launchView addSubview :Imageview];
[ self . view addSubview :launchView];
// 这一步是获取上次网络请求下来的图片,如果存在就展示该图片,如果不存在就展示本地保存的名为 test 的图片
NSMutableData * data = [[ NSUserDefaults standardUserDefaults ] objectForKey : @"imageu" ];
if (data. length > 0 ) {
Imageview. image = [ UIImage imageWithData :data];
} else {
Imageview. image = [ UIImage imageNamed : @"Test" ];
}
// 下面这段代码,是调用 AFN 下载文件的方法,异步
NSURLSessionConfiguration *configuration = [ NSURLSessionConfiguration defaultSessionConfiguration ];
AFURLSessionManager *manager = [[ AFURLSessionManager alloc ] initWithSessionConfiguration :configuration];
NSURL *URL = [ NSURL URLWithString : @"http://s16.sinaimg.cn/large/005vePOgzy70Rd3a9pJdf&690" ];
NSURLRequest *request = [ NSURLRequest requestWithURL :URL];
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest :request progress : nil destination :^ NSURL *( NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryURL = [[ NSFileManager defaultManager ] URLForDirectory : NSDocumentDirectory inDomain : NSUserDomainMask appropriateForURL : nil create : NO error : nil ];
return [documentsDirectoryURL URLByAppendingPathComponent :[response suggestedFilename ]];
} completionHandler :^( NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog ( @"File downloaded to: %@" , filePath);
NSData * image = [ NSData dataWithContentsOfURL :filePath];
[[ NSUserDefaults standardUserDefaults ] setObject :image forKey : @"imageu" ];
}];
[downloadTask resume ];
// 这段代码,可以实现第二张图片有 3D 的动画效果,动画结束后,进行同步的网络请求,请求的是广告页图片
[ UIView animateWithDuration :3 .0f delay : 0.0f options : UIViewAnimationOptionBeginFromCurrentState animations :^{
//launchView.alpha = 0.0f;
launchView. layer . transform = CATransform3DScale ( CATransform3DIdentity , 1.5f , 1.5f , 1.0f );
} completion :^( BOOL finished) {
NSString * ad_imgUrl = @"http://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E5%9B%BE%E7%89%87&pn=0&spn=0&di=125546894880&pi=&rn=1&tn=baiduimagedetail&ie=utf-8&oe=utf-8&cl=2&lm=-1&cs=1003704465%2C1400426357&os=4246966059%2C4277404619&simid=4210997991%2C798394471&adpicid=0&ln=30&fr=ala&fm=&sme=&cg=&bdtype=0&oriquery=&objurl=http%3A%2F%2Fpic25.nipic.com%2F20121112%2F5955207_224247025000_2.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bgtrtv_z%26e3Bv54AzdH3Ffi5oAzdH3FnAzdH3F0nAzdH3F0al8l0mhdj9v1c9n_z%26e3Bip4s&gsm=0" ;
AppDelegate *appDelegate = ( AppDelegate *)[[ UIApplication sharedApplication ] delegate ];
[ BBLaunchAdMonitor showAdAtPath :ad_imgUrl
onView :appDelegate. window . rootViewController . view
timeInterval : 5
detailParameters : @{ @"carId" : @(0001) , @"name" : @" 0007 " } ];
[launchView removeFromSuperview ];
}];