iOS-插入广告-InMobi使用教程

由于苹果停止iAd,目前最方便的只有用InMobi了
教程如下:

网页部分

首先,你要能翻墙,方式不赘述,我用到Lantern,每月免费500M,基本够用。
InMobi官网看着像中国本地化了,但是注册不知道为什么收不到验证码,坑爹呢。但是下载sdk没问题(关于sdk,你pod也可以下载也可以,看你自己喜好啦,由于我不太喜欢pod所以下载的sdk,如有反感可以点x了)。我用的google账号登录的,实在不行自己去注册一个Google账号。
填写完毕之后按照引导,创建完你的app,一般来说新应用添加广告应该都还没上架,这里要写上你的app名称,上架的填你app的url就行了。这个时候上面有一排字,让你填信息的,有两个,第一个个人信息,第二个就是关键之处,银行卡信息(银行swift code传送门)。

强烈建议使用banner(横幅)模式要不然很恶心

这个时候,要记得复制两个东西出来备用:

位置ID,如下图

先点这里

1

复制红条位置的位置ID

2

(如果有多个我也不知道该怎么用,你先复制下来再说呗,应该就是每个bannerView对应一个位置ID,反正我是这样的,而且两个分开计费)

你账号的ID

3

这两个ID复制备用,然后就可以来到Xcode里了。


Xcode部分

首先,导入sdk。右键项目,add files to..选择这个玩意儿。
InMobiSDK.framework

4

记得选择copy,确定。

然后在Build phases的Link Binary…中 还需要添加下面两个库

5

Info里面添加两个key,如下
1
6
2(这个主要是需要根据地理位置获得广告信息的,我用的时候没有提示,随便写值就好了)
7

接下来进入主题,使用。

在AppDelegate.h中:

@import InMobiSDK;

AppDelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [IMSdk initWithAccountID:@"刚刚复制下来的你的accountID"];
    return YES;
}

创建广告(以banner为例)
同样,在你需要添加广告的Controller中先导入sdk

@import InMobiSDK;

添加delegate

<IMBannerDelegate>

创建视图:

self.banner = [[IMBanner alloc] initWithFrame:CGRectMake(0,400, 320, 50)
                                      placementId:1493267833946];

    self.banner.delegate = self;
    [self.view addSubview:self.banner];
    [self.banner load];

然后是一些代理方法(建议不管有没有用,写上先,强迫症表示看到一堆警告⚠️很不舒服)

#pragma mark -------------------- 广告 ----------------------

/*Indicates that the banner has received an ad. */
- (void)bannerDidFinishLoading:(IMBanner *)banner {
    NSLog(@"bannerDidFinishLoading");
}

/* Indicates that the banner has failed to receive an ad */
- (void)banner:(IMBanner *)banner didFailToLoadWithError:(IMRequestStatus *)error {
    NSLog(@"banner failed to load ad");
    NSLog(@"Error : %@", error.description);
}

/* Indicates that the banner is going to present a screen. */
- (void)bannerWillPresentScreen:(IMBanner *)banner {
    NSLog(@"bannerWillPresentScreen");
}

/* Indicates that the banner has presented a screen. */
- (void)bannerDidPresentScreen:(IMBanner *)banner {
    NSLog(@"bannerDidPresentScreen");
}

/* Indicates that the banner is going to dismiss the presented screen. */
- (void)bannerWillDismissScreen:(IMBanner *)banner {
    NSLog(@"bannerWillDismissScreen");
}

/* Indicates that the banner has dismissed a screen. */
- (void)bannerDidDismissScreen:(IMBanner *)banner {
    NSLog(@"bannerDidDismissScreen");
}

/* Indicates that the user will leave the app. */
- (void)userWillLeaveApplicationFromBanner:(IMBanner *)banner {
    NSLog(@"userWillLeaveApplicationFromBanner");
}

/*  Indicates that the banner was interacted with. */
-(void)banner:(IMBanner *)banner didInteractWithParams:(NSDictionary *)params{
    NSLog(@"bannerdidInteractWithParams");
}

/*Indicates that the user has completed the action to be incentivised with .*/
-(void)banner:(IMBanner*)banner rewardActionCompletedWithRewards:(NSDictionary*)rewards{
    NSLog(@"rewardActionCompletedWithRewards");
}

command + R 就能看到广告了。横幅(banner)广告默认60秒刷新一次。

使用:

banner.keywords = @"sports, cars, bikes";//设置显示广告的类型

/*
    设置刷新频率(最低20,应该就是按你请求广告次数算钱的吧,不过貌似有bug,频率过高的话就刷不出来了,所以建议这个值不要太小,30~50吧)
    */
banner.refreshInterval = 20;

[banner shouldAutoRefresh:YES];//设置是否自动刷新

==================================

4.28更新

==================================

app成功上架之后,需要添加url,鼓捣半天,终于成功,步骤如下

iTunes connect中:
8

9

10

然后来到InMobi,点击中间的monetize,

11

12

步骤就是这样的啦,最后上一张效果图

13

最后的最后,安利一个我的app,图中取字,一个利用百度文字识别复制图片中的文字的app,由于简书贴链接被封了,所以还请大家自行App Store了

谢谢大家。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值