多平台开发 JavaScript 接入ios原生 inMobi 广告

第一步: 用cocoapods

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>

     @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 {
   
    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 *)[[ UIApplication sharedApplication ] keyWindow ]. rootViewController;
   
- (- (void)inmobiAd{ //添加广告
          NSLog ( @" 播放 inmobi 广告 " );
         [ IMSdk initWithAccountID : @"4028cb8b2c3a0b4512c406824e00ba12" ]; //在官方平台注册的广告
          //    [IMSdk setLogLevel:kIMSDKLogLevelDebug];
          _adInterstitial = [[ IMInterstitial alloc ] initWithPlacementId : 1446377525590 delegate : self ];
         [ _adInterstitial load ];
     }
   
    如果是多平台项目,在脚本语言里调用oc的接口 来达到实现广告播放的目的  
     + ( void )test{ //这里是用js调用的, 由于只能调用oc的类方法,这里在类方法中获得当前viewController的实例来添加广告
          NSLog ( @" 播放视频 " );
         [( RootViewController *)[[ UIApplication sharedApplication ] keyWindow ]. rootViewController inmobiAd ];
     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值