Friday, 26 April 2013

AdMob Integration In Ios Applicaton


How to AdMob integrate in your application in iPhone

This is the AdMob example. In this example we will see how to integrate AdMob in the application. I will show you the easiest way to integrate AdMob in the application.
Step 1: Open the Xcode, Create a new project using View base application. Give the application “AdmobiPhone”.
Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.
Step 3: Xpand classes and notice Interface Builder created the AdmobiPhoneViewController class for you and generated a separate nib, AdmobiPhoneViewController.xib for the “AdmobiPhone”.
Step 4: First go to www.admob.com site, we need to register in this site for AdMob. After login, goto Sites &Apps –> Add site/App –> Select a site or app type –> Select iPhone App (See figure 1)



 Next we need to full fill details (See figure 2)
Now you can download the AbMob SDK, it is required for publishing Ads and drag drop into the Xcode project.
 
Step 5: We need to add framework in project, so select the framework -> add New Framework -> Select AudioTollbox.framework, MediaPlayer.framework,MessageUI.framework and SystemConfiguration.framework add in the Framework folder.AdMobSDKFiles
 and right click on the any of file and select add files to the Some app name select the AdMob Files Folder

Step 6: We need to add one background image in the project.

Step 7: Open the AdmobiPhoneViewController.h file, in this file we need to import GADBannerView.h file and create a instance of GADBannerView class. So make the following changes:
#import <UIKit/UIKit.h>
#import "GADBannerView.h" @interface AdmobiPhoneViewController : UIViewController {
         GADBannerView *AbMob;
}
@end
Step 8:  Now open the AdmobiPhoneViewController.m file and make the following changes in the file.
#import "AdmobiPhoneViewController.h"
#define AdMob_ID @"a14dccd0fb24d45" // You can get this id from www.admob.com. This is Publisher ID @implementation AdmobiPhoneViewController
- (void)dealloc
{
    AbMob.delegate = nil;
    [AbMob release];
    [super dealloc];
}
- (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.
}
#pragma mark – View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
      AbMob = [[GADBannerView alloc]
                   initWithFrame:CGRectMake(0.0,
                                            self.view.frame.size.height -
                                            GAD_SIZE_320x70.height,
                                            GAD_SIZE_320x70.width,
                                            GAD_SIZE_320x70.height)];
   
     AbMob.adUnitID = AdMob_ID;
     AbMob.rootViewController = self;
    [self.view addSubview:AbMob];
 
   
       GADRequest *r = [[GADRequest alloc] init];
    r.testing = YES;
    [AbMob loadRequest:r];
   
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
   - (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end

Step 9: Now compile and run the application on the device.


You can Download SourceCode from here

Wednesday, 27 February 2013


Disabling the ARC in Xcode 4.2





With Xcode 4.2 (iOS 5) Apple introduce ARC (Automatic Reference Counting) to help with memory management. Basically you no longer need to call retain or release. However current examples/books (and (open source) libraries) are still doing it. This leads to (annoying) errors like:
ARC forbids explicit message send of ‘retain’
To get rid of this error you need to disable ARC, but how?
  1. Select your project file.
  2. You should be in the “Build settings” tab. Select the “levels” option (default is “Combined”)
  3. There’s a search field to the right of “Combined”. Enter “Automatic”
  4. Second group should be “Apple LLVM Compiler 3.0 – Language”. Second line under that controls ARC.
  5. Click that line, then in the middle column (where it says “yes”), click and choose “no”.
Now the error is gone. Great!

Monday, 25 February 2013

Creating Your First iPhone Application with Interface Builder 

The first thing we are going to do is get our project started, which we do in Xcode. This is easily done, go to File > New Project and choose "Application" under iPhone OS. Click "Choose" and give it a name and we're good to go.

















Well, now it is time to open up Interface Builder. The first item on the agenda is to create our main view. Go to File > New, select User Interface on the left and choose "View XIB", I named mine SimpleUIView. Once created we can add our text input, label, and button to it. I also update the background color on the view to give it a little bit of personality. Below is a video demonstrating setting up the interface.


The next step is creating the view controller that will handle the bulk of our logic. We are going to go back to Xcode to handle this. We add the file by going to File > New File, select Cocoa Touch Class on the left and then choose "UIViewController subclass" as the template. I also made sure that "With XIB for user interface" wasn't selected. Once chosen I named mine "SimpleUIViewController".
Starting in the header file "SimpleUIViewController.h", we add the properties and instance variables we are going to use for our application. We add a variable and property for the label and text input. In order for Interface Builder to know about these we need to mark them as an IBOutlet, as seen below. We also add a variable and property for storing the name entered. A method for changing the label that will be hooked up to our button is also added. The method needs to be tagged as an IBAction, again for Interface Builder. The final item for the header is adding that our controller implements the UITextFieldDelegate.


#import <UIKit/UIKit.h>

@interface SimpleUIViewController : UIViewController <UITextFieldDelegate> {
  UITextField *textInput;
  UILabel *label;
  NSString *name;
}

@property (nonatomic, retain) IBOutlet UITextField *textInput;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, copy) NSString *name;

