如何集成inmobi到ios

来源:互联网 发布:麦克雷爆头伤害数据 编辑:程序博客网 时间:2024/06/06 09:00
1 、Adding SDK to your project
Copy the below header files and binary from the downloaded SDK bundle to your project
  • libInMobi­5.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 NSLocationWhenInUseUsageDescription flag to your info.plist file

3、Adding Additional Build Settings
Add the ­-ObjC flag to Other Linker Flags by following the below steps:
  1. Open your project in XCode
  2. Select Application Target > Build Settings
  3. In the Search field, search for Other Linker Flags
  4. 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.h file 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.m file, didFinishLaunchingWithOptions method, 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.
  1. Register the UIViewController with <IMInterstitialDelegate> and declare an interstitial instance as shown below before @end of 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 UIViewController or 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 UIViewController before the last @end line.

- (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];
}
0 0
原创粉丝点击