A9628298AF2F97B5E073C680D9D5DC85 Apps King Technologies

Tuesday, 22 April 2014

Sqlite database iOS application

                                     Read and write in to sqlite database in iOS application

//-----add two framework in your project---
1. libsqlite3.dylib
2. libsqlite3.0.dylib


DBManager.h


#import <Foundation/Foundation.h>
#import <sqlite3.h>

@interface DBManager : NSObject
{
    NSString *databasePath;
}

+(DBManager*)getSharedInstance;
-(BOOL)createDB;
- (BOOL) saveData:(NSString*)ID name:(NSString*)Name address:(NSString*)Address phone:(NSString*)Phone;
- (NSArray*) findByRegisterNumber:(NSString*)ID;
@end




DBManager.m


#import "DBManager.h"
static DBManager *sharedInstance = nil;
static sqlite3 *database = nil;
static sqlite3_stmt *statement = nil;

@implementation DBManager

+(DBManager *)getSharedInstance
{
    if (!sharedInstance) {
        sharedInstance = [[DBManager alloc]init]; //[[super allocWithZone:NULL]init];
        [sharedInstance createDB];
    }
    return sharedInstance;
}

-(BOOL)createDB
{
    
    NSString *docsDir;
    NSArray *dirPaths;
    // Get the documents directory
    dirPaths = NSSearchPathForDirectoriesInDomains
    (NSDocumentDirectory, NSUserDomainMask, YES);
    docsDir = dirPaths[0];
    // Build the path to the database file
    databasePath = [[NSString alloc] initWithString:
                    [docsDir stringByAppendingPathComponent: @"Contacts.sqlite"]];
    BOOL isSuccess = YES;
    NSFileManager *filemgr = [NSFileManager defaultManager];
    if ([filemgr fileExistsAtPath: databasePath ] == NO)
    {
        const char *dbpath = [databasePath UTF8String];
        if (sqlite3_open(dbpath, &database) == SQLITE_OK)
        {
            //char *errMsg;
            //const char *sql_stmt = @"";
           // "create table if not exists studentsDetail (regno integer
           // primary key, name text, department text, year text)";
           // if (sqlite3_exec(database, sql_stmt, NULL, NULL, &errMsg)!= SQLITE_OK)
           // {
           //     isSuccess = NO;
           //     NSLog(@"Failed to create table");
           // }
           // sqlite3_close(database);
            return  isSuccess;
        }
        else {
            isSuccess = NO;
            NSLog(@"Failed to open/create database");
        }
    }
    return isSuccess;
}



- (BOOL) saveData:(NSString*)ID
       name:(NSString*)Name address:(NSString*)Address phone:(NSString*)Phone
{
     sqlite3_stmt *statement = nil;
    const char *dbpath = [databasePath UTF8String];
    if (sqlite3_open(dbpath, &database) == SQLITE_OK)
    {
        //NSString *insertSQL = [NSString stringWithFormat:@"insert into Records (id,name, address, phone) values (\"%@\",\"%@\", \"%@\", \"%@\")",ID, Name, Address, Phone];
        
        NSString *insertSQL = [NSString stringWithFormat:@"insert into Records (id,name, address, phone) values ('%@','%@', '%@', '%@');",ID, Name, Address, Phone];
        const char *insert_stmt = [insertSQL UTF8String];
        //sqlite3_prepare_v2(database, insert_stmt,-1, &statement, NULL);
        //if (sqlite3_step(statement) == SQLITE_DONE)
        if (sqlite3_prepare_v2(database, insert_stmt,-1, &statement, NULL) == SQLITE_DONE)
        {
            return YES;
        }
        else {
            return NO;
        }
        sqlite3_reset(statement);
        sqlite3_finalize(statement);
    }
    return NO;
}
                               
- (NSArray*) findByRegisterNumber:(NSString*)ID
  {
    const char *dbpath = [databasePath UTF8String];
    if (sqlite3_open(dbpath, &database) == SQLITE_OK)
    {
        NSString *querySQL = [NSString stringWithFormat:@"select name, address, phone FROM Records where id=\"%@\"",ID];
        const char *query_stmt = [querySQL UTF8String];
        NSMutableArray *resultArray = [[NSMutableArray alloc]init];
        if (sqlite3_prepare_v2(database,query_stmt, -1, &statement, NULL) ==SQLITE_OK)
        {
            if (sqlite3_step(statement) == SQLITE_ROW)
            {
                NSString *name = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
                [resultArray addObject:name];
                NSString *address = [[NSString alloc] initWithUTF8String:
                (const char *) sqlite3_column_text(statement, 1)];
                [resultArray addObject:address];
                 NSString *phone = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)];
                [resultArray addObject:phone];
                return resultArray;
             }
             else{
                    NSLog(@"Not found");
                    return nil;
            }
            sqlite3_reset(statement);
        }
     }
     return nil;
  }

@end




Then go to your view controller.m and call these methods

//-----to save data in database--------
[[DBManager getSharedInstance]saveData:txtFID.text name:txtFName.text address:txtFAddress.text phone:txtFPhone.text];


//------to get data from data base------------
[[DBManager getSharedInstance]findByRegisterNumber:txtFID.text];




Some useful methods and links for storyboard.


Some useful methods in for storyboard.

                                 get object of a class that is push in storyboard.

ProviderLookupViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ProviderLookupViewController"];
[self presentModalViewController:vc animated:YES];


//--------------------------------------------
[self performSegueWithIdentifier:@"SomeSegueName" sender:someObject];




//--------------------------------

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"TargetSegue"]) {
        TargetViewController *vc = segue.destinationViewController;
        //vc.items = nil;
    }
}



