How to detect if iAd loaded using an "if" statement - ios

I have a code that creates a button depending whenever a user has an iphone 4 or 5 and whenever they purchased an IAP to remove ads. Below is the code for it:
if ((int)[[UIScreen mainScreen] bounds].size.height == 568)
{
// This is iPhone 5 screen
if (intvalue == 1) {
//No Ads
self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
self.infoButton.tintColor = [UIColor whiteColor];
self.infoButton.center = CGPointMake(289, 495);
[self.view addSubview:self.infoButton];
}
else{
//Yes Ads
self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
self.infoButton.tintColor = [UIColor whiteColor];
self.infoButton.center = CGPointMake(289, 451);
[self.view addSubview:self.infoButton];
}
} else {
// This is iPhone 4/4s screen
if (intvalue == 1|) {
//No Ads
self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
self.infoButton.tintColor = [UIColor whiteColor];
self.infoButton.center = CGPointMake(289, 429);
[self.view addSubview:self.infoButton];
}
else{
//Yes Ads
self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
self.infoButton.tintColor = [UIColor whiteColor];
self.infoButton.center = CGPointMake(289, 400);
[self.view addSubview:self.infoButton];
}
}
However one issue for me occurs when the ads don't load. The button is still placed higher in the screen that when it should be. How do I detect if ads did not load place the button in the location of when ads are removed?

You need to implement the ADBannerViewDelegate Protocol in your class.
https://developer.apple.com/library/ios/documentation/userexperience/Reference/ADBannerViewDelegate_Ref/Reference/Reference.html
When an ad is loaded, Apple will call bannerViewDidLoadAd.
When an ad is not loaded, Apple will call bannerView:didFailToReceiveAdWithError:
So for a temporary fix, in your code I would always draw the button as if an ad did not load. Then when the ad does load (inside bannerViewDidLoadAd) move the button down and display the ad.

Related

When UIButton is toggled Map View isn't filing the whole screen iOS

