Pages

Monday 19 January 2015

Check Box Button in iOS





I have created a simplest way to create a checkbox in iOS..

download the source code -


In that code there is three way we can use the checkbox in iOS..download the code and refer it.

and


1 more way is just you can...

 // when you setup your button, set an image for the selected and normal states
        [myCheckBoxButton setImage:nonCheckedImage forState:UIControlStateSelected];
        [myCheckBoxButton setImage:nonCheckedImage forState:UIControlStateNormal];
        
       

  - (void)myCheckboxToggle:(id)sender
     {
            myCheckboxButton.selected = !myCheckboxButton.selected; // toggle the selected property, just a simple BOOL

     }

























Thursday 8 January 2015

how detect ios version






Following way we can detect iOS version 


   NSLog(@"[UIDevice currentDevice].systemName: %@",[UIDevice currentDevice].systemName);
    NSLog(@"[UIDevice currentDevice].systemVersion: %@",[UIDevice currentDevice].systemVersion);
    
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
    {
       
        NSLog(@"older than iOS 7 code here");
    } else
    {
        
            NSLog(@"iOS 7 and above  code here");

    }

Wednesday 7 January 2015

How can I detect ,my app is running in the iphone simulator?





Following way we can determine the our App is run in simulator


    NSString *model = [[UIDevice currentDevice] model];
    if ([model isEqualToString:@"iPhone Simulator"])
    {
        
         NSLog(@"device is simulator");
    }



or

NSLog(@"My device is  %@",[[UIDevice currentDevice] model]);

Tuesday 6 January 2015

How to detect iOS device model by macro



Steps 1]

Define macro's as follows in .pch file or create new header file (like in example Header.h )

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)

#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)

#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)




Steps 2] use following conditions (to check isRetina Supports or Not / is iPAD or iPhone / which iPhone device model used / Max Screen Length )


 if(IS_IPAD)
    {
        NSLog(@"IT'S IPAD");
    }
    if(IS_IPHONE)
    {
        NSLog(@"IT'S IPHONE");
    }
    
    //retina support
    if(IS_RETINA)
    {
        NSLog(@"RETINA SUPPORTED");
    }
    else
    {
        NSLog(@"RETINA NOT SUPPORTED");
    }
    
    
    
    
    if(IS_IPHONE_4_OR_LESS)
    {
        NSLog(@"IT'S  IPHONE_4_OR_LESS");
    }
    if(IS_IPHONE_5)
    {
        NSLog(@"IT'S IPHONE_5 or 5 IPHONE_5s ");
    }
    if(IS_IPHONE_6)
    {
        NSLog(@"IT'S IPHONE_6");
    }
    if(IS_IPHONE_6P)
    {
        NSLog(@"IT'S IPHONE_6Plus");
    }
    
    NSLog(@"================================================");
    NSLog(@"SCREEN_WIDTH: %.2f", SCREEN_WIDTH);
    NSLog(@"SCREEN_HEIGHT: %.2f", SCREEN_HEIGHT);
    NSLog(@"SCREEN_MAX_LENGTH: %.2f", SCREEN_MAX_LENGTH);
    NSLog(@"SCREEN_MIN_LENGTH: %.2f", SCREEN_MIN_LENGTH);



Monday 5 January 2015

how to show pdf file or any other document in ios




    //If you are trying to display website or any url contain
    UIWebView *mywebview = [[UIWebView alloc] initWithFrame:CGRectMake(5, 5, 300, 300)];
    NSURL *targetURL = [NSURL URLWithString:@"http://www.google.com"];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
    [mywebview loadRequest:request];
    
    [self.view addSubview:mywebview];


    
    
    
    // if you have a PDF file or any other file  bundled with your application
    UIWebView *mywebview = [[UIWebView alloc] initWithFrame:CGRectMake(5, 5, 300, 300)];
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"document" ofType:@"pdf"];
    NSURL *targetURL = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];

    [mywebview loadRequest:request];



Saturday 3 January 2015

Detect first time app launch in iOS



Here we can simply  add the if else condition using NSUserDefualts...


 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    

{
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
        {
            // app already launched
        }
        else
        {
            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            // This is the first launch ever
        }
}

    







or else if we want launch count then we can use instead of above follow the below code


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    
    NSUserDefaults *theDefaults;
    int  launchCount;
    //Set up the properties for the integer and default.
    theDefaults = [NSUserDefaults standardUserDefaults];
    launchCount = [theDefaults integerForKey:@"hasRun"] + 1;
    [theDefaults setInteger:launchCount forKey:@"hasRun"];
    [theDefaults synchronize];
    
    //Log the amount of times the application has been run
    NSLog(@"This application has been run %d amount of times", launchCount);
    
    //Test if application is the first time running
    if(launchCount == 1)
    {
        //Run your first launch code (Bring user to info/setup screen, etc.)
        NSLog(@"This is the first time this application has been run %d ====",launchCount);
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                  @"Title" message:[NSString stringWithFormat:@"%d",launchCount]  delegate:self
                                                 cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
        [alertView show];
        
    }
              
              //Test if it has been run before
              if(launchCount >= 2)
              {
                  //Run new code if they have opened the app before (Bring user to home screen etc.
                  NSLog(@"This application has been run before==== %d ",launchCount);
                  UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                            @"Title" message:[NSString stringWithFormat:@"%d",launchCount]  delegate:self
                                                           cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
                  [alertView show];
                }
    
                  
    return YES;
}

warning: no rule to process file of type for architecture

e.g  warningno rule to process file '/Users/idz/Documents/src/ IDZSwiftCommonCrypto/README.md' of type net.daringfireball.markdown for architecture x86_64.

"no rule to process file of type for architecture"


if these kind of error is occurred when build the App or run on the simulator..

then we can resolve that things with simply following step:-

Step 1) Select Project Navigator
Step 2) Select your project
Step 3) Select your targetStep 4) Select Build PhasesStep 5) Move files which we don't want the compiler to process from Compile Sources to Copy Bundle Resources






Friday 2 January 2015

Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGBitmapInfo' (aka 'enum CGBitmapInfo')



Here we got error like Implicit conversion..
First thing need to be consider in mind.. we need to 'typecast' to resolve the warning

CGBitmapInfo bitmapInfo =  kBitmapInfo;//old code here we got warning
Here we can simply typecast as below

CGBitmapInfo bitmapInfo = (CGBitmapInfo) kBitmapInfo;//do typecast as it

Thursday 1 January 2015

'minimumFontSize' is deprecated: first deprecated in iOS 6.0

            

label.minimumFontSize = 8.0f; // 'minimumFontSize' is deprecated: first deprecated in iOS 6.0


Above method method is decrepitude in iOS 6.0 

instead  of  'minimumFontSize' , you use 'minimumScaleFactor' for resolve the issue...

 label.minimumScaleFactor = 8.0f// use minimumScaleFactor