如何集成inmobi到ios
2015-12-26 17:19
706 查看
1 、Adding SDK to your project
Copy the below header files and binary from the downloaded SDK bundle to your project
2、Adding Frameworks
Add the frameworks below to your Xcode project by navigating to your project settings and hitting the “+” button under the “Linked Frameworks and Libraries” section.
Note: If you use iOS 8.x, please add the
to your
3、Adding Additional Build Settings
Add the
Linker Flags by following the below steps:
Open your project in XCode
Select Application Target > Build Settings
In the Search field, search for Other Linker Flags
Add the <code>-ObjC</code> flag
Also for now, disable ATS for apps on iOS 9 (Click here to
learn why), and please add the following code snippet to your app's plist.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
4、Initializing the InMobi SDK
You must initialize the SDK during app launch. Your account ID has been prepopulated to aid copying and pasting.
In
import the below:
#import "IMSdk.h"
#import "IMCommonConstants.h"
In the
that reflects the location of your ad unit, import the below:
#import "IMBanner.h"
#import "IMBannerDelegate.h"
#import "IMInterstitial.h"
#import "IMInterstitialDelegate.h"
#import "IMNative.h"
#import "IMNativeDelegate.h"
In
initialize the SDK as shown below:
- (BOOL)application:(UIApplication
*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Initialize InMobi SDK with your account ID
[IMSdk initWithAccountID:@"9697f54927be4ff3ba71a02181323d65"];
// Do your stuff.
return YES;
}
5、Implementing a Full Screen Interstitial Ad
InMobi serves both landscape and portrait type of interstitial ads (non-rewarded video, images, rich-media). The InMobi SDK will automatically ensure that it serves appropriate ads as per the application orientation. Perform the below steps to implement interstitial
ads.
Register the
<IMInterstitialDelegate> and declare an interstitial instance as shown below before
your declaration section . Make any necessary code changes to avoid duplication of controller definitions.
@interface ViewController () <IMInterstitialDelegate>
@property (nonatomic,strong) IMInterstitial *interstitial;
2.To instantiate your interstitial, copy and paste the below code in the
of your
in a method that initiates a new user session in order to enable loading of the ad.
/* This code loads the ad in the cache for better performance. Please place this in a method of your controller that ensure that ads are
loaded again after they have been dismissed. */
self.interstitial = [[IMInterstitial alloc] initWithPlacementId:1449126032215 delegate:self];
[self.interstitial load];
3.Add the following callbacks
by copying the below code and pasting it in your
the last
- (void)interstitial:(IMInterstitial
*)interstitial didFailToLoadWithError:(IMRequestStatus *)error{
NSLog(@"Interstitial Failed to load interstitial with error: %@",error.description);
}
- (void)interstitial:(IMInterstitial *)interstitial didFailToPresentWithError:(IMRequestStatus *)error {
NSLog(@"Interstitial Failed to Present Interstitial with error : %@",error.description);
}
- (void)interstitial:(IMInterstitial *)interstitial didInteractWithParams:(NSDictionary *)params {
NSLog(@"Interstitial did interact with param : %@",params);
}
- (void)interstitial:(IMInterstitial *)interstitial rewardActionCompletedWithRewards:(NSDictionary *)rewards {
NSLog(@"Interstitial reward action completed with Rewards : %@",rewards);
}
- (void)interstitialDidDismiss:(IMInterstitial *)interstitial {
NSLog(@"Interstitial Did Dismiss");
}
- (void)interstitialDidFinishLoading:(IMInterstitial *)interstitial {
NSLog(@"Interstitial Did Finish Loading");
}
- (void)interstitialDidPresent:(IMInterstitial *)interstitial {
NSLog(@"Interstitial Did Present");
}
- (void)interstitialWillDismiss:(IMInterstitial *)interstitial {
NSLog(@"Interstitial Will Dismiss");
}
- (void)interstitialWillPresent:(IMInterstitial *)interstitial {
NSLog(@"Interstitial Will Present");
}
4.Add
the following code to a method in your controller that is invoked at the time at which you want the ad to be shown. This is typically at level failure in a game, or as an item in the store-front or so on.
if
([self.interstitial isReady]){
[self.interstitial showFromViewController:self];
}
Copy the below header files and binary from the downloaded SDK bundle to your project
libInMobi5.x.x.a
IMSdk.h
IMBanner.h
IMBannerDelegate.h
IMInterstitial.h
IMInterstitialDelegate.h
IMNative.h
IMNativeDelegate.h
IMCustomNative.h
IMRequestStatus.h
IMCommonConstants.h
2、Adding Frameworks
Add the frameworks below to your Xcode project by navigating to your project settings and hitting the “+” button under the “Linked Frameworks and Libraries” section.
AdSupport.framework
AudioToolbox.framework
AVFoundation.framework
CoreLocation.framework
CoreTelephony.framework
EventKit.framework
EventKitUI.framework
MediaPlayer.framework
MessageUI.framework
SafariServices.framework
Security.framework
Social.framework
StoreKit.framework
SystemConfiguration.framework
libsqlite3.0.dylib
libz.dylib
Note: If you use iOS 8.x, please add the
NSLocationWhenInUseUsageDescriptionflag
to your
info.plistfile
3、Adding Additional Build Settings
Add the
-ObjCflag to Other
Linker Flags by following the below steps:
Open your project in XCode
Select Application Target > Build Settings
In the Search field, search for Other Linker Flags
Add the <code>-ObjC</code> flag
Also for now, disable ATS for apps on iOS 9 (Click here to
learn why), and please add the following code snippet to your app's plist.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
4、Initializing the InMobi SDK
You must initialize the SDK during app launch. Your account ID has been prepopulated to aid copying and pasting.
In
AppDelegate.h,
import the below:
#import "IMSdk.h"
#import "IMCommonConstants.h"
In the
UIViewController.hfile
that reflects the location of your ad unit, import the below:
#import "IMBanner.h"
#import "IMBannerDelegate.h"
#import "IMInterstitial.h"
#import "IMInterstitialDelegate.h"
#import "IMNative.h"
#import "IMNativeDelegate.h"
In
AppDelegate.mfile,
didFinishLaunchingWithOptionsmethod,
initialize the SDK as shown below:
- (BOOL)application:(UIApplication
*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Initialize InMobi SDK with your account ID
[IMSdk initWithAccountID:@"9697f54927be4ff3ba71a02181323d65"];
// Do your stuff.
return YES;
}
5、Implementing a Full Screen Interstitial Ad
InMobi serves both landscape and portrait type of interstitial ads (non-rewarded video, images, rich-media). The InMobi SDK will automatically ensure that it serves appropriate ads as per the application orientation. Perform the below steps to implement interstitial
ads.
Register the
UIViewControllerwith
<IMInterstitialDelegate> and declare an interstitial instance as shown below before
@endof
your declaration section . Make any necessary code changes to avoid duplication of controller definitions.
@interface ViewController () <IMInterstitialDelegate>
@property (nonatomic,strong) IMInterstitial *interstitial;
2.To instantiate your interstitial, copy and paste the below code in the
viewDidLoad()method
of your
UIViewControlleror
in a method that initiates a new user session in order to enable loading of the ad.
/* This code loads the ad in the cache for better performance. Please place this in a method of your controller that ensure that ads are
loaded again after they have been dismissed. */
self.interstitial = [[IMInterstitial alloc] initWithPlacementId:1449126032215 delegate:self];
[self.interstitial load];
3.Add the following callbacks
by copying the below code and pasting it in your
UIViewControllerbefore
the last
@endline.
- (void)interstitial:(IMInterstitial
*)interstitial didFailToLoadWithError:(IMRequestStatus *)error{
NSLog(@"Interstitial Failed to load interstitial with error: %@",error.description);
}
- (void)interstitial:(IMInterstitial *)interstitial didFailToPresentWithError:(IMRequestStatus *)error {
NSLog(@"Interstitial Failed to Present Interstitial with error : %@",error.description);
}
- (void)interstitial:(IMInterstitial *)interstitial didInteractWithParams:(NSDictionary *)params {
NSLog(@"Interstitial did interact with param : %@",params);
}
- (void)interstitial:(IMInterstitial *)interstitial rewardActionCompletedWithRewards:(NSDictionary *)rewards {
NSLog(@"Interstitial reward action completed with Rewards : %@",rewards);
}
- (void)interstitialDidDismiss:(IMInterstitial *)interstitial {
NSLog(@"Interstitial Did Dismiss");
}
- (void)interstitialDidFinishLoading:(IMInterstitial *)interstitial {
NSLog(@"Interstitial Did Finish Loading");
}
- (void)interstitialDidPresent:(IMInterstitial *)interstitial {
NSLog(@"Interstitial Did Present");
}
- (void)interstitialWillDismiss:(IMInterstitial *)interstitial {
NSLog(@"Interstitial Will Dismiss");
}
- (void)interstitialWillPresent:(IMInterstitial *)interstitial {
NSLog(@"Interstitial Will Present");
}
4.Add
the following code to a method in your controller that is invoked at the time at which you want the ad to be shown. This is typically at level failure in a game, or as an item in the store-front or so on.
if
([self.interstitial isReady]){
[self.interstitial showFromViewController:self];
}
相关文章推荐
- iOS中的手势详解
- [IOS开发教程] iOS获取设备信息
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS Label的图文混排
- [IOS开发教程] NSfileManager的使用方法
- iOS开发怎么在Button的显示倒计时
- iOS支付宝支付
- iOS中判断数组长度问题
- iOS开发- 隐藏状态栏(电池栏)
- iOS数据类型
- xcode安装模拟器失败 (could not download and install iOS 7.1 simulator ,需要授权才能安装这些软件包)
- iOS初体验---通知
- iOS- tableview的本地性能优化
- iOS_第3方键盘管理库_IQKeyboardManager
- iOS开发编码规范建议
- ios学习--XCode标准Framework静态库制作方法 & 工程转Framework静态库加xib和图片的完美解决方案
- iOS 导航控制器下级向上级传值,pop反向传值
- ios学习--XCode打包.a静态库文件&正确导出.h头文件
- iOS-----使用CoreLocation定位
- iOS: 如何判断字符串是否相等?