第一步: 用cocoapods
target "项目名称" do
platform :ios, '7.0'
pod 'InMobiSDK', '~> 6.2.0'
platform :ios, '7.0'
pod 'InMobiSDK', '~> 6.2.0'
end
导入框架
可能出现的问题:
Use the
$(inherited)
flag, or
Remove the build settings from the target.
-
[!] The `AllBlue [AutoDebug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.autodebug.xcconfig'. This can lead to problems with the CocoaPods installation
Use the$(inherited)
flag, or
-
Remove the build settings from the target.
[!] The `AllBlue [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation
Use the$(inherited)
flag, or
-
Remove the build settings from the target.
[!] The `AllBlue [AutoRelease]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.autorelease.xcconfig'. This can lead to problems with the CocoaPods installation
Use the$(inherited)
flag, or
Remove the build settings from the target.
大概就是config设置上有冲突,解决办法:
在Build Settings -> Other linker flags 中添加$(inherited)在Build Settings -> head search Path 中添加$(inherited) (就是按照提示添加标识就行了)
第二步: 在
当前ViewController 开始弹出广告
1️⃣导入头文件 设置代理 并声明一个属性 来显示广告
#import
<InMobiSDK/InMobiSDK.h>
@interface
RootViewController
()<
IMInterstitialDelegate
> //设置代理
@property
(
strong
,
nonatomic
)
IMInterstitial
*adInterstitial; //声明一个属性来显示广告
@end
2️⃣实现代理方法
/
* Notifies the delegate that the ad server has returned an ad. Assets are not yet available.
* Please use interstitialDidFinishLoading: to receive a callback when assets are also available.
*/
-(void)interstitialDidReceiveAd:(IMInterstitial *)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial has finished loading
*/
-(void)interstitialDidFinishLoading:(IMInterstitial*)interstitial {
[interstitial showFromViewController:selfwithAnimation:kIMInterstitialAnimationTypeCoverVertical];
}
/
* The interstitial has failed to load with some error.
*/
-(void)interstitial:(IMInterstitial*)interstitial didFailToLoadWithError:(IMRequestStatus*)error {
* Notifies the delegate that the ad server has returned an ad. Assets are not yet available.
* Please use interstitialDidFinishLoading: to receive a callback when assets are also available.
*/
-(void)interstitialDidReceiveAd:(IMInterstitial *)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial has finished loading
*/
-(void)interstitialDidFinishLoading:(IMInterstitial*)interstitial {
[interstitial showFromViewController:selfwithAnimation:kIMInterstitialAnimationTypeCoverVertical];
}
/
* The interstitial has failed to load with some error.
*/
-(void)interstitial:(IMInterstitial*)interstitial didFailToLoadWithError:(IMRequestStatus*)error {
NSLog(@"错误信息:%@",error);
}
/
* The interstitial would be presented.
*/
-(void)interstitialWillPresent:(IMInterstitial*)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial has been presented.
*/
-(void)interstitialDidPresent:(IMInterstitial *)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial has failed to present with some error.
*/
-(void)interstitial:(IMInterstitial*)interstitial didFailToPresentWithError:(IMRequestStatus*)error {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial will be dismissed.
*/
-(void)interstitialWillDismiss:(IMInterstitial*)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial has been dismissed.
*/
-(void)interstitialDidDismiss:(IMInterstitial*)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial has been interacted with.
*/
-(void)interstitial:(IMInterstitial*)interstitial didInteractWithParams:(NSDictionary*)params {
NSLog(@"%s",__PRETTY_FUNCTION__);
NSLog(@"params : %@", params);
}
/
* The user has performed the action to be incentivised with.
*/
-(void)interstitial:(IMInterstitial*)interstitial rewardActionCompletedWithRewards:(NSDictionary*)rewards {
NSLog(@"%s",__PRETTY_FUNCTION__);
NSLog(@"rewards : %@", rewards);
}
/
* The user will leave application context.
*/
-(void)userWillLeaveApplicationFromInterstitial:(IMInterstitial*)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
/
* The interstitial would be presented.
*/
-(void)interstitialWillPresent:(IMInterstitial*)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial has been presented.
*/
-(void)interstitialDidPresent:(IMInterstitial *)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial has failed to present with some error.
*/
-(void)interstitial:(IMInterstitial*)interstitial didFailToPresentWithError:(IMRequestStatus*)error {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial will be dismissed.
*/
-(void)interstitialWillDismiss:(IMInterstitial*)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial has been dismissed.
*/
-(void)interstitialDidDismiss:(IMInterstitial*)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
/
* The interstitial has been interacted with.
*/
-(void)interstitial:(IMInterstitial*)interstitial didInteractWithParams:(NSDictionary*)params {
NSLog(@"%s",__PRETTY_FUNCTION__);
NSLog(@"params : %@", params);
}
/
* The user has performed the action to be incentivised with.
*/
-(void)interstitial:(IMInterstitial*)interstitial rewardActionCompletedWithRewards:(NSDictionary*)rewards {
NSLog(@"%s",__PRETTY_FUNCTION__);
NSLog(@"rewards : %@", rewards);
}
/
* The user will leave application context.
*/
-(void)userWillLeaveApplicationFromInterstitial:(IMInterstitial*)interstitial {
NSLog(@"%s",__PRETTY_FUNCTION__);
}
3️⃣
如果是ios项目 就在当前ViewController添加广告就可以了
[self inmobiAd
];
如果是多平台项目,
先找到当前ViewController RootViewController *rootViewController =
(
RootViewController
*)[[
UIApplication
sharedApplication
]
keyWindow
].
rootViewController;
- (- (void)inmobiAd{ //添加广告
NSLog
(
@"
播放
inmobi
广告
"
);
[
IMSdk
initWithAccountID
:
@"4028cb8b2c3a0b4512ce00ba12"
]; //在官方平台注册的广告
// [IMSdk setLogLevel:kIMSDKLogLevelDebug];
_adInterstitial
= [[
IMInterstitial
alloc
]
initWithPlacementId
:
90
delegate
:
self
];
[
_adInterstitial
load
];
}
如果是多平台项目,在脚本语言里调用oc的接口 来达到实现广告播放的目的
+ (
void
)test{ //这里是用js调用的, 由于只能调用oc的类方法,这里在类方法中获得当前viewController的实例来添加广告
NSLog
(
@"
播放视频
"
);
[(
RootViewController
*)[[
UIApplication
sharedApplication
]
keyWindow
].
rootViewController
inmobiAd
];
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/98392.html