GumGum是一家领先的图片和屏幕内广告平台,为广告商提供品牌参与度,为出版商带来跨所有屏幕的收入增长。
1) 在您的目标“与库链接”中链接所需的框架: 注意:
MessageUI.framework
是可选的
2) 将 GumGumiOSSDK.framework
链接到您的目标:
3) 将 GumGumiOSSDK.bundle
添加到您的目标“复制包资源”构建阶段:
4) 将 -ObjC
编译器标志添加到项目目标构建设置的“其他链接器标志”中。
5) 构建您的项目(⌘+B),以确保一切正常工作。
#import <GumGumiOSSDK/GumGumiOSSDK.h>
设置您应用程序的信息。这应在您的 App Delegate 中或在尽可能早的时间进行。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Make sure you have setup your keyWindow first.
[window makeKeyAndVisible];
NSURL *url = [NSURL URLWithString:@"your app store url or website url"];
[GumGumSDK initializeWithZoneId:@"your zone ID" appStoreURL:url isPaid:YES];
return YES;
}
[GGNativeAdManager getNativeAdForSize:CGSizeMake(320, 100)
placementId:// Your placement id (provided by GumGum)
viewControllerDelegate:// A UIViewController conforming to GGAdDelegate
completion:^(GGNativeAd *nativeAd, NSError *error) {
// Your logic for displaying the native ad
/* GGNativeAd model contains:
* title
* adDescription
* imageView.image or imageUrl
* sponsoredBy
*/
}];
从 GGInImageView
继承您希望广告放置的 UIImageView
。
如果您使用 Storyboards,您需要将 UIImageView
的 "Custom Class" 字段更改为 GGInImageView
在 -viewDidLoad
(或初始化后调用的任何方法)中
- (void)viewDidLoad {
[super viewDidLoad];
// All values are required
GGInImageView *imageView = [[GGInImageView alloc] init];
imageView.imageURL = [NSURL URLWithString:@"http://gumgum.com"];
imageView.pageURL = [NSURL URLWithString:@"http://gumgum.com"];
imageView.delegate = // A UIViewController conforming to GGAdDelegate
// The ad will NOT start loading until an image with at least 120px height is set.
imageView.image = [UIImage alloc] init];
}
将 UIViewController
与 GGAdDelegate
匹配
@interface YourViewController: UIViewController <GGAdDelegate>
屏幕内广告由 UINavigationController
的一个实例控制。
UIViewController *viewController = [[UIViewController alloc] init];
GGInScreenNavigationController *navigationController = [[GGInScreenNavigationController alloc] initWithRootViewController:viewController];
navigationController.pageURL = [NSURL URLWithString:@"http://gumgum.com"];
navigationController.keywords = @"An, ad, is, worth, a, million, billion, impressions";
请记住,屏幕内广告在视图控制器展示之间保持状态。要控制哪些视图控制器显示广告,只需将您想显示广告的视图控制器与 GGAdDelegate
匹配即可。
如果您将视图控制器与 GGAdDelegate
匹配以显示 GGInImageView
,但同时也想不显示屏幕内广告,只需设置导航控制器上的 inScreenHidden
属性
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([self.navigationController conformsToProtocol:@protocol(GGAdDelegate)]) {
GGInScreenNavigationController *navController = (GGInScreenNavigationController *)self.navigationController;
[navController setInScreenHidden:YES animated:YES];
}
}
// Don't forget to restore inScreenHidden when leaving that view controller!
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if ([self.navigationController conformsToProtocol:@protocol(GGAdDelegate)]) {
GGInScreenNavigationController *navController = (GGInScreenNavigationController *)self.navigationController;
[navController setInScreenHidden:NO animated:YES];
}
}
使用 GGInFeedDataSource
匹配管理您希望在其中显示广告的 UITableView
的实例。
在您想要开始加载数据流内广告的时间
CGSize size = CGSizeMake(300, 100);
id <GGInFeedDataSource> dataSource = // An instance conforming to GGInFeedDataSource
UIViewController <GGAdDelegate>*viewController = // An instance of UIViewController that conforms to GGAdDelegate
[[GGInFeedManager sharedManager] getInFeedAdWithSize:size
placementId:// Your placement id (provided by GumGum)
indexPath:// Optional. If you wish to specify exactly where the ad should be placed.
dataSource:dataSource
delegate:delegate];
根据需要,为您的 UITableView
提供辅助方法,以适应原生广告的显示。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSUInteger rows = // Number of rows you plan to show in this section
NSUINteger nativeAdCount = [[GGInFeedManager sharedManager] nativeAdCountForSection:section];
return rows + nativeAdCount;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Your UITableViewCell setup logic
GGNativeAd *nativeAd = [[GGInFeedManager sharedManager] nativeAdAtIndexPath:indexPath cell:cell];
if (nativeAd) {
// Your logic for displaying the native ad
} else {
// Your normal cell display implementation
// Keep in mind you'll want to offset the array of data you are
// normally displaying. Here is a rough example...
NSArray *rowItems = @[];
NSDictionary *cellInfo = rowItems[indexPath.row + offset]; // You should always add the offset!
}
return cell;
}
更多文档可以在这里找到 http://cocoadocs.org/docsets/GumGumiOSSDK/0.1.1/.
就是这样!
关注 GumGum 的 Twitter (@GumGum)
Jake Peterson (@jakenberg)