共享类AdMobViewController:UIViewController <AdMobDelegate>{
视图AdMobView;
计时器refreshTimer;
共享方法+(AdMobViewController*)sharedController;
请求视图方法-(void)requestAd;
实现请求视图方法-(void)requestAd{
获取视图self.AdMobView = requestAdWithDelegate:self;
}
实现协议AdMobDelegate{
请求失败didFailToReceive{
重试{
原计时器停止refreshTimer invalidate;
新计时器初始化refreshTimer = scheduledTimerWithTimerInterval selector(requestAd);
} 重试结束 {
计时器停止refreshTimer invalidate;
移除视图AdMobView remove;
释放视图AdMobView release;
AdMobView = nil;
}
}
请求成功didReceiveAd{
将请求得到视图放入共享类的视图AdMobViewController.view = AdMobView.view;
计时器停止refreshTimer invalidate;
}
}
}
根视图控制RootViewController{
ViewDidLoad{
获取共享类share AdMobViewController;
请求视图requestAd;
}
viewWillAppear{
设置框架大小和位置AdMobViewController.view.frame = CGReckMake(x, y, w, h);
向当前视图添加子视图self.view addSubView:AdMobViewController.view;
}
viewWillDisappear{
移除子视图AdMobViewController.view remove;
}
}
子视图控制OptionViewController{
viewWillAppear{
获取共享类share AdMobViewController;
设置框架大小和位置AdMobViewController.view.frame = CGReckMake(x, y, w, h);
向当前视图添加子视图self.view addSubView:AdMobViewController.view;
}
viewWillDisappear{
移除子视图AdMobViewController.view remove;
}
}