I would like to ask the following questions:
1) How to hide iAD when the user clicks on the empty screen?
2) How to identify inactivity i.e. If user has an opened some application and leave the iphone and went away and application remained open?
Update:
According the apple documentation, this method is responsible for dismissing the iAD. but this method is still not working in my code. Any sample or how this method works?
- (void)cancelBannerViewAction
Explanation:
A banner view action can cover your application’s user interface. However, your application continues to run, and receives events normally. If your application receives an event that requires the user’s attention, it can programmatically cancel the action and uncover its interface by calling cancelBannerViewAction. Canceling actions frequently can cause a loss of revenue for your application.
Reference from Apple
But still I am unable to execute? This method is not working properly
You can just do something like below code.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.adBannerViewIsVisible)
{
NSLog(#"\nBanner Success");
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// assumes the banner view is offset 50 pixels so that it is not visible.
banner.frame = CGRectOffset(banner.frame,0,-94);
[UIView commitAnimations];
self.adBannerViewIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.adBannerViewIsVisible)
{
NSLog(#"\nBanner Failed");
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 94);
[UIView commitAnimations];
self.adBannerViewIsVisible = NO;
}
}
Just specify location of iAd in your code then you can change it's position by just changing value in this line
banner.frame = CGRectOffset(banner.frame, 0, 94);`
Hope this may clear what you want.
Related
I am trying to force EGORefreshTableHeaderView to update from the code. When I pull down everything works perfect and the TableView (root) gets refreshed. But I have a modal view where the user can subscribe to certain entities. When he subscribes to one the reload method in the first (root) table view gets triggered. This method establishes a connection to a server, loads some specific data based on the subscription, stores it in a CoreData DB and updates the TableView (root).
The problem is that when the user is only connected to 3G or Edge network the download, which is processed in an own thread, can take several seconds. To indicate the user that something happens I would like to show the EGORefreshTableHeaderView.
I found out that I can set the indent of the refresh view and manually show the loading icon but I was wondering if there is not an easier solution by just triggering a delegate or a method on the EGORefreshTableHeaderView?
Did you try using egoRefreshScrollViewDataSourceStartManualLoading?
Assuming your EGORefreshTableHeaderView instance is named _refreshTableHeaderView, then a call like:
[_refreshTableHeaderView egoRefreshScrollViewDataSourceStartManualLoading:self.tableView];
works for me...
So, it's been too long since I used this, and I forgot I applied the change myself...
I modified EGORefreshTableHeaderDelegate (declared in EGORefreshTableHeaderView.h) to add this additional protocol:
- (void)egoRefreshScrollViewDataSourceStartManualLoading:(UIScrollView *)scrollView;
And the implementation (in EGORefreshTableHeaderView.m):
- (void)egoRefreshScrollViewDataSourceStartManualLoading:(UIScrollView *)scrollView {
[self setState:EGOOPullRefreshLoading];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);
[UIView commitAnimations];
if ([_delegate respondsToSelector:#selector(egoRefreshTableHeaderDidTriggerRefresh:)]) {
[_delegate egoRefreshTableHeaderDidTriggerRefresh:self];
}
}
Let me know if you need more help there.
(And thank-you enormego for the great work!)
Thanks to Reuven and his code I have improved it a little bit that it can also be used in an UIScrollView that is larger as the screen. Additionally, I have changed the deprecated commitAnimations to block animations.
#pragma mark - Manually refresh view update
- (void)egoRefreshScrollViewDataSourceStartManualLoading:(UIScrollView *)scrollView {
[self.refreshHeaderView setState:EGOOPullRefreshLoading];
//animating pull down scroll view
[UIView animateWithDuration:0.2
animations:^{
scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);
scrollView.contentOffset = CGPointMake(0, -60.0f);
}
];
//triggering refreshview regular refresh
if ([self.tableView.delegate respondsToSelector:#selector(egoRefreshTableHeaderDidTriggerRefresh:)]) {
[self egoRefreshTableHeaderDidTriggerRefresh:self.refreshHeaderView];
}
}
I used iAd framework for add ad on screen. I done with this by below code.
but I want ad in UIAertview. When UIAlertview comes user should be view company ad in that.
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animatesAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height); [UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animatesAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height); //rect, dx,dy
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
I know we can customized UIAlertview. But not getting how to add iAd view in that. If anyone know's help me.
If I'm understanding you correctly, you want to create an ad for your own company? You wouldn't use iAd for this, as with iAd you have very little control over which advertisement is pushed to your banner. However you can make a new view with whatever you want in it (advertisement wise) and add it as a subview of your UIAlertView. Now I am saying you CAN do this, but you probably shouldn't. Modification of an alertView in this way will most likely be rejected by Apple.
I have an iAd which shows up fine when connected to the Network. On the iOS simulator or testing on my device, if I open up my app, see the iAd, then go to settings and turn on airplane mode, and return to the app, the banner slide off the screen. Great. Now, if I turn airplane mode back off (network is ON), the iAd doesn't reappear - even after waiting for 10-15 minutes.
So, here are my questions:
Does the iAd Test Advertisement refresh itself the same as a real iAd would (every minute or so)?
Is there a way to force the iAd to refresh and request a new ad when the network is detected?
I just can't find information on the behaviour of the Test Ads anywhere, and I can't test with real Ads until I upload the app to the App Store (right?)
Heres my code:
Where the iAd is created:
- (void)viewDidLoad
{
adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 410, 320, 50)];
adView.frame = CGRectOffset(adView.frame, 0, 50);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adView];
adView.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];
}
And the delegate methods:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(#"AdWin");
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"AdLose");
if (self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
The delegate method NSLog calls only appear once - not every minute, like I would expect if the Ad was getting refreshed.
1- yes and like live ads there are some times with no ad at all, it can be hours. I believe the refresh cycle is 3 minutes but it seems apple can change it as they will
2- you shouldn't need to, when properly setup this happens automatically. I have an app with ads and it behaves correctly when switching network or using the airplane setting
Now, there seems to be something about the airplane setting, see this thread : iAds Loading Throttled After Re-Launching App From Background (Also Happens In iAdSuite), but I don't have the final answer. Maybe you could explore more by changing your NSLog in didFail... to NSLog(#"%#", error) to check what it exactly says.
Ah and indeed there is no way to test with real ads until it's accepted in the appstore.
I don't see that method in there... I just put the iAd banner in using xcode at the top of a drill down table tutorial. I tried it at the top and at the bottom.
It seems to compile and run in the simulator... but I get this error. I'm trying to add iAds to a table view app. Any suggestions would be greatly appreciated?
-(void) bannerViewDidLoadAd:(ADBannerView *)banner{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}}
-(void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
if (self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}}
I had the exact same issue in Xcode 4.2.1 when trying to add ADBannerView to TableView in a nib. It looks like a bug from Xcode or iAd framework.
This can be walkaround by following steps:
Add ADBanner View to TableView.
Switch to Attribute Inspector and click the ADBanner view.
Change "Orientation" to "Portait" and compile the Project. The error will be gone.
You could now change it back to "Both" again, and you won't see the error any more.
I'm testing iAds in XCode 4.
Everything works fine, until the first time a bannerView:didFailToReceiveAdWithError: is received, which I react to by sliding the banner off the screen.
//move the ad back off the screen if an error occurs
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
if (self.bannerIsInScreenBounds)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// move the banner view off the screen.
banner.frame = CGRectOffset(banner.frame, 320, 0);
[UIView commitAnimations];
}
}
After that, no more bannerViewDidLoadAd: messages are sent to the ADBannerViewDelegate. I'm logging that method right at the top, it's not being called any more.
I'm not releasing the banner or anything, and the ADBannerViewDelegate class is still there and doing other stuff.
What could be wrong?
Thanks.
Why do you expect it load adverts after an error has happened - I think this is the correct behavior.
Looking at the comments it show that the error is "The operation couldn’t be completed. Ad inventory unavailable".
How do you expect it to give you adverts if it can't find any adverts to give ;)
OK, not an ideal solution but here's what I ended up doing.
Whenever I get a didFailToReceiveAdWithError, I wait 10 seconds (to avoid spamming with failures) then recreate the banner.
-(void)replaceAdView {
UIView *adViewSuperview = [adView superview];
[adView removeFromSuperview];
[adView release];
//starting off the screen again
adView = [[NSClassFromString(#"ADBannerView") alloc] initWithFrame:CGRectMake(320, 382, 320, 50)];
adView.delegate = self;
if (adViewSuperview) {
[adViewSuperview addSubview:adView];
}
self.bannerIsInScreenBounds = NO;
}
As my comment at how to implement AdBannerview and ADBannerview delegate, running iphone app in ipad simulator I got didFailToReceiveAdWithError immediately on setting the ADBannerView delegate, and never another delegate call. Running it on the iphone simulator (or changing the app target to universal) the delegate only got called after adding ADBannerView as a subview, and then delegate calls every 30 secs after that.