多平台开发 JavaScript 接入ios原生 inMobi 广告
2017-05-01 10:39
489 查看
第一步: 用cocoapods
target "项目名称" do
platform :ios, '7.0'
pod 'InMobiSDK', '~> 6.2.0'
end
导入框架
可能出现的问题:
Use the
or
Remove the build settings from the target.
Use the
Remove the build settings from the target.
Use the
Remove the build settings from the target.
Use the
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>
@interfaceRootViewController()<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 {
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__);
}
3️⃣
如果是ios项目 就在当前ViewController添加广告就可以了 [self inmobiAd];
如果是多平台项目,先找到当前ViewController RootViewController *rootViewController = (RootViewController
*)[[UIApplicationsharedApplication]keyWindow].rootViewController;
- (- (void)inmobiAd{
//添加广告
NSLog(@"播放inmobi广告");
[IMSdkinitWithAccountID:@"4028cb8b2c3a0b4512c406824e00ba12"];
//在官方平台注册的广告
// [IMSdk setLogLevel:kIMSDKLogLevelDebug];
_adInterstitial
= [[IMInterstitialalloc]initWithPlacementId:1446377525590delegate:self];
[_adInterstitialload];
}
如果是多平台项目,在脚本语言里调用oc的接口 来达到实现广告播放的目的
+ (void)test{
//这里是用js调用的, 由于只能调用oc的类方法,这里在类方法中获得当前viewController的实例来添加广告
NSLog(@"播放视频");
[(RootViewController
*)[[UIApplicationsharedApplication]keyWindow].rootViewControllerinmobiAd];
}
target "项目名称" do
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>
@interfaceRootViewController()<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 {
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__);
}
3️⃣
如果是ios项目 就在当前ViewController添加广告就可以了 [self inmobiAd];
如果是多平台项目,先找到当前ViewController RootViewController *rootViewController = (RootViewController
*)[[UIApplicationsharedApplication]keyWindow].rootViewController;
- (- (void)inmobiAd{
//添加广告
NSLog(@"播放inmobi广告");
[IMSdkinitWithAccountID:@"4028cb8b2c3a0b4512c406824e00ba12"];
//在官方平台注册的广告
// [IMSdk setLogLevel:kIMSDKLogLevelDebug];
_adInterstitial
= [[IMInterstitialalloc]initWithPlacementId:1446377525590delegate:self];
[_adInterstitialload];
}
如果是多平台项目,在脚本语言里调用oc的接口 来达到实现广告播放的目的
+ (void)test{
//这里是用js调用的, 由于只能调用oc的类方法,这里在类方法中获得当前viewController的实例来添加广告
NSLog(@"播放视频");
[(RootViewController
*)[[UIApplicationsharedApplication]keyWindow].rootViewControllerinmobiAd];
}
相关文章推荐
- iOS开发 接入InMobi广告平台的一些个人经验
- Unity3d与iOS交互开发——接入平台SDK必备技能
- Unity3D开发 - Unity3d与iOS交互开发(接入平台SDK)
- 使用OSS JavaScript的sdk进行web端直传,开发环境下测试没有问题,但部署到服务器上或者打包到IOS原生包中出现了问题。
- Unity3d与iOS交互开发——接入平台SDK必备技能
- Unity3d与iOS交互开发——接入平台SDK必备技能
- Unity3d与iOS交互开发——接入平台SDK必备技能
- iOS开发-------基于WKWebView的原生与JavaScript数据交互
- Unity3d与iOS交互开发——接入平台SDK必备技能
- 移动开发新选择 使用javascript开发iOS和Android原生应用
- Unity与iOS平台交互和原生插件开发
- Unity3d与iOS交互开发——接入平台SDK必备技能
- android开发步步为营之55:google广告平台admob接入总结
- Unity3d与iOS交互开发——接入平台SDK必备技能
- Unity与iOS平台交互和原生插件开发
- iOS与H5交互 H5与App原生交互,一般会是前端页面中的JavaScript与App使用的原生开发语言的交互。技术方案应能达到以下要求: 在js与原生进行交互的时候能保证正常的正向调用逻辑返回
- IOS开发广告接入iAD框架_InMobi框架
- Unity3d与iOS交互开发——接入平台SDK必备技能
- unity开发关于IOS平台接入之自动化构建管线
- Unity3d与iOS交互开发——接入平台SDK必备技能