Friday 28 December 2012

Implementation the Google Analytics for Xcode (2.0 Beta 3)

Download the Analytics SDK for iOS (2.0 Beta 3)



Create a Google Analytics account for MobileApp

       Sign in Google Analytics --> Sign up --> What would you like to track? --> Choose App


If Want More Reference :      

https://developers.google.com/analytics/devguides/collection/ios/v2/                                                          


Step 1: Xcode --> Create New Project  
Step 2: Add headers and libraries to your project

Download the Google Analytics for iOS SDK and add these files from the SDK package to your app:
  • GAI.h
  • GAITracker.h
  • GAITrackedViewController.h
  • GAITransaction.h
  • GAITransactionItem.h
  • libGoogleAnalytics.a
Add the FrameWorks (or) Add the following to your application target's linked libraries:
  • CoreData.framework
  • SystemConfiguration.framework

Step 3: If you want to Track this page add the codings into ViewDidLoad (or) ViewWillAppear


Page View Analytics:

     id<GAITracker> tracker = [[GAI sharedInstancetrackerWithTrackingId:@"UA-XXXX-XX"];
    
     [tracker trackView:@"Sample_Tracking_Page"];

Event Analytics:

    id<GAITracker> tracker = [[GAI sharedInstancetrackerWithTrackingId:@"UA-XXXX-XX"];
   
    [tracker trackEventWithCategory:@"ButtonType"
                         withAction:@"Sample_Action"
                          withLabel:@"Action_Label"
                          withValue:[NSNumber numberWithInt:1]];

Friday 21 December 2012

In View Controller, Add a Another View Controller (Reusability) in Xcode

Main Page:

.h File

#import <UIKit/UIKit.h>

@interface DetailPage : UIViewController
{
    CGRect PopAnimateStart;
    CGRect PopAnimateEnd;
    UIView *same;

    //Passing Array
    NSMutableArray *mut_some;  
}

-(IBAction)show:(id)sender;

-(IBAction)hide:(id)sender;


@end



.m File

#import "DetailPage.h"
#import "Ad_View.h"
#import "Ad_Detail.h"

@interface DetailPage ()
{
    Ad_View *advertisment;
}

@end

@implementation DetailPage

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title=@"Main Page";
    // Do any additional setup after loading the view from its nib.
}

-(IBAction)show:(id)sender
{
    PopAnimateStart=CGRectMake(0, 480, 320, 62);
    PopAnimateEnd=CGRectMake(0, 354, 320, 62);

    
    advertisment = [[Ad_View alloc]init];
    advertisment.delegate=self;
    
    advertisment.stringTitle=@"Ad Name";
    advertisment.stringContent=@"Content for Ads";

    [self.view addSubview:advertisment.view];
    
    same=advertisment.view;

    same.frame = PopAnimateStart;
    same.alpha = 1.0f;
    [UIView animateWithDuration:0.20 delay:0.1f options:UIViewAnimationCurveEaseOut animations:^{same.frame = PopAnimateEnd;} completion:^(BOOL finished){ }];
}

- (void)cancelBtnClicked:(Ad_View *)Ad_ViewController
{
    [same removeFromSuperview];
     same=nil;
}


//Passing Array

- (void)setString:(NSMutableArray *)array
{
    mut_some=[[NSMutableArray alloc]init];
    mut_some= array;
}

- (void)NavigateBtnClicked:(Ad_View *)Ad_ViewController
{
    Ad_Detail *de=[[Ad_Detail alloc]init];
    [self.navigationController pushViewController:de animated:YES];

    //Passing Array

    /* Ad_Detail *addetail=[[Ad_Detail alloc]init];
    addetail.arr_vendor_det=[[NSMutableArray alloc]init];
    [addetail.arr_vendor_det  addObject:[mut_some objectAtIndex:0]];//0
    [addetail.arr_vendor_det  addObject:[mut_some objectAtIndex:1]];//1
    [addetail.arr_vendor_det  addObject:[mut_some objectAtIndex:2]];//2
    [addetail.arr_vendor_det  addObject:[mut_some objectAtIndex:3]];//3
    [addetail.arr_vendor_det  addObject:[mut_some objectAtIndex:4]];//4
    [addetail.arr_vendor_det  addObject:[mut_some objectAtIndex:5]];//5
    [addetail.arr_vendor_det  addObject:[mut_some objectAtIndex:6]];//6
    [addetail.arr_vendor_det  addObject:[mut_some objectAtIndex:7]];//7
    [addetail.arr_vendor_det  addObject:[mut_some objectAtIndex:8]];//8
    [addetail.arr_vendor_det addObject:[mut_some objectAtIndex:9]];//9
    [addetail.arr_vendor_det addObject:[mut_some objectAtIndex:10]];//10
    [addetail.arr_vendor_det addObject:[mut_some objectAtIndex:11]];//11
    addetail.sid=[mut_some objectAtIndex:12];
    addetail.itemid=[mut_some objectAtIndex:13];
    addetail.uname=username;
    addetail.transfer_res=@"vendor";
    [self.navigationController  pushViewController: addetail animated:YES];*/
}

-(void)viewWillDisappear:(BOOL)animated
{
    [same removeFromSuperview];
    same=nil;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end





.Xib File



Mappings:

Show: --- >  Show Button





Add Page:

.h File


#import <UIKit/UIKit.h>
@protocol PopupDelegate;

@interface Ad_View : UIViewController
{
    
    IBOutlet UILabel *MyTitle;
    IBOutlet UILabel *Contents;
    
    NSString *stringTitle;
    NSString *stringContent;


    NSMutableArray *mut_some;
    
}
@property (assign, nonatomic) id <PopupDelegate>delegate;

@property(nonatomic,retain)IBOutlet UILabel *MyTitle;
@property(nonatomic,retain)IBOutlet UILabel *Contents;

@property(nonatomic,retain)NSString *stringTitle;
@property(nonatomic,retain)NSString *stringContent;

- (IBAction)Close:(id)sender;
- (IBAction)Navigate:(id)sender;

@end


@protocol PopupDelegate<NSObject>
@optional

- (void)cancelBtnClicked:(Ad_View *)Ad_ViewController;
- (void)NavigateBtnClicked:(Ad_View *)Ad_ViewController;

//passing array
- (void)setString:(NSMutableArray *)array;

@end




.m File


#import "Ad_View.h"

@interface Ad_View ()

@end

@implementation Ad_View

@synthesize stringContent,stringTitle,MyTitle,Contents;
@synthesize delegate;


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSLog(stringTitle);
    NSLog(stringContent);
    
    MyTitle.text=stringTitle;
    Contents.text=stringContent;
}


- (IBAction)Close:(id)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(cancelBtnClicked:)])
    {
        [self.delegate cancelBtnClicked:self];
    }

}

