当我显示在_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();
}
你检查,如果该设备是一台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]; }