您的位置:首页 > Web前端 > JavaScript

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

2017-05-01 10:39 489 查看
第一步: 用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>

     @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];
     }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息