Fuze360SDK 1.0.0
使用 CocoaPods 进行安装
要将 Fuze360SDK 添加到您的应用程序中,请在 Podfile 中添加以下行
pod 'Fuze360SDK', :git => 'https://github.com/fuze360/Fuze360-iOS-SDK.git', :tag => '1.0.0'
然后运行
pod install
初始化 Fuze360SDK
在加载广告之前,应该在应用程序启动时初始化 Fuze360SDK。这应该只做一次
#import <Fuze360SDK/Fuze360SDK.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Initialize Fuze360SDK
[Fuze360Manager configureWithApiKey:@“API_KEY” authId:@“AUTH_ID” andMode:Fuze360SDKModeSandbox];
return YES;
}
API_KEY
和 AUTH_ID
在应用程序注册 Fuze360SDK 时生成。在编码、测试和调试时,请确保使用 Fuze360SDKModeSandbox
模式。否则可能会导致您的账户被暂停。发布应用程序之前,请将其替换为 Fuze360SDKModeLive
。
插屏广告
插屏广告是完全屏广告,它覆盖了应用程序的界面,直到用户关闭它。当应用程序显示插屏广告时,用户可以选择点击广告并继续访问其目的地,或者关闭它并返回应用程序。插屏广告通过 Fuze360Interstitial
对象进行请求和显示。
- (void)viewDidLoad {
[super viewDidLoad];
self.fuze360Interstitial = [[Fuze360Interstitial alloc] init];
self.fuze360Interstitial.delegate = self;
[self.fuze360Interstitial loadInterstitial];
}
要显示插屏广告,请检查 isReady
属性以确认它已加载完成,然后调用 presentFromRootViewController
。
if (self.fuze360Interstitial.isReady) {
[self.fuze360Interstitial presentFromRootViewController:self];
} else {
NSLog(@"Interstitial is not ready“);
}
一旦显示了横幅广告,hasBeenUsed
返回 true
,横幅广告就不能再用于展示其他广告。如果再次尝试展示横幅广告, 将会得到错误 "Interstitial has been used"
。通过在前一个横幅广告消失后立即预加载另一个横幅,您的应用就可以在下一个逻辑中断点再次展示横幅。最佳加载另一个横幅的位置是在 Fuze360InterstitialDelegate
上的 interstitialDidDismissScreen
方法中,这样就可以在前一个横幅消失后立即开始加载下一个横幅。
- (void)interstitialDidDismissScreen:(Fuze360Interstitial *)interstitial {
[self.fuze360Interstitial loadInterstitial];
}
Fuze360InterstitialDelegate
中的每个方法都被标记为可选的,所以您只需要实现您需要的方法。
// Tells the delegate an ad request succeeded.
- (void)interstitialDidReceiveAd:(Fuze360Interstitial *)interstitial {
NSLog(@"interstitialDidReceiveAd");
[interstitial presentFromRootViewController:self];
}
// Tells the delegate an ad request failed.
- (void)interstitial:(Fuze360Interstitial *)interstitial didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"Interstitial didFailToReceiveAdWithError: %@", error);
}
// Tells the delegate that an interstitial failed to be presented
- (void)interstitialDidFailToPresentScreenWithError:(NSError *)error {
NSLog(@"Interstitial interstitialDidFailToPresentScreenWithError: %@", error);
}
// Tells the delegate that an interstitial will be presented.
- (void)interstitialWillPresentScreen:(Fuze360Interstitial *)interstitial {
NSLog(@"interstitialWillPresentScreen");
}
// Tells the delegate the interstitial is to be animated off the screen.
- (void)interstitialWillDismissScreen:(Fuze360Interstitial *)interstitial {
NSLog(@"interstitialWillDismissScreen");
}
// Tells the delegate the interstitial had been animated off the screen.
- (void)interstitialDidDismissScreen:(Fuze360Interstitial *)interstitial {
NSLog(@"interstitialDidDismissScreen");
}
// Tells the delegate that a user click will open another app (such as Safari or App Store), backgrounding the current app.
- (void)interstitialWillLeaveApplication:(Fuze360Interstitial *)interstitial {
NSLog(@"interstitialWillLeaveApplication");
}
横幅广告
横幅广告在 Fuze360BannerView
中显示,因此第一步是在视图层次结构中包含一个 Fuze360BannerView
。这通常在 Interface Builder 或程序化方式中实现。要加载横幅广告,请调用
- (void)viewDidLoad {
[super viewDidLoad];
self.bannerView.delegate = self;
[self.bannerView loadBanner];
}
要注册横幅广告事件,设置 Fuze360BannerView
上的 delegate
属性为一个实现了 Fuze360BannerViewDelegate
协议的对象。在 Fuze360BannerViewDelegate
中的每个方法都被标记为可选的,因此您只需要实现您想要的方法。
// Tells the delegate an ad request succeeded.
- (void) fuze360AdsBannerViewDidReceiveAd:(Fuze360BannerView *) bannerView {
NSLog(@"fuze360AdsBannerViewDidReceiveAd");
}
// Tells the delegate an ad request failed.
- (void) fuze360AdsBannerView:(Fuze360BannerView *) bannerView didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"Banner didFailToReceiveAdWithError: %@", error);
}
// Tells the delegate that a user click will open another app (such as Safari or App Store), backgrounding the current app.
- (void) adViewWillLeaveApplication:(Fuze360BannerView *) bannerView {
NSLog(@"adViewWillLeaveApplication");
}
原生广告
原生广告在 Fuze360NativeAdView
中显示,因此第一步是在视图层次结构中包含一个 Fuze360NativeAdView
。这通常在 Interface Builder 或程序化方式中实现。要加载原生广告,请调用
- (void)viewDidLoad {
[super viewDidLoad];
self.nativeAdView.delegate = self;
[self.nativeAdView loadNativeAd];
}
要注册原生广告事件,设置 Fuze360NativeAdView
上的 delegate
属性为一个实现了 Fuze360NativeAdViewDelegate
协议的对象。在 Fuze360NativeAdViewDelegate
中的每个方法都被标记为可选的,因此您只需要实现您想要的方法。
// Tells the delegate an ad request succeeded.
- (void) fuze360NativeAdViewDidReceiveAd:(Fuze360NativeAdView *) nativeAd {
NSLog(@"fuze360NativeAdViewDidReceiveAd");
}
// Tells the delegate an ad request failed.
- (void) fuze360NativeAdView:(Fuze360NativeAdView *) nativeAdView didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"NativeAd didFailToReceiveAdWithError: %@", error);
}
// Tells the delegate that a user click will open another app (such as Safari or App Store), backgrounding the current app.
- (void) nativeAdViewWillLeaveApplication:(Fuze360NativeAdView *) nativeAd {
NSLog(@"nativeAdViewWillLeaveApplication");
}
许可协议
Fuze360SDK 以 MIT 许可协议提供。更多详情请参阅 LICENSE 文件。