启动页加载远程广告的简单实现
来源:互联网 发布:unity3d 2017 新功能 编辑:程序博客网 时间:2024/05/02 17:51
启动页在加载完毕会自动执行AppDelegate didFinishLaunchingWithOptions 函数
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. return YES;}
所以直接将加载广告代码写在这个函数里面就对了:
AppDelegate.m
//// AppDelegate.m// TBTest//// Created by addcn591 on 15/12/30.// Copyright © 2015年 Addcn. All rights reserved.//#import "AppDelegate.h"@interface AppDelegate ()//启动页view@property (strong, nonatomic) UIView *LaunchView;@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. //创建window self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; //获取启动页 UIStoryboard *LaunchScreen = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil]; UIViewController *LaunchVC = [LaunchScreen instantiateInitialViewController]; self.LaunchView = LaunchVC.view; //加载远程广告 [self loadAD]; //设置rootView self.window.rootViewController = LaunchVC; [self.window makeKeyAndVisible]; return YES;}#pragma mark 加载远程广告- (void)loadAD{ //远程图片地址 NSURL *url = [NSURL URLWithString:@"http://images.weiphone.net/attachments/photo/Day_120201/57319_b74b13280821486dc66ef44cea6c5.png"]; //异步加载图片 dispatch_queue_t queue = dispatch_queue_create("loadImage", NULL); dispatch_async(queue, ^{ //图片资源 NSData *imgData = [NSData dataWithContentsOfURL:url]; UIImage *img = [UIImage imageWithData:imgData]; dispatch_async(dispatch_get_main_queue(), ^{ //创建imageView UIImageView *adView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)]; adView.image = img; //添加图片点击手势 UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAD)]; adView.userInteractionEnabled = YES; [adView addGestureRecognizer:singleTap]; [self.LaunchView addSubview:adView]; //LaunchView前置于window [self.window bringSubviewToFront:self.LaunchView]; //延迟5秒后删除广告 [self performSelector:@selector(removeAd) withObject:nil afterDelay:5]; }); });}#pragma mark 广告点击- (void)clickAD { [self removeAd];}#pragma mark 删除广告- (void)removeAd{ [self.LaunchView removeFromSuperview]; //重新设置rootView UIStoryboard *main = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; self.window.rootViewController = [main instantiateInitialViewController]; [self.window makeKeyAndVisible];}- (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end
效果图:
0 0
- 启动页加载远程广告的简单实现
- 启动页上点击广告跳转,退出广告页后返回继续启动的实现方法
- 启动页上点击广告跳转,退出广告页后返回继续启动的实现方法
- ios App启动加载广告页
- iOS-APP启动页加载广告
- 【iOS开发系列】启动页面广告(可实现动态加载)
- 仿网易新闻广告启动页的实现
- iOS 启动页加入动态的广告实现
- 通过设置图片实现app启动广告页的效果
- 启动App的广告页
- App启动时广告的实现
- 垂直自动翻页的广告页简单实现
- 一个屏蔽广告程序的简单实现
- 文中广告简单实现的个人总结
- android 简单的广告条实现
- 实现简单广告轮播的效果
- JavaScript实现简单的广告滚动条
- React Native 启动页广告图预加载
- (求解答)decoder->decode returned false
- 如何在JPA,Hibernate 和 Spring 中配置 Ehcache 缓存
- IntentService解析
- Error:(1, 0) Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRID
- 【iOS笔记】Xcode的基本操作与配置
- 启动页加载远程广告的简单实现
- [Android基础学习]ImageView 图片不拉伸
- PID11 / 计数的梦 这种做法 给跪了
- 多线程之GCD
- 【虫师--系列06】性能测试知多少---响应时间
- IOS SDK详解之拍照/相册(默认+自定义拍照界面)
- hdu 2012
- onNewIntent调用时机
- 基于Linux环境在ARM嵌入式平台快速部署Qt5.4