Monday, 13 July 2015

Getting library for Youtube Integration

change xcrun developer path

1 . sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
2. Open terminal and copy paste the following URL.

svn checkout http://google-api-objectivec-client.googlecode.com/svn/trunk/ google-api-objectivec-client-read-only
For latest Library :
https://code.google.com/p/google-api-objectivec-client/source/checkout

Thursday, 19 June 2014

IOS : Save Data using Rest Web services with POST method

- (IBAction)providerRegistration:(id)sender
{

@try 
{
    [self.txtClientId resignFirstResponder];
    if([[self.txtEmrName notNull:self.txtEmrName] isEqualToString:@""] || [[self.txtUserName notNull:self.self.txtUserName] isEqualToString:@""] || [[self.txtPassword notNull:self.self.txtPassword] isEqualToString:@""]|| [[self.txtProvider notNull:self.self.txtProvider] isEqualToString:@""]|| [[self.txtClientId notNull:self.self.txtClientId] isEqualToString:@""])
    {
  UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"empty" message:@"information   required" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
        [alert show];
        return;
    }
    NSError *error;

    NSString *url = @"http://four-developers.com/service1.svc/GetData";
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
    

    
    [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
      [request setHTTPMethod:@"POST"];
    
    NSMutableDictionary* mapData = [[ NSMutableDictionary alloc ] init ];
    
    //[ mapData setObject :@"MEDPRIME" forKey : @"DataSourceName"];
    [ mapData setObject :self.txtEmrName.text forKey : @"aa"];
      
    NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error];
    [request setHTTPBody:postData];

    [NSURLConnection sendAsynchronousRequest:request
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
 {
                             
                               [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                                   
                                  // UI Updation...
                               }];
                               
                               NSError *err = nil ;
                               NSDictionary   *responseDict = [ NSJSONSerialization JSONObjectWithData :data options : 0 error :&err];
                               NSString* strResult = [responseDict objectForKey : @"ProviderRegristrationResult" ];
                               
                               if([strResult isKindOfClass:[NSNull class]])
                               {
                                   UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"empty" message:@"Data save failed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
                                   [alert show];
                                   return;
                               }
                               else if([strResult isEqualToString:@""])
                               {
                                   UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"empty" message:@"Data save failed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
                                   [alert show];
                                   return;
                               }
                               else if([strResult isEqualToString:@"User Already Exist"])
                               {
                                   UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"empty" message:strResult delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
                                   [alert show];
                                   return;
                               }
                               else if([strResult isEqualToString:@"Success"])
                               {
                                   UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"empty" message:@"Data save successfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
                                   [alert show];
                                   
                               }

                           }];
    

    
}
@catch (NSException *exception)
{
    NSLog(@"%@",exception.description);
    
}

}

Saturday, 7 June 2014

Custom activityIndicator using objective C

-(void)StartProgressBar:(NSString *)strMessgae superView:(UIView *)view
{
    
    UIView *alertView=[[UIView alloc] initWithFrame:CGRectMake((view.frame.size.width/2)-50, (view.frame.size.height/2)-80, 100, 70)];
    alertView.tag=505;
    [alertView setBackgroundColor:[UIColor blackColor]];
    [alertView setAlpha:.7];
    alertView.layer.cornerRadius=8.0f;
    
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    //[activityIndicator setFrame:CGRectMake((alertView.frame.size.width/2)-25, 10, 55, 30)]; // Commented on 28thJan2014
    [activityIndicator setFrame:CGRectMake((alertView.frame.size.width/2)-25, 20, 55, 30)];
    [activityIndicator startAnimating];
    [alertView addSubview:activityIndicator];
    
    // Commented on 28thJan2014 START --
//    UILabel *lbl=[[UILabel alloc] initWithFrame:CGRectMake(0, 40, alertView.frame.size.width, 30)];
//    lbl.text=strMessgae;
//    [lbl setBackgroundColor:[UIColor clearColor]];
//    [lbl setTextColor:[UIColor whiteColor]];
//    [lbl setFont:[UIFont fontWithName:@"Helvetica-Bold" size:11]];
//    [lbl setTextAlignment:NSTextAlignmentCenter];
//    [alertView addSubview:lbl];
    // -- END
    
    view.userInteractionEnabled = NO;
    self.navigationController.view.userInteractionEnabled = NO;
    [view addSubview:alertView];
    
    
}

-(void)StopProgressBar:(UIView *)view
{
    //[alertProgressBar dismissWithClickedButtonIndex:0 animated:YES];
    UIView *subView=(UIView *)[view viewWithTag:505];
    
    if (subView)
        [subView removeFromSuperview];
    
    view.userInteractionEnabled = YES;
    self.navigationController.view.userInteractionEnabled = YES;

}

Thursday, 29 May 2014

Complete code : Insert and retrieve data using sqlite

- (IBAction)saveWithSqlite:(id)sender
{
    [self initDBWithDataTable];
    [self storingDataIntoSqlite];
    [self getPersons];
}

