I am working on application in which i have to show iAds continuously. Can anyone tell me how can i set iAds that continuously stays on screen.
Thanks in Advance.
The problem is that you should only show iAd banner when it has it's contents loaded. And there's no guarantee that contents will be available for you 24/7.
You could however provide an alternate content (house ads or ads from other source) for when iAd banner has no content.
Note that in this case you have to hide iAd banner and show a custom banner on it's place.
As a source of alternate content you can take a look at:
mobiclix
admob
You have to take iAd in to the application Delegate View and set is bring subview to front.
In Application Delegate add this line
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
[self createAdBannerView];
}
- (void)createAdBannerView
{
Class classAdBannerView = NSClassFromString(#"ADBannerView");
if (classAdBannerView != nil)
{
self.adBannerView = [[[classAdBannerView alloc] initWithFrame:CGRectZero] autorelease];
[_adBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects: ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil]];
if (UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
[_adBannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifier480x32];
}
else
{
[_adBannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifier320x50];
}
if(DeviceFlag == 1)
{
[_adBannerView setFrame:CGRectOffset([_adBannerView frame], 0, -100)];
}
else
{
[_adBannerView setFrame:CGRectOffset([_adBannerView frame], 0, -70)];
}
//[_adBannerView setFrame:CGRectOffset([_adBannerView frame], 0, -[self getBannerHeight])];
[_adBannerView setDelegate:self];
[viewController.view addSubview:_adBannerView];
[self.window bringSubviewToFront:_adBannerView];
}
}
Related
I m loading a view which gets data from webservices. So depending upon the response code from server I show the current view or redirect to another view (ErrorView) if responsecode is 400.But I'm not being redirected to ErrorView and find a message in console "Attempt to present <ErrorView: 0xe332f30> on ViewController while a presentation is in progress!"
After googling it out I found to place vieDidLoad code to viewDidAppear
After placing the entire code , it redirects to error view and works correctly.But in ios7 for Status bar issue I used the code
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if(responsecode==200)
{
//load current view
}
else
{
//Load anotherview(ErrorView)
}
float systemVersion=[[[UIDevice currentDevice] systemVersion] floatValue];
if(systemVersion>=7.0f)
{
CGRect tempRect;
for(UIView *sub in [[self view] subviews])
{
tempRect = [sub frame];
tempRect.origin.y += 20.0f;
[sub setFrame:tempRect];
}
}
}
First the statusbar appear on the top ,then after loading the entire viewdata , view gets adjusted and status bar dropsdown by 20px , which looks odd.Can I get it to be adjusted automatically before the viewloads completely ?
Any ideas/suggestions would be appreciable.
I think, you should seperate this code
-(void)viewDidLoad
{
float systemVersion=[[[UIDevice currentDevice] systemVersion] floatValue];
if(systemVersion>=7.0f)
{
CGRect tempRect;
for(UIView *sub in [[self view] subviews])
{
tempRect = [sub frame];
tempRect.origin.y += 20.0f;
[sub setFrame:tempRect];
}
}
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if(responsecode==200)
{
//load current view
}
else
{
//Load anotherview(ErrorView)
}
}
I have an iPhone application in which I am testing in the applicationDidBecomeActive: that if the selected viewcontroller's rootview is there, then I want to call one webservice, otherwise not when I am coming from background to foreground I am taking the stack and checking it. But now even if I am in the rootview the webservice is not getting called. Can anybody help me on this?
Here is my code snippet:
- (void)applicationDidBecomeActive:(UIApplication *)application{
NSLog(#"applicationWilssnd");
if(tabBarController.selectedIndex==0)
{
NSArray *mycontrollers = self.tabBarController.viewControllers;
NSLog(#"%#",mycontrollers);
///if([mycontrollers objectAtIndex:0]!=)
///[[mycontrollers objectAtIndex:0] popToRootViewControllerAnimated:NO];
PinBoardViewController *pinvc=(PinBoardViewController*)[[mycontrollers objectAtIndex:0]topViewController] ;
if([mycontrollers objectAtIndex:0]!=pinvc)
{
}
else
{
[pinvc merchantnews];
}
mycontrollers = nil;
tabBarController.selectedIndex = 0;
}
}
`here the merchantnews is not getting called.
PinBoardViewController *pinvc=(PinBoardViewController*)[[mycontrollers objectAtIndex:0]topViewController] ;
if([mycontrollers objectAtIndex:0]!=pinvc)
Instead of this, try this
PinBoardViewController *pinvc=(PinBoardViewController*)[[mycontrollers objectAtIndex:0]topViewController] ;
if(pinvc isKindOfClass:[PinBoardViewController class]){
// Do ur stuff
}
I called the code below to add Game center user banner pop up at the top of the screen, but it says Game is not recognized by Game Center:
I added this to my addDidFinishLaunching:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error){
if (error ==nil) {
NSLog(#"Success");
} else {
NSLog(#"Fail");
}
}];
For viewing leader boards, what code do I need to add to properly call it?
-(void)viewscores:(SPEvent*)event{
CODE HERE
}
You could try it like that :
GKLeaderboardViewController *leaderboardVC = [[[GKLeaderboardViewController alloc]init]autorelease];
if (leaderboardVC !=nil) {
leaderboardVC.leaderboardDelegate = self;
[self presentViewController:leaderboardVC];
}
I hope it helps :-)
I have a huge problem, I've integrated inmobi in my app, which doesnt support interface orientation, but when i press on ad, view is loaded on top and it rotates, this wouldn't be bad, but the when it rotates, the view becomes distorted, not covering full screen,
maybe someone has had similar problem?
My code:
- (void)showInMobiBanner
{
if (_inMobView == nil)
{
_inMobView = [[IMAdView alloc] init];
_inMobView.delegate = self; //optional
_inMobView.imAppId = kInMobiAppId;
_inMobView.imAdUnit = IM_UNIT_320x50;
_inMobView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
}
if (self.containerView != nil)
{
_inMobView.rootViewController = self.containerView;
}
else
{
_inMobView.rootViewController = self.navigationController;
}
IMAdRequest *request = [IMAdRequest request];
request.isLocationEnquiryAllowed = NO;
_inMobView.frame = CGRectMake(0, 0, 320, 50);
_inMobView.imAdRequest = request;
[_inMobView loadIMAdRequest:request];
[self.view addSubview:_inMobView];
}
Thanks in advance!
It seems you're using an older version of InMobi SDK(3.0.2).
There has been a newer version launched very recently: http://developer.inmobi.com/wiki/index.php?title=IOS_SDK_350
A new method has been introduced:
- (BOOL)shouldRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation;
You can make use of this method in your UIViewController, and tackle orientation changes something like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [imAdView shouldRotateToInterfaceOrientation:interfaceOrientation];
}
Hope this helps!
I have spent the last several hours trying to get this to work and I can't so I need to know if what I am trying to do is the correct thing. Its driving me mad!
My goal is to have a ViewController that detects orientation change. When it's portrait it shows a view with a UITableView, when its landscape it shows a UIView with content that I will programmatically create.
In my parent viewcontroller I have:
- (void)viewDidLoad
{
[super viewDidLoad];
TableDataViewController *tableDataController = [[TableDataViewController alloc]
initWithNibName:#"TableDataViewController"
bundle:nil];
self.tableDataViewController = tableDataController;
[self.view insertSubview: tableDataController.view atIndex:0];
[tableDataController release];
}
This loads my view containing the table view and the controller that goes with it. The user then rotates the device and the function:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toOrientation
duration:(NSTimeInterval)duration
{
if (toOrientation == UIInterfaceOrientationPortrait) {
NSLog(#"PerformAnalysisViewController: Gone to Potrait");
}
if ((toOrientation == UIInterfaceOrientationLandscapeLeft) ||
(toOrientation == UIInterfaceOrientationLandscapeRight)) {
NSLog(#"PerformAnalysisViewController: Gone to Landscape");
// Load new view here
CGRect frame = [[UIScreen mainScreen] applicationFrame];
UIView *horizView = [[[HorizView alloc]
initWithFrame:frame] autorelease];
[self setView:horizView];;
}
}
will trigger depending. However it doesn't trigger? Is this because control has passed to the Subview I have inserted in the viewDidLoad? If so how do I get it back? Do I have to get it to detect orientation and then remove itself from the superview?
If that was then working would the new view be added as I have it above? I have tried reading the Apple documentation but I can't make this work.
All help greatly appreciated.
Mike
I am using the willRotateToInterfaceOrientation method in order to handle UI rotation:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
if( interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ) {
self.backgroundImageView.image = [UIImage imageNamed:#"vertical.png"];
}
else {
self.backgroundImageView.image = [UIImage imageNamed:#"horizontal.png"];
}
}
Please check, that your Info.plist supports more than one orientation and that you have implemented shouldAutorotateToInterfaceOrientation:interfaceOrientation by returning YES.