Wednesday, 16 March 2016

Multiple Operation of Database

Multiple Operation of Database



For Multiple Operation of Database First Create database and Then Implement Following Methods :-
:-  Create NSObject :-
CustomData.h :-
#import <Foundation/Foundation.h>

@interface CustomData : NSObject

@property (nonatomic,retain) NSString *strLT_VERSION_NUMBER;

//Import
@property (nonatomic,retain) NSString *strSLC_ID;
@property (nonatomic,retain) NSString *strMAC_ID;
@property (nonatomic,retain) NSString *strSLC_NAME;
@property (nonatomic,retain) NSString *strSLC_GROUP_NAME;


//Import data For Motion Group
@property (nonatomic,retain) NSString *strSLC_IDForMotion;
@property (nonatomic,retain) NSString *strMAC_IDForMotion;
@property (nonatomic,retain) NSString *strSLC_NAMEForMotion;
@property (nonatomic,retain) NSString *strSLC_GROUP_NAMEForMotion;
@property (nonatomic,retain) NSString *strSLC_GROUP_IDForMotion;


@end

CustomData.m :-

#import "CustomData.h"

@implementation CustomData


@synthesize strMAC_ID, strSLC_ID, strSLC_NAME, strSLC_GROUP_NAME;

@synthesize strSLC_GROUP_IDForMotion,strSLC_GROUP_NAMEForMotion,strMAC_IDForMotion,strSLC_IDForMotion,strSLC_NAMEForMotion ;


@end

Note :- Here DataBase File Implement For Declare Methods in Database 

Database.h :-

#import <Foundation/Foundation.h>

#import <sqlite3.h>

#import "CustomData.h"


@interface Database : NSObject
{
    NSString *querySQL;
}

@property (strong , nonatomic) CustomData *objCustomDetail ;

//GET DATABASE PATH

-(NSString *)getDBPath;
-(void)openDB;

//Import slc data.

-(void)AddSLCData  : (CustomData *)objDetail;
-(void)UpdateSLCData  : (NSString *)SLC_Name : (NSString *)MAC_ID;
-(void)DeleteSLCData;
-(NSMutableArray *)GetSLCDetails;
-(NSString *)Get_SLC_ID : (NSString *)SLC_Name;

// ADD & DELETE Motion SLC_GROUP DATA.

-(void)Add_SLC_Motion_Group_Data  : (CustomData *)objDetail;
-(void)UpdateSLC_Motion_Data  : (CustomData *)objDetail : (NSString *)GRP_ID;
-(void)Delete_SLC_Motion_Group_Data : (NSString *)Group_Name;
-(NSMutableArray *)Get_SLC_Motion_Group_Name;
-(NSMutableArray *)Get_SLC_Group_ID;
-(NSString *)Get_GROUP_SLC_Motion_NAME : (NSString *)Group_Name;
-(CustomData *)Get_SLC_Motion_Group_Details : (NSString *)Group_Name;
-(NSString *)Get_SLC_From_GroupID : (NSString *)Group_ID;


// For image Save And Get

- (void) SaveImagesToSql: (NSData*) imgData :(NSString*) mainUrl ;


- (NSData*) LoadImagesFromSql: (NSString*) imageLink ;

@end


Database.m :-


#import "Database.h"

#import "AppDelegate.h"

@implementation Database

static sqlite3 *database = nil;

-(AppDelegate *)appDelegate
{
    return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}

-(NSString *)getDBPath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex : 0];
return [documentsDir stringByAppendingPathComponent : @"Database.sqlite3"];
}

-(void)openDB
{
    if (sqlite3_open([[self getDBPath]UTF8String],&database) == SQLITE_OK)
    {
        NSLog(@"database opened");
    }
    else
    {
        sqlite3_close(database);
        NSAssert(0, @"database failed to open");
    }
}


#pragma mark - ADD UPDATE DELETE SLC DATA.

