IOS实现开机启动欢迎页广告倒计时源代码

本文介绍了如何在iOS应用启动时显示欢迎页广告,并实现倒计时功能。通过在AppDelegate中检查本地图片是否存在,如果存在则展示带有倒计时的广告页面,否则从网络加载图片。代码示例中使用了WCImageView类和KKProgressTimer类,分别用于显示广告和倒计时。WCImageView类会监听KKProgressTimer的进度更新并关闭广告页面。
摘要由CSDN通过智能技术生成

@implementation AppDelegate的 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions


NSString * documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];


        UIImage * imageFromWeb = [self loadImage:@"MyImage" ofType:@"jpg" inDirectory:documentsDirectoryPath];

                               

        if (imageFromWeb) {

            WCImageView *imageV = [[WCImageView alloc] initWithFrame:self.window.frame];

            imageV.image = imageFromWeb;

            [imageV startShowingPage];

        }

        else {

            [WCImageView loadingImageDataFromWeb];

            

        }

其中方法:

-(UIImage *) loadImage:(NSString *)fileName ofType:(NSString *)extension inDirectory:(NSString *)directoryPath {

    UIImage * result = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.%@", directoryPath, fileName, extension]];

    

    return result;

}



WCImageView类实现:


#import <UIKit/UIKit.h>

#import "KKProgressTimer.h"


@interface WCImageView : UIImageView <KKProgressTimerDelegate>


- (void)startShowingPage;

+ (void)loadingImageDataFromWeb;


@end



#import "WCImageView.h"

#import "MFService.h"

#import "Utilities.h"

#import "UIColor+extend.h"


#define DEFAULT_TIMEROUT 4.f

static UIWindow *__sheetWindow = nil;

@implementation WCImageView

{

    KKProgressTimer *timer1;

}

- (id)initWithFrame:(CGRect)frame {

    if (self = [super initWithFrame:frame]) {

        

    }

    return self;

}


#pragma mark - PUBLIC METHODS

- (void)startShowingPage {

    [self addWindowAction];

}


+ (void)loadingImageDataFromWeb {

    NSString *timestamp = [Utilities getTimestamp];

    

    NSDictionary *paramters = @{ @"spid":SPID, @"timestamp":timestamp,

                                @"hash":[Utilities getHash:timestamp],

                                @"citycode":@""};

    

    NSDictionary *serviceDict = [[MFServiceList manager] queryActionWithId:NO_18_queryPageThemes];

    MFService *service = [[MFService alloc] initWithDataDictionary:serviceDict];

    [service queryWith:paramters success:^(id result) {

        

        NSDictionary *dict = (NSDictionary *)result;

        NSDictionary *data = dict[@"data"];

        NSDi

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值