iOS app crashed while loading ad? - objective-c

Here is my code in viewDidLoad method:
self.bannerView_= [[GADBannerView alloc] initWithFrame:CGRectMake(80,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
self.bannerView_.adUnitID = #"a15037256bd8776";
self.bannerView_.rootViewController =self;
[self.view addSubview:self.bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
My app is designed for landscap mode only. And it works fine in home screen, but when i goes to other screens and trying to load ad(by clicking on banner) the ad is loaded in half part of screen, other half part of screen remains unchanged.
Can anybody help me please.

try following code
self.adBanner= [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
self.adBanner.adUnitID = #"a15037256bd8776";
self.adBanner.delegate = self;
self.adBanner.rootViewController =self;
[self.view addSubview:self.adBanner];
[self.adBanner loadRequest:[self createRequest]];

After more then two days finally i resolved the issue-
Instead to instantiate and call GADBannerView from viewDidLoad of all my view's, I've created a singleton class and use it. see this link for more help

Related

Prevent shutter animation from appearing full screen when using cameraOverlayView [duplicate]

I have a transparent view with a rectangle drawn onto it using CoreGraphics.
When the camera launches the custom overlay view is above the shutter animation.
What you see is the standard camera shutter with the custom rectangle above it.
How do I get it to go in the right place, underneath the shutter animation? I've looked at other sample code but it's for OS 3.1 and doesn't seem to do anything differently.
Here's my code:
-(IBAction)cameraButton{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerCameraDeviceRear]){
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Add the OverlayView with the custom Rectangle
CGRect overlayFrame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
OverlayView *overlayView = [[OverlayView alloc]initWithFrame:overlayFrame];
picker.cameraOverlayView = overlayView;
[overlayView release];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
On the iPad this problem doesn't exist, and the overlay view is behind the shutter animation by default. But on the iPhone, the overlay appears at front.
I've found a solution that worked for me.
You have to set your overlay view as a subview in this method:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (!viewController)
return;
UIView* controllerViewHolder = viewController.view;
UIView* controllerCameraView = [[controllerViewHolder subviews] objectAtIndex:0];
UIView* controllerPreview = [[controllerCameraView subviews] objectAtIndex:0];
[controllerCameraView insertSubview:self.overlayView aboveSubview:controllerPreview];
}
Hope it helps
Original source:
http://www.alexcurylo.com/blog/2009/06/18/uiimagepickercontroller-in-3-0/
You may not do anything else other than what you're already doing; if iOS decides to put your overlay view over the shutter, you'll just have to live with it (unless you want to risk getting rejected from the app store).
As an imperfect workaround, you could start your overlay with alpha=0 and then set alpha to 1 a second or two later. But there is no set time period that the shutter appears for before 'opening' (I think it depends on how long it takes to initialize the camera hardware), so sometimes your interface might not appear until late and sometimes might appear too early.
As of 4.3.3, the shutter animation is broken because elements are displayed on top, and then snap underneath when the animation starts. I've filed this as a Radar: http://openradar.appspot.com/radar?id=1204401
I answered a similar question here. What worked for me (in iOS 6) was setting the cameraOverlayView in navigationController:willShowViewController:animated.
- (void) navigationController:(UINavigationController*) navigationController willShowViewController:(UIViewController*) viewController animated:(BOOL) animated {
self.imagePickerController.cameraOverlayView = ...; // your camera overlay view
}

Camera Shutter shows up in front of custom UIView?

I have a custom UIView that I have created to display my custom buttons and toolBar. When I first called for it to show, the bar is on top of the Shutter (which is good). But after the camera is loaded, the shutter comes in front of it, then opens.
If you look at the native camera.app, it doesn't do this. The toolbar stays there the whole time. Here is my code:
// .h
UIImagePickerController *theCamera;
#property (nonatomic, retain) UIImagePickerController *theCamera;
// .m
theCamera = [[UIImagePickerController alloc] init];
theCamera.delegate = self;
theCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
theCamera.showsCameraControls = NO;
theCamera.toolbar.alpha = 0;
theCamera.navigationBarHidden = YES;
theCamera.toolbarHidden = YES;
theCamera.wantsFullScreenLayout = YES;
theCamera.cameraViewTransform = CGAffineTransformMakeScale(1.25, 1.25);
UIImageView *tabBarBack = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_bar_back.png"]];
tabBarBack.frame = CGRectMake(0, 422, 320, 58);
[customView addSubview:tabBarBack];
theCamera.cameraOverlayView = customView;
[self presentModalViewController:theCamera animated:YES];
Obviously there are more buttons I add to the customView, but you get the concept.
Subscribe to:
AVCaptureSessionDidStartRunningNotification
This is when the iris open animation begins. If you add a cameraOverlayView during this time, it will be properly covered up by the iris. It is posted at the same time as that PL… private notification. This is a documented approach that does not risk app rejection.
AFAIK there is no direct way to do this. If you use cameraOverlay, you will get shutter for the complete screen.
How ever there are some alternate methods (playing around with the view hierarchy) that will help you in making your preview screen as parent view. I am not sure if this approach is correct as per app store guidelines.
have a look at Hide/Show iPhone Camera Iris/Shutter animation for better understanding on how to achieve this.
On iOS 6+, if you've added your controller as the delegate for the UIImagePickerController, this code should ensure that the shutter stays behind your cameraOverlayView:
- (void) navigationController:(UINavigationController*) navigationController willShowViewController:(UIViewController*) viewController animated:(BOOL) animated {
self.imagePickerController.cameraOverlayView = ...; // your camera overlay view
}
I haven't tested on versions of iOS prior to iOS 6 though.

UIScrollView adding UIViewController as a sub view? with UIPageControl

I am currently working on my application and would like to have a UIScrollView and UIPageControl which would allow the user to swipe the screen left and right to get to different view controllers.
I have this working so far, so that I can swipe left and right to see either view controller however I am finding that when one of my UIViewControllers needs to access it delegate nothing happens, for example UITableViewDelegate.
This is the code i have so far in my scrollViewController
CGRect frame2;
frame2.origin.x = self.scrollView.frame.size.width * 1;
frame2.origin.y =30;
frame2.size = self.scrollView.frame.size;
myViewController *vc3 = [[myViewController alloc] initWithNibName:#"myViewController" bundle:nil];
vc3.view.frame = frame2;
[self.scrollView addSubview:vc3.view];
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * 2, self.scrollView.frame.size.height);
One thing I am not able to do also is release [vc3 release]; after adding it to the scrollView the app will just crash.
Any help would be great, also please let me know if I am going about this the wrong way.
Thanks Aaron
By adding v3.view , v3's retain count wont increase. So you cant release v3. you can
[v3.view release];

UIView created in code only draws in portrait mode

I'm trying to add a view to my controller, which is put into landscape mode programmatically with the follwoing code:
- (void)viewDidLoad {
[super viewDidLoad];
//EpisodeView *nextEpisode = [self getNextEpisode];
UIImageView *nextEpisode = [[UIImageView alloc] initWithImage:[UIImage imageNamed: #"default-background.png"]];
CGRect selfBounds = self.view.bounds;
nextEpisode.frame = selfBounds;
[self.view addSubview:nextEpisode];
}
The problem is that the added view draws itself in portrait mode, not in landscape. Can anyone please point out what I could have missed?
When I'm adding the same view using Interface Builder, all works perfectly fine. So, I think, I have missed some property or something like that.
You probably haven't added autoresizingMasks which are by default UIViewAutoresizingNone. IB has different defaults. Set them as needed.

Switch View issue

OK i asked this yesturday but i updated it with more detail as to the problems im having. The problem im having is this. When i run my app, the main view looks fine, just as it is suppose to. But, when i click a button to go to the next view, that view is shifted up about 20pixels. When i goback to the main screen it is shifted up the same.
The only time that my app looks like it is suppose to is when i first load it, once i click a button and start changing views, every view after i leave the mainview that first time is shifted up 20 pixels, even the mainview when i go back to it. I started having this issue when i upgraded from xcode 3.2 to xcode 4.0 beta. There is one way i have found to switchviews that doesnt make the views shift up BUT, i have an issue with this way. I have users input data on view1, on button click it switches to view2 and sends that data from 1 to 2. Using the switchview method that shows my views as they are suppose to be my data dont want to transfer to view2. Using the switchview method that gives me the data transfer from 1 to 2 that i need, it shifts the views up by 20 pixels. below are the examples of what im using.
-- with xcode 4 this way causes my views to shift up 20 pixels where as xcode 3.25 it worked great, had no issues and it transfered the data from view1 to view2.
- (IBAction)calculate:(id)sender {
MaleResultsController *maleResults = [[MaleResultsController alloc] initWithNibName:#"MaleResultsController" bundle:nil];
[UIView beginAnimations:#"flipping view" context:nil];
[UIView setAnimationDuration:.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.view cache:YES];
[self.view addSubview:maleResults.view];
maleResults.displayAge.text = ageInput.text;
maleResults.displayHeight.text = heightInput.text;
maleResults.displayWeight.text = weightInput.text;
NSString *minWeightString = [[NSString alloc] initWithFormat:#"%.0f", [self getMinWeight]];
maleResults.displayMinWeight.text = minWeightString;
[minWeightString release];
NSString *maxWeightString = [[NSString alloc] initWithFormat:#"%.0f", [self getMaxWeight]];
maleResults.displayMaxWeight.text = maxWeightString;
[maxWeightString release];
NSString *maxBodyFatString = [[NSString alloc] initWithFormat:#"%.0f", [self getMaxBodyFatPercentage]];
maleResults.displayMaxBodyFatPercentage.text = maxBodyFatString;
[maxBodyFatString release];
NSString *bodyFatString = [[NSString alloc] initWithFormat:#"%.0f", [self getBodyFatPercentage]];
maleResults.displayBodyFat.text = bodyFatString;
[bodyFatString release];
NSString *abdomenAvgString = [[NSString alloc] initWithFormat:#"%.2f", [self getAbdomenAvg]];
maleResults.abdomenAvg.text = abdomenAvgString;
[abdomenAvgString release];
NSString *neckAvgString = [[NSString alloc] initWithFormat:#"%.2f", [self getNeckAvg]];
maleResults.neckAvg.text = neckAvgString;
[neckAvgString release];
NSString *abNeckFactorString = [[NSString alloc] initWithFormat:#"%.2f", [self getAbNeckFactor]];
maleResults.abdomenNeckFactor.text = abNeckFactorString;
[abNeckFactorString release];
//
// [self.navigationController pushViewController:maleResults animated:YES];
[UIView commitAnimations];
}
-- with xcode 4 this method works to switch views correctly but doesnt transfer textfield input on view1 to label output on view2..
- (IBAction)calculate:(id)sender {
MaleBFCResults *maleBFCresults = [[MaleBFCResults alloc] initWithNibName:#"MaleBFCResults" bundle:nil];
MaleBFCdata *maleBFCData = [[MaleBFCdata alloc] init];
maleBFCresults.maleData = maleBFCData;
maleBFCresults.displayAge = ageInput.text;
maleBFCresults.displayHeight = heightInput.text;
maleBFCresults.displayWeight = weightInput.text;
maleBFCresults.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:maleBFCresults animated:YES];
[maleBFCresults release];
}
I have been searching for ways to fix this issue for a couple weeks now, and havnt been able to find anything to help. I havnt put all my forumlas and calculations into place yet on this new one because i want to make sure that the UI is functioning properly before i spend the time writing out all the code for the calculations. I like the transitions that "modalTransitionStyle" gives me over the "setAnimationTransition". Which is good because it works properly to switch views i just cant get it to transfer data from view1 to view2.
Im sure if i had to i could always revert back to the previous version of xcode but im trying not to have to do have to do that, if anyone has had a similar issue and has a solution i would really appreciate it. there may even be a different way to send data from view1 to view2 that would work that i havnt tried yet, but i havnt found a good way to do that either.
thanks in advance for any help with this issue..
I also faced the same problem of shifting view adn resolved it as below. The following code snippet switches from viewController to msgViewController.
Open the mainWindow.xib and add the UIViewController Object from the Library. Change its class to your Class that handles the specified viewController and then comes the click. Go to the properties section of the Attribute Inspector and set the respective Nib Name for the Controller and now save and exit the IB.
And the code changes to
-(void) flipToBack
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
[viewController.view removeFromSuperview];
[tabBarController.view removeFromSuperview];
[self.window addSubview:[msgViewController view]];
[UIView commitAnimations];
}
Hope this helps you!!
If it does please communicate.
Adjust the frame of those views regarding to the status bar.
However, I wouldn't rely on the application delegate object to handle multiple views. Have a root view controller which takes care of those views.