How to show GADInterstitial in ios project? i am getting error "Request error : no ads to show" but admob is working in my another project.
// ViewController.h
#import <UIKit/UIKit.h>
#import "GADBannerView.h"
#import "GADCustomEventBanner.h"
#import "GADInterstitial.h"
#interface ViewController : UIViewController <GADInterstitialDelegate>
{
UIButton *interstitialButton_;
GADInterstitial *interstitial_;
}
#property(nonatomic, retain) IBOutlet UIButton *interstitialButton;
#property(nonatomic, retain) GADInterstitial *interstitial_;
- (IBAction)showInterstitial:(id)sender;
#end
//ViewController.h
#import "ViewController.h"
#implementation ViewController
#synthesize interstitialButton ;
#synthesize interstitial_;
- (void)dealloc {
interstitial_.delegate = nil;
[interstitial_ release];
[interstitialButton_ release];
[super dealloc];
}
- (void)interstitial:(GADInterstitial *)interstitial
didFailToReceiveAdWithError:(GADRequestError *)error {
// Alert the error.
UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:#"GADRequestError"
message:[error localizedDescription]
delegate:nil cancelButtonTitle:#"Drat"
otherButtonTitles:nil] autorelease];
[alert show];
interstitialButton_.enabled = YES;
}
-(void)interstitialWillPresentScreen:(GADInterstitial *)ad{
NSLog(#"on screen");
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
[interstitial presentFromRootViewController:self];
interstitialButton_.enabled = YES;
[self showInterstitial:nil];
}
- (IBAction)showInterstitial:(id)sender {
self.interstitial_ = [[[GADInterstitial alloc] init] autorelease];
self.interstitial_.delegate = self;
self.interstitial_.adUnitID = MY_ADMOB_KEY; // this key is working in admob //
GADRequest *request = [GADRequest request];
request.testing = YES;
[self.interstitial_ loadRequest: request];
interstitialButton_.enabled = NO;
}
#end
Change the ad size to full screen in the settings in admob website.
self.interstitial_.adUnitID = MY_ADMOB_KEY; // this key is working in admob
check this comment, and replace it with:
self.interstitial_.adUnitID = #"ca-app-pub-xxxxxxxxxxx"; // this key is working in admob
you should get you own adUnitID form admob
Related
I've done some research about my problem without fining a solution. My project compiles with success and launches but but the simulator only shows black. My project was working perfectly before I added googles Interstitials to my app. The following is my code to implement this:
Appdelegate.h
#interface AppDelegate : UIResponder <UIApplicationDelegate,GADInterstitialDelegate> {
UIWindow *window_;
MainViewController *mainController;
GADInterstitial *splashInterstitial_;
}
#property (nonatomic, retain) UIWindow *window;
#property(nonatomic, retain) IBOutlet MainViewController *mainController;
#property(nonatomic, readonly) NSString *interstitialAdUnitID;
- (GADRequest *)createRequest;
Appdelegate.m
#define INTERSTITIAL_AD_UNIT_ID #""
#synthesize mainController = mainViewController_;
#synthesize window = window_;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window setRootViewController:mainViewController_];
[self.window makeKeyAndVisible];
splashInterstitial_ = [[GADInterstitial alloc] init];
splashInterstitial_.adUnitID = self.interstitialAdUnitID;
splashInterstitial_.delegate = self;
[splashInterstitial_ loadAndDisplayRequest:[self createRequest]
usingWindow:self.window
initialImage:[UIImage imageNamed:#"InitialImage"]];
}
- (void)dealloc {
splashInterstitial_.delegate = nil;
}
- (NSString *)interstitialAdUnitID {
return INTERSTITIAL_AD_UNIT_ID;
}
#pragma mark GADRequest generation
- (GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
request.testDevices =
[NSArray arrayWithObjects:
nil];
return request;
}
MainViewController.h
#interface MainViewController : UIViewController <GADInterstitialDelegate> {
UIButton *interstitialButton_;
GADInterstitial *interstitial_;
}
#property (nonatomic, retain) GADInterstitial *interstitial;
#property (nonatomic, retain) IBOutlet UIButton *interstitialButton;
- (IBAction)showInterstitial:(id)sender;
MainViewController.m
#synthesize interstitialButton = interstitialButton_;
#synthesize interstitial = interstitial_;
- (void)interstitial:(GADInterstitial *)interstitial
didFailToReceiveAdWithError:(GADRequestError *)error {
// Alert the error.
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"GADRequestError"
message:[error localizedDescription]
delegate:nil cancelButtonTitle:#"Drat"
otherButtonTitles:nil] ;
[alert show];
interstitialButton_.enabled = YES;
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
[interstitial presentFromRootViewController:self];
interstitialButton_.enabled = YES;
}
- (IBAction)showInterstitial:(id)sender {
self.interstitial = [[GADInterstitial alloc] init] ;
self.interstitial.delegate = self;
AppDelegate *appDelegate =
(AppDelegate *)
[UIApplication sharedApplication].delegate;
self.interstitial.adUnitID = appDelegate.interstitialAdUnitID;
[self.interstitial loadRequest: [appDelegate createRequest]];
interstitialButton_.enabled = NO;
}
In my custom Tab Bar Application, the orientation never seems to change, even if I force rotate the status bar. Here is my code in my AppDelegate:
AppDelegate.h:
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"
#class exampleViewContoller;
#class example1ViewController;
#class example2ViewController;
#class example3ViewController;
#class example4ViewController;
#interface <appname>AppDelegate : NSObject <UIApplicationDelegate, MBProgressHUDDelegate> {
UIWindow *window;
UITabBarController *rootController;
exampleViewContoller *viewController;
example1ViewController *viewController1;
example2ViewController *viewController2;
example3ViewController *viewController3;
example4ViewController *viewController4;
NSMutableData *responseData;
NSMutableArray *tweets;
MBProgressHUD *HUD;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
#property (nonatomic, retain) IBOutlet exampleViewContoller *viewController;
#property (nonatomic, retain) IBOutlet example1ViewController *viewController1;
#property (nonatomic, retain) IBOutlet example2ViewController *viewController2;
#property (nonatomic, retain) IBOutlet example3ViewController *viewController3;
#property (nonatomic, retain) IBOutlet example4ViewController *viewController4;
#property (nonatomic, retain) NSMutableArray *tweets;
#end
AppDelegate.m:
#import "<appname>AppDelegate.h"
#import "exampleViewContoller.h"
#import "example1ViewController.h"
#import "example2ViewController.h"
#import "example3ViewController.h"
#import "example4ViewController.h"
#import "SBJson.h"
#define TMP NSTemporaryDirectory()
#implementation <appname>AppDelegate
#synthesize window = _window;
#synthesize rootController;
#synthesize viewController;
#synthesize viewController1;
#synthesize viewController2;
#synthesize viewController3;
#synthesize viewController4;
#synthesize tweets;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGFloat width = self.rootController.view.bounds.size.width;
CGFloat height = self.rootController.view.bounds.size.height;
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, height)];
UIImage *imageView = [UIImage imageNamed:#"TabBarBackground.png"];
UIColor *kMainColor = [[UIColor alloc] initWithPatternImage:imageView];
[v setBackgroundColor:kMainColor];
[kMainColor release];
[self.rootController.tabBar insertSubview:v atIndex:0];
[imageView release];
[v release];
responseData = [[NSMutableData data] retain];
tweets = [NSMutableArray array];
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:#"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=ENTER_USER_HERE&count=20"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSAssert(nil != self.rootController, #"tab bar controller not hooked up!");
BOOL iPad = NO;
#ifdef UI_USER_INTERFACE_IDIOM
iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#endif
if (iPad) {
self.viewController = [[[exampleViewContoller alloc] initWithNibName:#"exampleViewController_iPad" bundle:nil] autorelease];
self.viewController1 = [[example1ViewController alloc] initWithNibName:#"example1ViewController_iPad" bundle:nil] autorelease];
self.viewController2 = [[[example2ViewController alloc] initWithNibName:#"example2ViewController_iPad" bundle:nil] autorelease];
self.viewController3 = [[[example3ViewController alloc] initWithNibName:#"example3ViewController_iPad" bundle:nil] autorelease];
self.viewController4 = [[[example4ViewController alloc] initWithNibName:#"example4ViewController_iPad" bundle:nil] autorelease];
} else {
self.viewController = [[[exampleViewContoller alloc] initWithNibName:#"exampleViewContoller_iPhone" bundle:nil] autorelease];
self.viewController1 = [[[example1ViewController alloc] initWithNibName:#"example1ViewController_iPhone" bundle:nil] autorelease];
self.viewController2 = [[[example2ViewController alloc] initWithNibName:#"example2ViewController2_iPhone" bundle:nil] autorelease];
self.viewController3 = [[[example3ViewController alloc] initWithNibName:#"example3ViewController_iPhone" bundle:nil] autorelease];
self.viewController4 = [[[example4ViewController alloc] initWithNibName:#"example4ViewController_iPhone" bundle:nil] autorelease];
}
self.rootController.viewControllers = [NSArray arrayWithObjects:self.viewController, self.viewController4, self.viewController1, self.viewController3, self.viewController2, nil];
[viewController release];
[viewController1 release];
[viewController2 release];
[viewController3 release];
[viewController4 release];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
self.window.rootViewController = self.rootController;
#else
[self.window addSubview:rootController.view];
#endif
[self.window makeKeyAndVisible];
HUD = [[MBProgressHUD alloc] initWithView:viewController.view];
[viewController.view addSubview:HUD];
[HUD show:NO];
HUD.delegate = self;
HUD.labelText = #"Loading";
return YES;
}
//[---CODE CLIP---]
- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation {
CGFloat width = self.rootController.view.bounds.size.width*2;
CGFloat height = self.rootController.view.bounds.size.height;
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, height)];
UIImage *imageView = [UIImage imageNamed:#"TabBarBackground.png"];
UIColor *kMainColor = [[UIColor alloc] initWithPatternImage:imageView];
[v setBackgroundColor:kMainColor];
[kMainColor release];
[self.rootController.tabBar insertSubview:v atIndex:0];
[imageView release];
[v release];
}
- (void)hudWasHidden {
[HUD removeFromSuperview];
}
//[---CODE CLIP---]
- (void)dealloc
{
[_window release];
[rootController release];
[HUD release];
[super dealloc];
}
#end
The problem is that when I rotate the device in iOS Simulator, the application won't rotate. Any ideas would be much appreciated!
UPDATE
I have also noticed that the launch image is also not rotating (for iPad that is - iPhone doesn't do landscape launch images).
NOTE FOR JMANS
I overrode UITabBarController:
#implementation UITabBarController (MyApp)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if(self.selectedIndex==4)
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
else
return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end
I would start by including this in all of your view controllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Also, make sure that you are supporting multiple orientations in your Info.plist.
Tab Bar Controllers and View Rotation
Tab bar controllers support a portrait orientation by default and do not rotate to a landscape orientation unless all of the contained view controllers support such an orientation. When a device orientation change occurs, the tab bar controller queries its array of view controllers. If any one of them does not support the orientation, the tab bar controller does not change its orientation.
The Tabs in my Tab Bar don't seem to be showing up. Here is my App Delegate code:
(appname)AppDelegate.h:
#import <UIKit/UIKit.h>
#class TwitterViewContoller;
#interface <appname>AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *rootController;
TwitterViewContoller *viewController;
NSMutableData *responseData;
NSMutableArray *tweets;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
#property (nonatomic, retain) IBOutlet TwitterViewContoller *viewController;
#property (nonatomic, retain) NSMutableArray *tweets;
#end
(appname)AppDelegate.m:
#import "<appname>AppDelegate.h"
#import "TwitterViewContoller.h"
#import "SBJson.h"
#implementation <appname>AppDelegate
#synthesize window = _window;
#synthesize rootController;
#synthesize viewController;
#synthesize tweets;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
CGFloat width = self.rootController.view.bounds.size.width;
CGFloat height = self.rootController.view.bounds.size.height;
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, height)];
UIImage *imageView = [UIImage imageNamed:#"TabBarBackground.png"];
UIColor *kMainColor = [[UIColor alloc] initWithPatternImage:imageView];
[v setBackgroundColor:kMainColor];
[kMainColor release];
[self.rootController.tabBar insertSubview:v atIndex:0];
[imageView release];
[v release];
responseData = [[NSMutableData data] retain];
tweets = [NSMutableArray array];
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:#"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=USER_NAME_ID"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSAssert(nil != self.rootController, #"tab bar controller not hooked up!");
self.viewController = [[[TwitterViewContoller alloc] initWithNibName:#"TwitterViewContoller_iPhone" bundle:nil] autorelease];
self.rootController.viewControllers = [NSArray arrayWithObject:self.viewController];
// this is now the Right Way to set the root view for your app, in iOS 4.0 and later
self.window.rootViewController = self.rootController;
[self.window makeKeyAndVisible];
return YES;
}
#pragma mark NSURLConnection delegate methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSArray *allTweets = [responseString JSONValue];
[viewController setTweets:allTweets];
}
- (void)dealloc {
[_window release];
[rootController release];
[viewController release];
[super dealloc];
}
#end
I believe the problem is in application didFinishLaunchingWithOptions: as the only recent changes I have made to App Delegate have been these lines:
NSAssert(nil != self.rootController, #"tab bar controller not hooked up!");
self.viewController = [[[TwitterViewContoller alloc] initWithNibName:#"TwitterViewContoller_iPhone" bundle:nil] autorelease];
self.rootController.viewControllers = [NSArray arrayWithObject:self.viewController];
// this is now the Right Way to set the root view for your app, in iOS 4.0 and later
self.window.rootViewController = self.rootController;
[self.window makeKeyAndVisible];
(EDIT: removing the 2nd and 3rd line above fixes the problem but I need to have them). Any ideas?
Make a Property of your other ViewControllers and synthesize them in your implementation file (.m). Also import them in your AppDelegate.m file. Here is what your header (.h) file will look like (rootController is your TabBarController):
#import <UIKit/UIKit.h>
#class TwitterViewContoller;
#class OtherViewController;
#interface <appname>AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *rootController;
TwitterViewContoller *viewController;
OtherViewController *viewController1;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
#property (nonatomic, retain) IBOutlet TwitterViewContoller *viewController;
#property (nonatomic, retain) IBOutlet OtherViewController *viewController1;
#end
And the first few lines of your implementation (.m) file:
#import "<appname>AppDelegate.h"
#import "TwitterViewContoller.h"
#import "OtherViewController.h"
#implementation <appname>AppDelegate
#synthesize window = _window;
#synthesize rootController;
#synthesize viewController;
#synthesize viewController1;
Add additional allocs and inits for all your ViewControllers:
self.viewController = [[[TwitterViewContoller alloc] initWithNibName:#"TwitterViewContoller_iPhone" bundle:nil] autorelease];
self.viewController1 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController_iPhone" bundle:nil] autorelease];
Then replace this:
self.rootController.viewControllers = [NSArray arrayWithObject:self.viewController];
with this:
self.rootController.viewControllers = [NSArray arrayWithObjects:self.viewController, self.viewController1, nil];
This is so you can add more than one UIViewController to your TabBar Controller.
Then of course, release:
[viewController release];
[viewController1 release];
And under each class for your ViewControllers, under the -initWithNibName method add this inside the if (self) statement:
UITabBarItem *tabBarItem = [self tabBarItem];
UIImage *tabBarImage = [UIImage imageNamed:#"IMAGE NAME.png"];
[tabBarItem setImage:tabBarImage];
[tabBarItem setTitle:#"TITLE GOES HERE"];
Run your application and it should be working now!
I am stuck in a tutorial, trying to switch views with a toolbar. My code builds fine and I put some alerts in to check the toolbar was working, and it is. But my subviews I am inserting are just not showing up at all. Can anybody help please?
Here is my main controller code..
MainViewController.h is
#import
#class FlavourPickerView;
#class ShakeView;
#class ResultsView;
#interface MainViewController : UIViewController {
IBOutlet FlavourPickerView *flavourPickerView;
IBOutlet ShakeView *shakeView;
IBOutlet ResultsView *resultsView;
}
#property (retain,nonatomic) FlavourPickerView *flavourPickerView;
#property (retain,nonatomic) ShakeView *shakeView;
#property (retain,nonatomic) ResultsView *resultsView;
-(IBAction)loadFlavourPickerView:(id)sender;
-(IBAction)loadShakeView:(id)sender;
-(IBAction)loadResultsView:(id)sender;
-(void)clearView;
#end
and here is MainViewController.m
#import "MainViewController.h"
#import "FlavourPickerView.h"
#import "ShakeView.h"
#import "ResultsView.h"
#implementation MainViewController
#synthesize flavourPickerView;
#synthesize shakeView;
#synthesize resultsView;
-(IBAction)loadFlavourPickerView:(id)sender{
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:#"Flavour selected"
message:#"Seems to work"
delegate:nil
cancelButtonTitle:#"OK!"
otherButtonTitles:nil];
[alertDialog show];
[alertDialog release];
[self clearView];
[self.view insertSubview:flavourPickerView.view atIndex:10];
}
-(IBAction)loadShakeView:(id)sender{
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:#"Shaker selected"
message:#"Seems to work"
delegate:nil
cancelButtonTitle:#"OK!"
otherButtonTitles:nil];
[alertDialog show];
[alertDialog release];
[self clearView];
[self.view insertSubview:shakeView.view atIndex:0];
}
-(IBAction)loadResultsView:(id)sender{
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:#"Results selected"
message:#"Seems to work"
delegate:nil
cancelButtonTitle:#"OK!"
otherButtonTitles:nil];
[alertDialog show];
[alertDialog release];
[self clearView];
[self.view insertSubview:resultsView.view atIndex:0];
}
-(void)clearView{
if(flavourPickerView.view.superview){
[flavourPickerView.view removeFromSuperview];
}else if(shakeView.view.superview){
[shakeView.view removeFromSuperview];
}else{
[resultsView.view removeFromSuperview];
}
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[self loadFlavourPickerView:nil];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[flavourPickerView release];
[shakeView release];
[resultsView release];
[super dealloc];
}
#end
and here is an example of one of the other views, starting with FlavourPickerView.h
#import
#interface FlavourPickerView : UIViewController {
}
#end
and FlavourPickerView.m
#import "FlavourPickerView.h"
#implementation FlavourPickerView
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
There is also a nib for the flavourPickerView and I have added subviews into my mainView, with the Class set to FlavourPickerView and nib name is FlavourPickerView.xib.
Are flavourPickerView, shakeView, and resultsView properly initialized when you add their view to this UIViewController view?
Another thing: avoid to call a UIViewController just 'XXXView', try instead 'XXXViewController'
Hey Guys I have the following simple Code :
WhereAmIViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface WhereAmIViewController : UIViewController <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
CLLocation *startingPoint;
IBOutlet UILabel *latitudeLabel;
IBOutlet UILabel *longitudeLabel;
IBOutlet UILabel *magneticHeading;
}
#property (retain, nonatomic) CLLocationManager *locationManager;
#property (retain, nonatomic) CLLocation *startingPoint;
#property (retain, nonatomic) UILabel *latitudeLabel;
#property (retain, nonatomic) UILabel *longitudeLabel;
#property (nonatomic, retain) UILabel *magneticHeading;
#end
WhereAmIViewController.m
#import "WhereAmIViewController.h"
#implementation WhereAmIViewController
#synthesize locationManager;
#synthesize startingPoint;
#synthesize latitudeLabel;
#synthesize longitudeLabel;
#synthesize magneticHeading;
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
NSString *magneticstring = [[NSString alloc] initWithFormat:#"%0.0f°",
newHeading.magneticHeading];
magneticHeading.text = magneticstring;
[magneticstring release];
}
#pragma mark -
-(void)viewDidLoad
{
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[locationManager startUpdatingHeading];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[locationManager release];
[startingPoint release];
[latitudeLabel release];
[longitudeLabel release];
[super dealloc];
}
#pragma mark -
#pragma mark CLLocationManagerDelegate Methods
-(void)locationManager:(CLLocationManager *)manger
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
if(startingPoint == nil)
self.startingPoint = newLocation;
NSString *latitudeString = [[NSString alloc] initWithFormat:#"%g",newLocation.coordinate.latitude];
latitudeLabel.text = latitudeString;
[latitudeString release];
NSString *longitudeString = [[NSString alloc] initWithFormat:#"%g",newLocation.coordinate.longitude];
longitudeLabel.text = longitudeString;
[longitudeString release];
}
-(void)longitudeManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSString *errorType = (error.code ==kCLErrorDenied)?#"Access Denied":#"Unknown Error";
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Error Getting Location!" message:errorType delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
#end
So that's what I am displaying on screen .. I just wanted to know how get these 3 labels as an overview for the camera . I have refered to http://www.musicalgeometry.com/archives/821
But having trouble as mine is "View Based app" and the tutorial uses a "Windows Based app" template .. How can I configure this code to get the camera overlay ?
P.S: The background color is : noColor (transparent ).
Thank You !
You need a UIImagePickerController, and then you create a UIView and add your 3 labels in appropriate locations in subview then you can call, picker.cameraOverlayView = YOUR_UI_VIEW and picker.showsCameraControls = NO. If you already set up everything inside your WhereAmIViewController then you can do picker.cameraOverlayView = whereAmIVC.view