-(void)AddSLCData  : (CustomData *)objDetail
{
    sqlite3_stmt *addStmt = nil;

    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK)
    {
if (addStmt == nil) {
const char *sql = "INSERT INTO ImportSLC (slc_id, mac_id, slc_name) values (?, ?, ?)";
if (sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'",sqlite3_errmsg(database));
}
        sqlite3_bind_text(addStmt, 1, [objDetail.strSLC_ID UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 2, [objDetail.strMAC_ID UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(addStmt, 3, [objDetail.strSLC_NAME UTF8String], -1, SQLITE_TRANSIENT);

if (SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
else{
            
            sqlite3_finalize(addStmt);
            sqlite3_close(database);
        }
    }
    else{
        
        sqlite3_finalize(addStmt);
        sqlite3_close(database);
    }
}

-(void)UpdateSLCData  : (NSString *)SLC_Name : (NSString *)MAC_ID
{
    sqlite3_stmt *updateStmt = nil;

    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK)
    {
if (updateStmt == nil) {
const char *sql = "UPDATE ImportSLC SET slc_name =? where mac_id = ?";
if (sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'",sqlite3_errmsg(database));
}
        
        sqlite3_bind_text(updateStmt, 2, [MAC_ID UTF8String], -1, SQLITE_TRANSIENT);

        sqlite3_bind_text(updateStmt, 1, [SLC_Name UTF8String], -1, SQLITE_TRANSIENT);

        
if (SQLITE_DONE != sqlite3_step(updateStmt))
NSAssert1(0, @"Error while updating data. '%s'", sqlite3_errmsg(database));
else
        {
            sqlite3_finalize(updateStmt);
            sqlite3_close(database);
        }
}
    else{
        
        sqlite3_finalize(updateStmt);
        sqlite3_close(database);
    }
}

-(void)DeleteSLCData
{
    sqlite3_stmt *deleteStmnt = nil;

    if(sqlite3_open([[self getDBPath] UTF8String],&database) == SQLITE_OK)
    {
        if(deleteStmnt == nil)
        {
            const char *sql = "delete from ImportSLC";
            if(sqlite3_prepare_v2(database, sql, -1, &deleteStmnt, NULL) != SQLITE_OK)
                NSAssert1(0, @"Error while creating delete statement. '%s'", sqlite3_errmsg(database));
        }
        
        
        if (SQLITE_DONE != sqlite3_step(deleteStmnt))
            NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(database));
        
        else{
            
            sqlite3_finalize(deleteStmnt);
            sqlite3_close(database);
        }
    }
    else{
        
        sqlite3_finalize(deleteStmnt);
        sqlite3_close(database);
    }
}


-(NSMutableArray *)GetSLCDetails
{
    sqlite3_stmt *selectStmt = nil;

    NSMutableArray *slcArray = [[NSMutableArray alloc] init];
    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK)
    {
        
        const char *sql = "SELECT * FROM ImportSLC";
        
        //NSLog(@"QUERY : %s",sql);
        
        if (sqlite3_prepare_v2(database, sql, -1, &selectStmt, NULL) == SQLITE_OK)
        {
            while (sqlite3_step(selectStmt) == SQLITE_ROW)
            {
                CustomData *objDetail=[[CustomData alloc] init];

                objDetail.strSLC_ID=((char *)sqlite3_column_text(selectStmt,0) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 0)];
                objDetail.strMAC_ID=((char *)sqlite3_column_text(selectStmt,1) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 1)];
                objDetail.strSLC_NAME=((char *)sqlite3_column_text(selectStmt,2) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 2)];

                [slcArray addObject:objDetail];
            }
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
        else{
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
    }
    return slcArray;
}


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

-(NSString *)Get_SLC_ID : (NSString *)SLC_Name
{
    sqlite3_stmt *selectStmt = nil;
    
    NSString *strSLC_ID;
    
    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK)
    {
        
        const char *sql = "SELECT slc_id FROM ImportSLC WHERE slc_name=?";
        
        //NSLog(@"QUERY : %s",sql);
        
        if (sqlite3_prepare_v2(database, sql, -1, &selectStmt, NULL) == SQLITE_OK)
        {
            sqlite3_bind_text(selectStmt, 1, [SLC_Name UTF8String], -1, SQLITE_TRANSIENT);
            
            while (sqlite3_step(selectStmt) == SQLITE_ROW)
            {
                strSLC_ID=((char *)sqlite3_column_text(selectStmt,0) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 0)];
            }
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
        else{
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
    }
    return strSLC_ID;
}




//--------------------------------------------------------------------------------------------------------------
//--------------------------------- Motion Group Method --------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------

#pragma mark - ADD & DELETE SLC_Mtion_GROUP DATA.

-(void)Add_SLC_Motion_Group_Data  : (CustomData *)objDetail
{
    sqlite3_stmt *addStmt = nil;
    
    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK)
    {
        
        if (addStmt == nil) {
            
            const char *sql = "INSERT INTO SLC_MotionGrp (motion_group_name, motion_slc_id, motion_mac_id, motion_slc_name, motion_group_id) values (?, ?, ?, ?, ?)";
            
            if (sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
                NSAssert1(0, @"Error while creating add statement. '%s'",sqlite3_errmsg(database));
        }
        
        sqlite3_bind_text(addStmt, 1, [objDetail.strSLC_GROUP_NAMEForMotion UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(addStmt, 2, [objDetail.strSLC_IDForMotion UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(addStmt, 3, [objDetail.strMAC_IDForMotion UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(addStmt, 4, [objDetail.strSLC_NAMEForMotion UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(addStmt, 5, [objDetail.strSLC_GROUP_IDForMotion UTF8String], -1, SQLITE_TRANSIENT);
        
        if (SQLITE_DONE != sqlite3_step(addStmt))
            NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
        else
        {
            
            sqlite3_finalize(addStmt);
            sqlite3_close(database);
        }
    }
    else{
        
        sqlite3_finalize(addStmt);
        sqlite3_close(database);
    }
}

-(void)UpdateSLC_Motion_Data  : (CustomData *)objDetail : (NSString *)GRP_ID
{
    sqlite3_stmt *updateStmt = nil;
    
    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK)
    {
        
        if (updateStmt == nil) {
            
            const char *sql = "UPDATE SLC_MotionGrp SET motion_group_name =?, motion_slc_id =?, motion_mac_id =?, motion_slc_name =? where motion_group_id = ?";
            
            if (sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK)
                NSAssert1(0, @"Error while creating add statement. '%s'",sqlite3_errmsg(database));
        }
        
        sqlite3_bind_text(updateStmt, 1, [objDetail.strSLC_GROUP_NAMEForMotion UTF8String], -1, SQLITE_TRANSIENT);
        
        sqlite3_bind_text(updateStmt, 2, [objDetail.strSLC_IDForMotion UTF8String], -1, SQLITE_TRANSIENT);
        
        sqlite3_bind_text(updateStmt, 3, [objDetail.strMAC_IDForMotion  UTF8String], -1, SQLITE_TRANSIENT);
        
        sqlite3_bind_text(updateStmt, 4, [objDetail.strSLC_NAMEForMotion UTF8String], -1, SQLITE_TRANSIENT);
        
        sqlite3_bind_text(updateStmt, 5, [GRP_ID UTF8String], -1, SQLITE_TRANSIENT);
        
        
        if (SQLITE_DONE != sqlite3_step(updateStmt))
            NSAssert1(0, @"Error while updating data. '%s'", sqlite3_errmsg(database));
        else
        {
            sqlite3_finalize(updateStmt);
            sqlite3_close(database);
        }
    }
    else{
        
        sqlite3_finalize(updateStmt);
        sqlite3_close(database);
    }
}




-(void)Delete_SLC_Motion_Group_Data : (NSString *)Group_Name
{
    sqlite3_stmt *deleteStmnt = nil;
    
    if(sqlite3_open([[self getDBPath] UTF8String],&database) == SQLITE_OK)
    {
        if(deleteStmnt == nil)
        {
            const char *sql = "delete from SLC_MotionGrp where motion_group_name = ?";
            if(sqlite3_prepare_v2(database, sql, -1, &deleteStmnt, NULL) != SQLITE_OK)
                NSAssert1(0, @"Error while creating delete statement. '%s'", sqlite3_errmsg(database));
        }
        
        sqlite3_bind_text(deleteStmnt, 1, [Group_Name UTF8String], -1, SQLITE_TRANSIENT);
        
        if (SQLITE_DONE != sqlite3_step(deleteStmnt))
            NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(database));
        
        else{
            
            sqlite3_finalize(deleteStmnt);
            sqlite3_close(database);
        }
    }
    else{
        
        sqlite3_finalize(deleteStmnt);
        sqlite3_close(database);
    }
}

-(NSMutableArray *)Get_SLC_Motion_Group_Name
{
    sqlite3_stmt *selectStmt = nil;
    
    NSMutableArray *slcArray = [[NSMutableArray alloc] init];
    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK)
    {
        
        const char *sql = "SELECT * FROM SLC_MotionGrp";
        
        //NSLog(@"QUERY : %s",sql);
        
        if (sqlite3_prepare_v2(database, sql, -1, &selectStmt, NULL) == SQLITE_OK)
        {
            while (sqlite3_step(selectStmt) == SQLITE_ROW)
            {
                
                NSString *strSLC_GROUP_NAME=((char *)sqlite3_column_text(selectStmt,0) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 0)];
                
                [slcArray addObject:strSLC_GROUP_NAME];
            }
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
        else{
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
    }
    return slcArray;
}

// Get Detail Of Group Id

-(NSMutableArray *)Get_SLC_Group_ID
{
    sqlite3_stmt *selectStmt = nil;
    
    NSMutableArray *slcIDArray = [[NSMutableArray alloc] init];
    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK)
    {
        
        const char *sql = "SELECT * FROM SLC_MotionGrp";
        
        //NSLog(@"QUERY : %s",sql);
        
        if (sqlite3_prepare_v2(database, sql, -1, &selectStmt, NULL) == SQLITE_OK)
        {
            while (sqlite3_step(selectStmt) == SQLITE_ROW)
            {
                
                NSString *strSLC_GROUP_ID=((char *)sqlite3_column_text(selectStmt,4) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 4)];
                
                
                [slcIDArray addObject:strSLC_GROUP_ID];
            }
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
        else{
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
    }
    return slcIDArray;
}


-(NSString *)Get_GROUP_SLC_Motion_NAME : (NSString *)Group_Name
{
    sqlite3_stmt *selectStmt = nil;
    
    NSString *strSLC_NAME;
    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK)
    {
        
        const char *sql = "SELECT motion_slc_name FROM SLC_MotionGrp WHERE motion_group_name=?";
        
        //NSLog(@"QUERY : %s",sql);
        
        if (sqlite3_prepare_v2(database, sql, -1, &selectStmt, NULL) == SQLITE_OK)
        {
            sqlite3_bind_text(selectStmt, 1, [Group_Name UTF8String], -1, SQLITE_TRANSIENT);
            
            while (sqlite3_step(selectStmt) == SQLITE_ROW)
            {
                strSLC_NAME=((char *)sqlite3_column_text(selectStmt,0) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 0)];
            }
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
        else{
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
    }
    return strSLC_NAME;
}

-(CustomData *)Get_SLC_Motion_Group_Details : (NSString *)Group_Name
{
    sqlite3_stmt *selectStmt = nil;
    
    objDetail = [[CustomData alloc] init];
    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK)
    {
        
        const char *sql = "SELECT * FROM SLC_MotionGrp where motion_group_name = ?";
        
        //NSLog(@"QUERY : %s",sql);
        
        if (sqlite3_prepare_v2(database, sql, -1, &selectStmt, NULL) == SQLITE_OK)
        {
            sqlite3_bind_text(selectStmt, 1, [Group_Name UTF8String], -1, SQLITE_TRANSIENT);
            
            while (sqlite3_step(selectStmt) == SQLITE_ROW)
            {
                objDetail.strSLC_GROUP_NAMEForMotion=((char *)sqlite3_column_text(selectStmt,0) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 0)];
                objDetail.strSLC_IDForMotion=((char *)sqlite3_column_text(selectStmt,1) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 1)];
                objDetail.strMAC_IDForMotion=((char *)sqlite3_column_text(selectStmt,2) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 2)];
                objDetail.strSLC_NAMEForMotion=((char *)sqlite3_column_text(selectStmt,3) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 3)];
                objDetail.strSLC_GROUP_IDForMotion=((char *)sqlite3_column_text(selectStmt,4) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 4)];
            }
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
        else{
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
    }
    return objDetail;
}


-(NSString *)Get_SLC_From_GroupID : (NSString *)Group_ID
{
    sqlite3_stmt *selectStmt = nil;
    
    NSString *strSLC_NAME;
    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK)
    {
        
        const char *sql = "SELECT motion_slc_id FROM SLC_MotionGrp WHERE motion_group_id=?";
        
        //NSLog(@"QUERY : %s",sql);
        
        if (sqlite3_prepare_v2(database, sql, -1, &selectStmt, NULL) == SQLITE_OK)
        {
            sqlite3_bind_text(selectStmt, 1, [Group_ID UTF8String], -1, SQLITE_TRANSIENT);
            
            while (sqlite3_step(selectStmt) == SQLITE_ROW)
            {
                strSLC_NAME=((char *)sqlite3_column_text(selectStmt,0) == NULL) ? @"" : [NSString stringWithUTF8String : (char *)sqlite3_column_text(selectStmt, 0)];
            }
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
        else{
            
            sqlite3_finalize(selectStmt);
            sqlite3_close(database);
        }
    }
    return strSLC_NAME;
}


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


- (void) SaveImagesToSql: (NSData*) imgData :(NSString*) mainUrl
{
    NSLog( @"\n*****Save image to SQLite*****\n" );
    
    const char* sqliteQuery = "INSERT INTO IMAGES (name, IMAGE) VALUES (?, ?)";
    sqlite3_stmt* statement;
    
    if( sqlite3_prepare_v2(database, sqliteQuery, -1, &statement, NULL) == SQLITE_OK )
    {
        sqlite3_bind_text(statement, 1, [mainUrl UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_blob(statement, 2, [imgData bytes], [imgData length], SQLITE_TRANSIENT);
        sqlite3_step(statement);
    }
    
    else NSLog( @"SaveBody: Failed from sqlite3_prepare_v2. Error is:  %s", sqlite3_errmsg(database) );
    
    // Finalize and close database.
    sqlite3_finalize(statement);
}

- (NSData*) LoadImagesFromSql: (NSString*) imageLink
{
    
    NSLog( @"\n*****Load image From SQLite*****\n" );
    
    NSData* data = nil;
    NSString* sqliteQuery = [NSString stringWithFormat:@"SELECT IMAGE FROM IMAGES WHERE name = '%@'", imageLink];
    sqlite3_stmt* statement;
    
    if( sqlite3_prepare_v2(database, [sqliteQuery UTF8String], -1, &statement, NULL) == SQLITE_OK )
    {
        if( sqlite3_step(statement) == SQLITE_ROW )
        {
            int length = sqlite3_column_bytes(statement, 0);
            data       = [NSData dataWithBytes:sqlite3_column_blob(statement, 0) length:length];
        }
    }
    
    // Finalize and close database.
    sqlite3_finalize(statement);
    
    return data;

}


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


@end





Note :- Here ViewControllers File Implement For Use Methods in Database 

ViewController.h :-

{
               Database *objDB;
               CustomData *objCustomData;
}


ViewController.m :-

//---------------------------------------- Import slc data.

For Add & Delete SLC Data :-

NSMutableArray *OldSLCAry = [[NSMutableArray alloc] init];
        
objDB = [[Database alloc] init];
        
OldSLCAry = [objDB GetSLCDetails];

// Get Data From Array -  OldSLCAry

 for (int i = 0; i < OldSLCAry.count; i++)
{
          NSString * strSLC_ID = [OldSLCAry objectAtIndex:i] strSLC_ID] ;

           NSString * strMAC_ID = [OldSLCAry objectAtIndex:i] strMAC_ID] ;

           NSString * strSLC_NAME = [OldSLCAry objectAtIndex:i] strSLC_NAME] ;
}

 //Delete Main SLC data.

[objDB DeleteSLCData];

CustomData *objCustomData = [[CustomData alloc] init];
                
objCustomData.strSLC_ID = [NSString stringWithFormat:@"1"];
objCustomData.strMAC_ID = [NSString stringWithFormat:@"2"];
                
objCustomData.strSLC_NAME = [NSString stringWithFormat:@"3"];
              
[objDB AddSLCData:objCustomData];



For Update SLC Data :-

 //Update slc_name.

Database *objData = [[Database alloc] init];
                      
[objData UpdateSLCData:currentTextField.text:self.strMac_ID];



For Get SLCID Data :-

NSString *strID = [objDB Get_SLC_ID:[Group_SLC_Name_Motion_Ary objectAtIndex:indexPath.row]];



//--------------------- ADD & DELETE SLC_Mtion_GROUP DATA.


For Add Data :-

 objDB = [[Database alloc] init];
                            
objCustomData = [[CustomData alloc] init];
                            
objCustomData.strSLC_GROUP_NAMEForMotion = groupNameTextField.text;
objCustomData.strSLC_IDForMotion = strMult_SLC_ID;
objCustomData.strSLC_NAMEForMotion = strMult_SLC_Name;
objCustomData.strMAC_IDForMotion = strMult_MAC_ID;
objCustomData.strSLC_GROUP_IDForMotion = strGroupIdData ;
                            
 [objDB Add_SLC_Motion_Group_Data:objCustomData];



For Update Data :-

 objDB = [[Database alloc] init];
                        
objCustomData = [[CustomData alloc] init];
                        
objCustomData.strSLC_GROUP_NAMEForMotion = groupNameTextField.text;
objCustomData.strSLC_IDForMotion = strMult_SLC_ID;
objCustomData.strSLC_NAMEForMotion = strMult_SLC_Name;
objCustomData.strMAC_IDForMotion = strMult_MAC_ID;
                                       
[objDB UpdateSLC_Motion_Data:objCustomData :strGroupIdData];



For Delete & Get Detail of Data :-

 objDB = [[Database alloc] init];
                
[objDB Delete_SLC_Motion_Group_Data:self.strGROUP_NAMEForMotion];


 NSMutableArray *Group_Name_Motion_Ary = [[NSMutableArray alloc] init];
                
Group_Name_Motion_Ary = [objDB Get_SLC_Motion_Group_Name];
                
NSLog(@"%@",Group_Name_Motion_Ary);




For Get Data By Specific Name :-


objDB = [[Database alloc] init];
                
objCustomData = [[CustomData alloc] init];
                     
objCustomData = [objDB Get_SLC_Motion_Group_Details:GrpNameForPushData];
                
NSString *strGroupIdData =  objCustomData.strSLC_GROUP_IDForMotion ;

Tuesday, 2 February 2016

Steps Of Submite Application to Apple Store

Submite Application to Apple Store


I assume that you have iPhone Developer License. Please follow the following steps, one by one:


  • Step 1:

    Certificate is very important part for submitting or testing your application on iPhone. It has the code-sign(Signatures) which will be Checked when you submit your application on apple Store or to test it on your iPhone .There are two steps to create a certificate from developer portal. I simply copied those two from “iPhone developer portal”
    1. Generating a Certificate Signing Request
    2. Submitting a Certificate Signing Request for Approval
    Generating a Certificate Signing Request
    1. In your Applications folder, open the Utilities folder and launch Keychain Access.
    2. In the Preferences menu, set Online Certificate Status Protocol (OSCP) and Certificate Revocation List (CRL) to “Off”.
    3. Choose Keychain Access -> Certificate Assistant -> Request a Certificate from a Certificate Authority.
    4. In the User Email Address field, enter your email address. Please ensure that The email Address entered matches the information that was submitted when you registered as an iPhone Developer.
    5. In the Common Name field enter Your Name. Please ensure that the name entered matches the information that was submitted when you registered as an iPhone Developer.
    6. No CA (Certificate Authority) Email Address is required. The ‘Required’ message will be removed after completing the following step.
    7. Select the ‘Saved to Disk’ radio button and if prompted, select ‘Let me specify key pair information’ and click ‘Continue’.
    8. If ‘Let me specify key pair’ was selected, specify a file name and click ‘Save’. In the following screen select ‘2048 bits’ for the Key Size and ‘RSA’ for the Algorithm. Click ‘Continue’.
    9. The Certificate Assistant will create a CSR file on your desktop.
    Submitting a Certificate Signing Request for Approval
    1. After creating a CSR, log in to the iPhone Developer Program Portal and navigate to ‘Certificates’ > ‘Development’ and click ‘Add Certificate’.
    2. Click the ‘Choose file’ button, select your CSR and click ‘Submit’. If the Key Size was not set to 2048 bits during the CSR creation process, the Portal will reject the CSR.
    3. Upon submission, Team Admins will be notified via email of the certificate request.
    4. Once your CSR is approved or rejected by a Team Admin, you will be notified via email of the change in your certificate status.
    Download/Installing Certificate on your machine
    1. Upon CSR approval, Team Members and Team Admins can download their certificates via the ‘Certificates’ section of the Program Portal. Click ‘Download’ next to the certificate name to download your iPhone Development Certificate to your local machine.
    2. On your local machine, double-click the Download .cer file to launch Keychain Access and install your certificate.
    Certificate is installed on your MAC now the next step is create a App ID. (Note:You have to follow this step only once and later you don’t have to make certificates for your other applications.)
  • Step 2:

    Creating an App Id is very easy, you have to follow few simple steps:
    1. Log in to the iPhone Developer Program Portal and navigate to ‘App IDs’ and click ‘Add Id’.
    2. In “App Id Name” enter the name of your application (i.e iphoneapp) and in “App Id” enter something like com.yourdomain.applicationame (i.e com.adeem.iphoneapp) and clicked on Submit
    3. Please write done the “App Id” because you will used this in Info.plist, Bundle identifier tag
  • Step 3:

    Now the next step is to create a Provisioning File for you Xcode and this will be your last step for creating binary which you submit it to appstore.
    1. In to the iPhone Developer Program Portal and navigate to ‘Provisioning’ > ‘Distribution’ and click ‘Add Profile’.
    2. Now select “App Store” in “Distribution Method”
    3. In “Profile Name” type your application name (i.e iphoneapp) which will be your provisioning profile name as well.
    4. In “App ID” select the app name (i.e iphoneapp) which you created in Step 2
    5. Download the Provisioning profile and copy it to your /YourUserName/Library/MobileDevice/Provisioning Profile
  • Step 4:

    Now everything is step up, open your project in Xcode
    1. Select your project from “Group & File” in left side bar and click on “i” ( info ) button.
    2. Move to “Configuration” tab and select “Release”. Press the “Duplicate” button from bottom, name is “iphoneDistribution”.
    3. Click on “Build” tab and select “iphoneDistribution” and type in “Search in Build Settings” filed ‘Base SDK’ and select the current selected Device and change it to what device your application is targetting ( I prefer “Device – iPhone OS 2.0)
    4. Now in “Search in build setting” field type “code signing identity” and select the provisioning profile you created in Step 3. Also do the same thing for the child property “Any iPhone OS Device”.
    5. Now Close the Info screen and select the “Target” > “YourApp” from “Group & File” in left side bar and clicked on “Info” button again from Xcode.
    6. Repeat the step 3 and 4 again for safe side.
    7. Now Info screen is still open clicked on “Properties” tab and in Identifier field type the “App Id” (i.e com.adeem.iphoneapp)
    8. Everything is set up, click on “Build”(cmd+B) from Xcode>Build
    9. Now right Click on “Product”>”YourApp” and select “Reveal in Finder”. This is your binary file so please zip this file.
  • Step 5:

    Now you are done from Xcode and iPhone Developer Protal. Now you will submit this binary to itunesconnect.
    1. In your Browser Type https://itunesconnect.apple.com/ (this website is very slow over https) and login using your iphone developer account.
    2. Click on “Manage Your Account” > “Add Application”
    3. Now answer simple question from apple and submit your application to appstore. Few thing you should have before you submit your application there in System/Mind:
      • Application Name ( must be uniqe)
      • Application description
      • Application Category
      • URL for your application feedback
      • Icon of your application in 512×512 size
      • Main picture of your application in 320×480 or 320×460 size. (Optionaly you can submit up to 4 more pictures of your application as well)