//----------------------------------------------
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"articleView"])
    {
        WebViewController *controller = (WebViewController *)segue.destinationViewController;
        RSSEntry *entry = [_allEntries objectAtIndex:[self.tableView indexPathForSelectedRow].row];
        controller.entry = entry;
    }
}


- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {  
    [self performSegueWithIdentifier:@"articleView" sender:[self.tableView cellForRowAtIndexPath:indexPath]];
}


//****************************************************************

                                   Links to learn storyboard


//****************************************************************









Thursday, 27 February 2014

Requirements to upload a project on iTunes



Requirements to upload  a project on iTunes:


1.  A developer account with user name and password.
2. Code of project or IPA of that project.
3. Four screen shot of that project.(if project are for iPhone and iPad both device then four screen shot for each devices)
      Screenshots for 3.5-inch iPhone and iPod touch Retina display must be 960x640, 960x600, 
        640x960 or 640x920 pixels, at least 72 DPI, in the RGB color space, and in the JPG or PNG 
        format.

        Screenshots for 4-inch iPhone 5 and iPod touch (5th generation) Retina display must be 
        1136x640, 1136x600, 640x1136 or 640x1096 pixels, at least 72 DPI, in the RGB color space, and 
         in the JPG or PNG format.

         iPad Screenshots must be .jpeg, .jpg, .tif, .tiff, or .png file that is 1024x768, 1024x748, 768x1024, 
         768x1004, 2048x1536, 2048x1496, 1536x2048 or 1536x2008 pixels, at least 72 DPI, and in the 
         RGB color space.
   
4. One icon of project in size 1024x1024 in png format without rounded corner.
5. Description about that project.
6. Provide category of application also make sure it have adult content or not.
7. if project have in app purchase then credit card info and account detail needed.


8. Metadata------
          description:
          Support url: 
          marketting url:
          privacy policy url:

9. Contact information-----
         first name:
         last name:
         email address:
         phone number: 
         Address with city,state,country,Postal code


10. Demo account information----
        User name:
        Password:


//--------------------------------------------------------------------------------------------------------
Before uploading application make sure fallowing points:

Make sure to validate the following properties that will cause your app to be rejected if the iTunes Connect information doesn’t match what’s set in the app binary:
  • Bundle ID
  • Version Number
  • App Sandbox Entitlement Usage Information
  • Application have distribution certificates and provisioning profiles.
  • Validate your application





Tuesday, 25 February 2014

Hide And Show TabBar in iOS


Hide TabBar in iOS:

- (void) showTabBar:(UITabBarController *) tabbarcontroller
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    float fHeight;
    ifUIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width - 49.0;
    }
    else
    {
      fHeight = screenRect.size.height-49.0;
    }
    
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            float x1 = view.frame.origin.x;
            float y1 = fHeight;
            float x11 = view.frame.size.width;
            float y11 = view.frame.size.height;
            if(flag)
            {
                x1 = 30;
                flag=0;
                
            }
            else
            {
                x1 = 0;
                flag = 1;
            }

            [view setFrame:CGRectMake(x1, fHeight, view.frame.size.width, view.frame.size.height)];
            NSLog(@"x1 %f ,x11 %f, y1 %f,y11 %f",x1,y1,x11,y11);
        }
        else
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
        }
    }
    [UIView commitAnimations];
}



- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    float fHeight = screenRect.size.height;
    ifUIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width;
    }
    
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            float x1 = view.frame.origin.x;
            float y1 = fHeight+49;
            float x11 = view.frame.size.width;
            float y11 = view.frame.size.height;
            if(flag)
            {
                y11 = 0;//view.frame.size.height-49;
                flag = 0;
            }
            else
            {
                flag = 1;
            }
            [view setFrame:CGRectMake(x1,y1,y1,y11)];
            NSLog(@"x1 %f ,x11 %f, y1 %f,y11 %f",x1,y1,x11,y11);
        }
        else
        {
           [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y , view.frame.size.width,fHeight)];
            
            view.backgroundColor = [UIColor blackColor];
          
        }
    }
    [UIView commitAnimations];
    

}




//*******************************************************************************


- (void) showTabBar:(UITabBarController *) tabbarcontroller
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    
    
    float fHeight;
    ifUIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width - 49.0;
    }
    else
    {
      fHeight = screenRect.size.height-49.0;
    }
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
        }
        else
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
        }
    }
    [UIView commitAnimations];
}



- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    float fHeight = screenRect.size.height;
    ifUIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width;
    }
    
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, fHeight+50, view.frame.size.width, view.frame.size.height-49)];
        }
        else
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y+50, view.frame.size.width,fHeight)];
            
            view.backgroundColor = [UIColor blackColor];
          
        }
    }
    [UIView commitAnimations];
    
}



Making Secure TextField in iOS


Make a secure text field in iOS:

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    const char * _char;
    _char = [string cStringUsingEncoding:NSUTF8StringEncoding];
    int isBackSpace = isBackSpace = strcmp(_char, "\b");
    
    if (isBackSpace == -8)
    {
        NSMutableString *text = [txtPassword.text mutableCopy];
        if (range.length > 0) {
            [text deleteCharactersInRange:range];
        }
        if (range.length == 0 && range.location != 0)
        {
            NSRange backward = NSMakeRange(range.location - 1, 1);
            [text deleteCharactersInRange:backward];
        }
        
        txtPassword.text = text;
        return YES;
        
    }
    
    pass = [pass stringByAppendingString:[NSString stringWithFormat:@"%s",_char]];
    passStar = [passStar stringByAppendingString:@"*"];
    
    txtPassword.text = passStar;
    NSLog(@"text is %@",pass);
    return YES;

}