- (IBAction)Navigate:(id)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(NavigateBtnClicked:)])
    {
        [self.delegate NavigateBtnClicked:self];
        [self.delegate setString:mut_some]; //Passing Array
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end




.Xib File


Mappings:


label --> MyTitle
label --> Contents
Close: -->  "X" button
Navigate: --> Round Rect Button( Invisible- Custom)







Detail Page(only Changed Xib File):

.h File


@interface Ad_Detail : UIViewController

@end



.m File


#import "Ad_Detail.h"

@interface Ad_Detail ()

@end

@implementation Ad_Detail

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end




.Xib File(Only Designed)





Output:



                   

1)Click the Show Button                  2)Click the "X" button to close the AnotherViewController.
                                                                     3)Press the view to Navigate the Detail Page.









In View, Add a Another View (Animation)

.h File

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    IBOutlet UIView *popupview;
    
    CGRect PopAnimateStart;
    CGRect PopAnimateEnd;
    
    IBOutlet UILabel *myTitle;
    IBOutlet UILabel *Contents;
}

@property(nonatomic,retain)IBOutlet UILabel *myTitle;
@property(nonatomic,retain)IBOutlet UILabel *Contents;

-(IBAction)show:(id)sender;

-(IBAction)hide:(id)sender;

@end



.m File

#import "ViewController.h"
#import "DetailPage.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize myTitle,Contents;


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title=@"Add a View in Animated View";
    
// Do any additional setup after loading the view, typically from a nib.

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)show:(id)sender
{
    myTitle.text=@"AssHuss";
    [popupview addSubview:myTitle];

     Contents.text=@"Advertisment or Somthing display contents";
    [popupview addSubview:Contents];
    
    popupview.frame=CGRectMake(0, 354, 320, 62);
    [self.view addSubview:popupview];
    
    PopAnimateStart=CGRectMake(0, 480, 320, 62);
    PopAnimateEnd=CGRectMake(0, 354, 320, 62);

    popupview.frame = PopAnimateStart;
    popupview.alpha = 1.0f;
    [UIView animateWithDuration:0.20 delay:0.1f options:UIViewAnimationCurveEaseOut animations:^{popupview.frame = PopAnimateEnd;} completion:^(BOOL finished){ }];
}

-(IBAction)detail:(id)sender
{
    DetailPage *detail=[[DetailPage alloc]init];
    [self.navigationController pushViewController:detail animated:YES];
}

-(IBAction)hide:(id)sender
{
    [popupview removeFromSuperview];
}

@end


.Xib File


Output:


    
1)click the show button.                                  2)In Bottom Shows the Another View.
                                                                                       3) Click "X" button to Close the View.
                                                                4) If you Want DetailView Press the Detail Disclosure Button.