I am new to using MapView in iOS, here's my situation:
When I toggle the nearby button it will redirect me to map view:
Then when I toggle the List View button, it will display a UItableView with a Map Button. Then finally, when I toggle the map button it will display the Map View.
My problem is, when in list view then I scrolled down then toggle the map view button the map view doesn't fill the whole screen (please see image for reference):
Here's what i have so far:
This is how i initiate the Map:
- (void)viewDidLoad {
jobsMapView = [[MTJobsMapView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
jobsMapView.showsUserLocation = YES;
jobsMapView.zoomEnabled = YES;
jobsMapView.rotateEnabled = NO;
jobsMapView.parentViewController = self;
jobsMapView.delegate = jobsMapView;
// Set up buttons but hide them
showListViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
showListViewButton.frame = CGRectMake(self.view.frame.size.width-58, self.view.frame.size.height-159, 50.0, 36.0);
[showListViewButton addTarget:self action:#selector(toggleNearbyView:) forControlEvents:UIControlEventTouchUpInside];
[showListViewButton setImage:[UIImage imageNamed:#"list.png"] forState:UIControlStateNormal];
[self.view addSubview:showListViewButton];
showMapViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
showMapViewButton.frame = CGRectMake(self.view.frame.size.width-58, self.view.frame.size.height-159, 50.0, 36.0);
[showMapViewButton addTarget:self action:#selector(toggleNearbyView:) forControlEvents:UIControlEventTouchUpInside];
[showMapViewButton setImage:[UIImage imageNamed:#"icon_map.png"] forState:UIControlStateNormal];
[self.view addSubview:showMapViewButton];
// Default mapView is shown in Nearby View
showListViewButton.hidden = YES;
showListViewButton.enabled = NO;
showMapViewButton.hidden = YES;
showMapViewButton.enabled = NO;
self.listViewSelected = NO;
}
- (IBAction)toggleNearbyView:(UIButton *)sender {
self.listViewSelected = !self.listViewSelected;
if (self.listViewSelected) {
self.title=[NSString stringWithFormat:#"Nearby Jobs (%d)",[[self.jobsDictionary objectForKey:#"sub_slots"] count]];
// TableView is shown, so showMapViewButton for user to select MapView
showMapViewButton.hidden = NO;
showMapViewButton.enabled = YES;
showListViewButton.hidden = YES;
showListViewButton.enabled = NO;
[jobsMapView removeFromSuperview];
} else {
showListViewButton.hidden = NO;
showListViewButton.enabled = YES;
showMapViewButton.hidden = YES;
showMapViewButton.enabled = NO;
self.title=[NSString stringWithFormat:#"Nearby Jobs (%d)",[[self.FilterDictionary objectForKey:#"sub_slots"] count]];
[jobsMapView mapViewWithJobsDisplayed:self.FilterDictionary andUserLocation:xapp.self.userLocation andUserCoordinates:xapp.self.userLocationCoordinates];
[self.jobsTableView addSubview:jobsMapView];
}
}
what am doing wrong here?
Any help will be appreciated..
thanks...
Comment This line.
self.listViewSelected = !self.listViewSelected;
in toggleNearbyView method

Unable to set offset value for last item of carousel?

I am using iCarousel in my application to show images which is coming from web service with linear type carousel. When user scroll end of the carousel if no images available from web service i am adding one carousel with button.
What i am doing is when no data available from web service i am setting boolean value yes(isNoImagesAvailable == YES).then i am adding one extra carousel item on bottom.
Below is example code to understand how i am doing
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
self.carousel.contentOffset = CGSizeMake(0, (213 - self.carousel.frame.size.height) * 0.5);
}
else
{
self.carousel.contentOffset = CGSizeMake(0, (200 - self.carousel.frame.size.height) * 0.5);
}
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
//Here i am increasing carousel count by 1 if no images available
if (isNoImagesAvailable)
{
return images.count+1;
}
else
{
return images.count;
}
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
//create new view if no view is available for recycling
if(index < images.count )
{
if (view == nil)
{
//this `if (view == nil)
{`
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
((UIImageView *)view).image =// Here loading images from web service
view.contentMode = UIViewContentModeCenter;
}
else
return view;
}
// if no images are available adding one button with text "No data available"
else
{
UIView * endimageView = nil;
if (view == nil)
{
endimageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150.0f,50.0f)];
endimageView.backgroundColor =[UIColor clearColor];
endimageView.contentMode = UIViewContentModeCenter;
UIButton *noDataButton =[UIButton buttonWithType:UIButtonTypeCustom];
noDataButton.frame =CGRectMake(0, 0, 150, 40);
noDataButton.userInteractionEnabled=YES;
[noDataButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[noDataButton setTitle:#"No data available" forState:UIControlStateNormal];
[noDataButton addTarget:self action:#selector(popToHomePage) forControlEvents:UIControlEventTouchUpInside];
noDataButton.backgroundColor =[UIColor whiteColor];
[endingDealView addSubview: noDataButton s];
}
return endingDealView;
}
Here the problem is when user on bottom of the screen when scroll up "No data available" button is going below the navigation bar. How can make "endimageView" carousel item offset to exact below the navigation bar.
Let me know any information need from my side
Thanks

Screen with different options for autorotate

I have a view with a collection of images. If the image is clicked then I show it full screen on same screen. When the phone is rotated, I want it to autorotate only if the image is full screen, otherwise no. I have isZoomedIn that is true when a image is full screen else false.
I have implemented the method shouldAutorotate. If it is zoomed-in it returns Yes otherwise No but it doesn't work even if isZoomedIn is set corectly.
I created a demo having a button to pop-up a new view on same screen similar to your image selection on clicking.
-(IBAction)buttonClicked:(id)sender //Called when button tapped to pop-up a new view.
{
flag = YES; //Flag check for rotating new view ,i.e., YES.
newView = [[UIView alloc] initWithFrame:CGRectMake(5, 5, self.view.frame.size.width-10, self.view.frame.size.height-10)];
[newView setBackgroundColor:[UIColor blueColor]];
closeNewViewBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 30, 100, 50)];
[closeNewViewBtn addTarget:self action:#selector(removeView) forControlEvents:UIControlEventTouchUpInside];
[closeNewViewBtn setTitle:#"Remove View" forState:UIControlStateNormal];
[closeNewViewBtn setBackgroundColor:[UIColor redColor]];
[newView addSubview:closeNewViewBtn];
[self.view addSubview:newView];
}
-(void)removeView //Called to remove view or in your case change it for removing the image or what ever you doing.
{
flag = NO;
[newView removeFromSuperview];
}
-(BOOL)shouldAutorotate //Rotation check
{
if(flag)
return YES; //Will rotate when new view is present.
else
return NO; //Will not rotate when new view is not present.
}
This will get you required needs.

UIButton is not being recognized when I touch it due to the UILongPress

I am trying to make a game that recognizes when a person is holding down his/her finger and moves a player when it is held down. On top of this, I am trying to create a back button in order to go back to the home screen.
This is my code for these two things:
- (void) didMoveToView:(SKView *)view {
holdingFinger = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongPress:)];
holdingFinger.minimumPressDuration = 0;
holdingFinger.numberOfTapsRequired = 0;
holdingFinger.numberOfTouchesRequired = 1;
holdingFinger.allowableMovement = 100;
[view addGestureRecognizer:holdingFinger];
changeScene = [UIButton buttonWithType:UIButtonTypeSystem];
[changeScene addTarget:self action:#selector(changeScene) forControlEvents:UIControlEventTouchUpInside];
[changeScene setTitle:#"Home" forState:UIControlStateNormal];
changeScene.backgroundColor = [UIColor whiteColor];
changeScene.frame = CGRectMake(410, 0, 70, 30);
[self.view addSubview:changeScene];}
- (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
//NSLog(#"isHoldingDown = YES");
isHoldingDown = YES;
} else if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
//NSLog(#"isHoldingDown = NO");
isHoldingDown = NO;
}}
- (void) changeScene {
[changeScene removeFromSuperview];
SKScene* nextScene = [[ATOpenScene alloc] initWithSize:self.size];
SKTransition* transition = [SKTransition doorsOpenVerticalWithDuration:0.5];
[self.view presentScene:nextScene transition:transition];
}
Both of these things work as I want them to on their own, however, when I put them both in, I am unable to press the button. Is there a simple fix / a careless mistake that I am making here? And if so what would it be? Thanks for the help.
Your holdingFinger.minimumPressDuration = 0; should be greater than 0 to work with the tapgesture

Display screen for iOS6 and iOS7 in simulator is different

My application i will give deployment target 6.1 so in 7.0 display and 6.1 display screen different so how to adjust the size in both 6.1 and 7.0
Main UI difference in iOS 6 and iOS 7 is that status bar is included inside the viewcontroller in iOS 7. it means your view controller is 20 px greater than iOS6. you have to adjust your items.
First design your items according to iOS 6 which is better way and you must have a lot of practice of doing that, now set Δy to 20 for every item.
Or design your items according to iOS 7 and set Δy to -20
use ios7.0 and later and then handle the secrren size using autolayout
Add this code in your AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Whatever your code goes here
if(kDeviceiPad){
//adding status bar for IOS7 ipad
if (IS_IOS7) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 1024, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
}
}
else{
//adding status bar for IOS7 iphone
if (IS_IOS7) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //You can give your own color pattern
[self.window.rootViewController.view addSubview:addStatusBar];
}
return YES;
}
It may be helpful
-(void)adjustFrameForiOS7:(UIView*)v
{
if([UIDevice currentDevice].systemVersion.floatValue >=7.0)
{
[v setFrame:CGRectMake(v.frame.origin.x, v.frame.origin.y+20, v.frame.size.width, v.frame.size.height)];
}
else
{
[v setFrame:CGRectMake(v.frame.origin.x, v.frame.origin.y, v.frame.size.width, v.frame.size.height)];
}
}

Resources