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 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, and 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​

When you pass an object that conforms to GFPAdCacheManagerDelegate, you can receive success or failure callbacks through that object.

info

You must register a delegate on the ad object received in the callback to receive ad events such as impressions, clicks, and rendering errors.

  • Native Ad: assign an object conforming to GFPNativeAdDelegate to the delegate of GFPNativeAd
  • Native Simple Ad: assign an object conforming to GFPNativeSimpleAdDelegate to the delegate of GFPNativeSimpleAd
- (void)cacheManager:(NSString *)adUnitId didCacheNativeAd:(GFPNativeAd *)nativeAd {
NSLog(@"cacheManger:didCacheNativeAd:");
nativeAd.delegate = self; // register GFPNativeAdDelegate
}

- (void)cacheManager:(NSString *)adUnitId didCacheNativeSimpleAd:(GFPNativeSimpleAd *)nativeSimpleAd {
NSLog(@"cacheManger:didCacheNativeSimpleAd:");
nativeSimpleAd.delegate = self; // register GFPNativeSimpleAdDelegate
}

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