ADInterstitialAd的截图程序在iOS中给出了黑色图像

问题描述 投票:0回答:1

当我显示在_parentView(UIView)的iAd的创建此_parentView的图像。

我显示此图像(resultingImage)上UIImageView,那么这个图像是空白的(全黑)。

我怎样才能得到iAd截图编程?

- (id)initWithView:(UIView *)currentView
{
    self = [super init];
    if (self) {
        _parentView = currentView;
        self.interstitial = [[ADInterstitialAd alloc] init];
        self.interstitial.delegate = self;
    }
    return self;
}

- (void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd
{
   [interstitialAd presentInView:_parentView];
   [self takeScreenshot];
}

- (void)takeScreenshot
{
    CGRect      rect = CGRectMake(0, 0, _parentView.frame.size.width, _parentView.frame.size.height);

    UIGraphicsBeginImageContext(rect.size);
    [_parentView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}
ios objective-c xcode ipad iad
1个回答
0
投票

你检查,如果该设备是一台iPad? 基于该Official Apple document

好像你正在做正确。你可能会瓦纳检查

  [interstitialAd presentInView:_parentView];

返回一个真正的错误,然后再继续。

如果没有帮助,请尝试使用委托函数:

- (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error;

如果返回你的任何错误。

编辑:尝试使用根视图控制器从密钥窗口。这个对我有用。

if([self.interstitial presentInView:_view])
{ NSLog(@"Able to present in view"); }
else
{ [self.interstitial presentFromViewController:[UIApplication sharedApplication].keyWindow.rootViewController]; }
© www.soinside.com 2019 - 2024. All rights reserved.