-(void)initDBWithDataTable
{
    NSArray* arrPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* strDBPath = [arrPath objectAtIndex:0];
    
    strDBPath = [strDBPath stringByAppendingPathComponent:@"EmpDB.sqlite3"];
    BOOL isExist = [[NSFileManager defaultManager]fileExistsAtPath:strDBPath];
    
    if(sqlite3_open([strDBPath UTF8String], &sqlite)== SQLITE_OK)
    {
        if(!isExist)
        {
            
            char *error;
            const char *sqlStatement = "CREATE TABLE IF NOT EXISTS PERSON (ID INTEGER PRIMARY KEY AUTOINCREMENT, FIRSTNAME TEXT, LASTNAME TEXT, BIRTHDAY DATE)";
            if(sqlite3_exec(sqlite, sqlStatement, NULL, NULL, &error) == SQLITE_OK)
            {
                // Create the ADDRESS table with foreign key to the PERSON table
                sqlStatement = "CREATE TABLE IF NOT EXISTS ADDRESS (ID INTEGER PRIMARY KEY AUTOINCREMENT, STREETNAME TEXT, STREETNUMBER INT, PERSONID INT, FOREIGN KEY(PERSONID) REFERENCES PERSON(ID))";
                if(sqlite3_exec(sqlite, sqlStatement, NULL, NULL, &error)== SQLITE_OK)
                {
                    NSLog(@"DataBase Created");
                }
                else
                {
                    NSLog(@"Error: %s", error);
                }
            }
            else
            {
                NSLog(@"Error: %s", error);
            }
        }
    }
    
    
}

-(void)storingDataIntoSqlite
{
    NSString *insertStatement = [NSString stringWithFormat:@"INSERT INTO PERSON (FIRSTNAME, LASTNAME, BIRTHDAY) VALUES (\"%@\", \"%@\", \"%@\")", @"Kiran",@"yadav", @"1987-02-24"];
    
    char *error;
    if ( sqlite3_exec(sqlite, [insertStatement UTF8String], NULL, NULL, &error) == SQLITE_OK)
    {
        int64_t personID = sqlite3_last_insert_rowid(sqlite);
        
        // Create insert statement for the address
        insertStatement = [NSString stringWithFormat:@"INSERT INTO ADDRESS (STREETNAME, STREETNUMBER, PERSONID) VALUES (\"%@\", \"%@\", \"%lld\")", @"Ghazipur", @"30", personID];
        if ( sqlite3_exec(sqlite, [insertStatement UTF8String], NULL, NULL, &error) == SQLITE_OK)
        {
            NSLog(@"Person inserted.");
        }
        else
        {
            NSLog(@"Error: %s", error);
        }
    }
    else
    {
        NSLog(@"Error: %s", error);
    }
}

-(NSArray*)getPersons
{
    // Allocate a persons array
    NSMutableArray *persons = [[NSMutableArray alloc]init];
    
    // Create the query statement to get all persons
    NSString *queryStatement = [NSString stringWithFormat:@"SELECT ID, FIRSTNAME, LASTNAME, BIRTHDAY FROM PERSON"];
    
    // Prepare the query for execution
    sqlite3_stmt *statement;
    if (sqlite3_prepare_v2(sqlite, [queryStatement UTF8String], -1, &statement, NULL) == SQLITE_OK)
    {
        // Iterate over all returned rows
        while (sqlite3_step(statement) == SQLITE_ROW)
        {
            
            // Get associated address of the current person row
            // int personID = sqlite3_column_int(statement, 0);
            // Convert the birthday column to an NSDate
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
            dateFormatter.dateFormat = @"yyyy-MM-dd";
            NSString *birthdayAsString = [NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
            NSDate *birthday = [dateFormatter dateFromString: birthdayAsString];
            NSLog(@"%@",birthday);
            // Create a new person and add it to the array
            
            NSString* str1 =    [NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
            NSString* str2 =    [NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
            
            [persons addObject:str1];
            [persons addObject:str2];
            
            
        }
        sqlite3_finalize(statement);
    }
    return persons;
    
}

Tuesday, 15 April 2014

Binary Search in IOS using objective C

-(void)binary_searchh
{
    NSMutableArray* arr = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"7",@"10",@"45",@"90",nil];
    int value =  90;
    int min = 0;
    int max = 5;
    for (int i=0; i<[arr count]; i++)
    {
        int mid = (min+max)/2;
        if(value>[[arr objectAtIndex:mid] integerValue] )
        {
            min = mid+1;
        }
        else if(value<[[arr objectAtIndex:mid] integerValue])
        {
            max = mid -1;
        }
        else if(value==[[arr objectAtIndex:mid] integerValue])
        {
            NSLog(@"Found %@",[arr objectAtIndex:mid]);
             NSLog(@"Found %d",i);
            break;
        }
    }

}