- (IBAction)changeGreeting:(id)sender;

@end

The implementation file "SimpleUIViewController.m" starts with a number of commented out methods. We don't need any of them so you can delete them if you would like. To have Objective-C handle creating our getters and setters we use @synthesize. Our properties need to have their memory released, this is done inside the overridden -(void)dealloc method. With these updates our file looks like the following:

#import "SimpleUIViewController.h" 
 @implementation SimpleUIViewController 
 @synthesize textInput; 
 @synthesize label;
  @synthesize name;

  - (void)didReceiveMemoryWarning
 {  
[super didReceiveMemoryWarning];
  // Release anything that's not essential, such as cached data 
 } 
 - (void)dealloc 
 { 
 [textInput release]; 
 [label release]; 
 [name release]; 
 [super dealloc]; 
 } 
 @end
 
Along with the above we also need to implement our action method and a text field delegate method. The first changeGreeting handles updating the label with our hello phrase. It starts by saving the input from the user in our name property. Then it will default the name to "Inigo Montoya" if the name is of length 0 (nothing was entered). After this we create a greeting and update it with the phrase of the day. The label's text is then updated and a tib bit of clean up is required.
The second function is not nearly as complex, it simply checks to see if the passed in text field is equal to our property. If this is the case we return YES which in turn closes the software keyboard.


#import "SimpleUIViewController.h"

@implementation SimpleUIViewController

@synthesize textInput;
@synthesize label;
@synthesize name;

- (IBAction)changeGreeting:(id)sender {
  self.name = textInput.text;

  NSString *nameString = name;
  if([nameString length] == 0) {
    nameString = @"Inigo Montoya";
  }
  NSString *greeting = [[NSString alloc] 
                        initWithFormat:@"Hello, my name is %@!", nameString];
  label.text = greeting;
  [greeting release];
}

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
  if(theTextField == textInput) {
    [textInput resignFirstResponder];
  }
  return YES;
}

- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning]; 
  // Release anything that's not essential, such as cached data
}

- (void)dealloc {
  [textInput release];
  [label release];
  [name release];
  [super dealloc];
}

@end
 
Having the controller created is only one part of it, we now have to do two more things to have it actually work. The first is to update our application delegate ("SimpleUIAppDelegate.h" and "SimpleUIAppDelegate.m") to create the controller and initialize it.
The header for the delegate needs to have an instance variable and property created for our controller. In order for this to work correctly we need to tell the file about our class using @class SimpleUIViewController. This leaves us with a pretty simple header file.


#import <UIKit/UIKit.h>

@class SimpleUIViewController;

@interface SimpleUIAppDelegate : NSObject <UIApplicationDelegate> {
  UIWindow *window;
  SimpleUIViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) SimpleUIViewController *viewController;

@end
 
The default implementation of the application delegate already overrides applicationDidFinishLaunching which is where we are going to allocate and initialize our controller. The controller is initialized using the instance method initWithNibName with the first parameter equal to the name our view nib which is equal to the name of our view, in my case "SimpleUIView". Before leaving the file we need to make sure we @synthesize our property and import the SimpleUIViewController header. The last thing we need to do in the implementation file is make sure to import the "SimpleUIViewController.h" file.

#import "SimpleUIAppDelegate.h"
#import "SimpleUIViewController.h"

@implementation SimpleUIAppDelegate

@synthesize window;
@synthesize viewController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

  // Override point for customization after application launch
  SimpleUIViewController *aViewController = [[SimpleUIViewController alloc] 
                                             initWithNibName:@"SimpleUIView" 
                                             bundle:[NSBundle mainBundle]];
  self.viewController = aViewController;
  [aViewController release];

  [window addSubview:[viewController view]];

  // Override point for customization after application launch
  [window makeKeyAndVisible];
}

- (void)dealloc {
  [window release];
  [super dealloc];
}

@end
 
The final piece is done inside of Interface Builder. We have to open up
our view again and this time literally connect our view controller to
our view components. Once you have the view ("SimpleUIView.xib") open
again in Interface Builder we need to set the File's Owner to be an
instance of our controller. This is done in the identity inspector, once
completed we have to drag lines from the connection inspector the
appropriate items on our view.
 

SampleCode.zip 




 

 


Hi welcome to ios Application developer Rockzz
Hello ios application developers