Skip to main content

Ad Caching

Ad Caching Guide

The ad disk caching feature is available only for Native Ads and Native Simple Ads served via S2S. It is supported starting from version 8.17.0 and above.

Creating Cache Options

To request disk-cached ads, you must create a GFPAdCacheNativeOptions instance.

Please refer to the basic guides for Native Ads and Native Simple Ads:

For guidance on adParam, refer to this link

GFPAdPraram *adParam = [[GFPAdParam alloc] init];

GFPAdCacheNativeOptions *cacheNativeOptions = [[GFPAdCacheNativeOptions alloc] initWith:@"set your unitId"
adParam:adParam
simpleOptions:nativeSimpleOptions
nativeOptions:nativeOptions];

Requesting Disk Caching

You can store Native Ads (NN) and Native Simple Ads (NS) on disk using prefetchNativeAd from GFPAdCacheManager.

  • Up to 5 ads per unit ID can be stored.
  • Only S2S-served ads are cached.
[GFPAdCacheManager.sharedInstance prefetchNativeAd: cacheNativeOptions];

Loading Cached Ads

Use GFPAdCacheManager to load ads saved on disk. By registering a GFPAdCacheManagerDelegate, you can receive success or failure callbacks.

[GFPAdCacheManager.sharedInstance loadNativeAdFromDisk:cacheNativeOptions delegate:self];

or

[GFPAdCacheManager.sharedInstance loadNativeAdFromDisk:cacheNativeOptions delegate:self isAutoPrefetch:YES];

isAutoPrefetch

The isAutoPrefetch option determines whether automatic prefetching is performed (default value: YES).

  • YES: When loadNativeAdFromDisk:delegate: is called, the GFP SDK internally calls prefetchNativeAd:.
  • NO: When loadNativeAdFromDisk:delegate: is called, the GFP SDK does not call prefetchNativeAd: internally.

Receiving Cached Ad Responses

If you pass an object that conforms to GFPAdCacheManagerDelegate, you can receive success or failure callbacks through the following methods.

- (void)cacheManager:(NSString *)adUnitId didCacheNativeAd:(GFPNativeAd *)nativeAd {
NSLog(@"cacheManger:didCacheNativeAd:");
}

- (void)cacheManager:(NSString *)adUnitId didCacheNativeSimpleAd:(GFPNativeSimpleAd *)nativeAd {
NSLog(@"cacheManger:didCacheNativeSimpleAd:");
}

- (void)cacheManager:(NSString *)adUnitId didFailWithError:(GFPError *)error responseInfo:(GFPLoadResponseInfo *)responseInfo {
NSLog(@"cacheManger:didCacheNativeAd:");
}