0

当我展示 iAd_parentView(UIView)并创建此图像时_parentView

我在 a 上显示此图像(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();
}
4

1 回答 1

0

您是否检查了该设备是否是 iPad?
基于Apple 官方文档

看起来你做对了。你可能想检查一下

  [interstitialAd presentInView:_parentView];

在继续之前返回 true 或 false。

如果这没有帮助,请尝试使用委托功能:

- (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]; }
于 2013-07-10T11:22:38.457 回答