Friday, 27 February 2015

iOS-Key-Value Coding

                          Key-Value Coding

Hi Guys!
Today, I'm going to work with Key-Value Coding. To explain why we need key-Value Coding, I've an example for you
To calculate an average salary from n number of  employees, You'll use loops and some coding stuff to add all employees salary and then Calculate average divided by No. of employees.
double totalSalary = 0.0;
           for (Employee *employee in employees) {
               totalSalary += [employee.salary doubleValue];
                   }
double averageSalary = totalSalary / [employees count];
 

Fortunately, Apple Provides Key-value Coding gives us a much more concise--almost Ruby-like--way to do this:  
[employees valueForKeyPath:@"@avg.salary"]; 
Key-Value Operators used with valueForKeyPath and @ denotes a particular aggregate function
 
Collection Operators fall into one of three different categories, according to the kind of value they return:

  • Simple Collection Operators return strings, numbers, or dates, depending on the operator.
  • Object Operators return an array.
  • Array and Set Operators return an array or set, depending on the operator.
Simple Collection Operators
  • @count: Returns the number of objects in the collection as an NSNumber.
  • @sum: Converts each object in the collection to a double, computes the sum, and returns the sum as an NSNumber.
  • @avg: Takes the double value of each object in the collection, and returns the average value as an NSNumber.
  • @max: Determines the maximum value using compare:. Objects must support comparison with one another for this to work.
  • @min: Same as @max, but returns the minimum value in the collection.
Example 
[products valueForKeyPath:@"@count"]; // 4
[products valueForKeyPath:@"@sum.price"]; // 3526.00
[products valueForKeyPath:@"@avg.price"]; // 881.50
[products valueForKeyPath:@"@max.price"]; // 1699.00
[products valueForKeyPath:@"@min.launchedOn"]; // June 11, 2012


Object Operators

  • @unionOfObjects / @distinctUnionOfObjects: Returns an array of the objects in the property specified in the key path to the right of the operator. @distinctUnionOfObjects removes duplicates, whereas @unionOfObjects does not.

 Example 

[inventory valueForKeyPath:@"@unionOfObjects.name"]; // "iPhone 5", "iPhone 5", "iPhone 5", "iPad Mini", "MacBook Pro", "MacBook Pro"
[inventory valueForKeyPath:@"@distinctUnionOfObjects.name"]; // "iPhone 5", "iPad Mini", "MacBook Pro"


                       
 

Wednesday, 18 February 2015

iPhone -Get number of lines of UILabel


 First Option :

Firstly calculate height for text according to font :

NSInteger lineCount = 0;
CGSize labelSize = (CGSize){yourLabel.frame.size.width, MAXFLOAT};
CGRect requiredSize = [self boundingRectWithSize:labelSize  options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: yourLabel.font} context:nil];


Now calculate number of lines :
int charSize = lroundf(yourLabel.font.leading);
int rHeight = lroundf(requiredSize.height);
lineCount = rHeight/charSize;
NSLog(@"No of lines: %i",lineCount);



Second Option :

 NSInteger lineCount = 0;
 CGSize textSize = CGSizeMake(yourLabel.frame.size.width, MAXFLOAT);
 int rHeight = lroundf([yourLabel sizeThatFits:textSize].height)
 int charSize = lroundf(yourLabel.font.leading);
 lineCount = rHeight/charSize;
 NSLog(@"No of lines: %i",lineCount);

Monday, 16 February 2015

iPhone-Number Formatter example




 //Number Formatter example

Ex:1
        NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
        [formatter setNumberStyle:NSNumberFormatterNoStyle];
        [formatter setPositiveFormat:@"$ ##.##"];
         [formatter setLenient:YES];


Ex:2
        NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
        [formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
        [formatter setGeneratesDecimalNumbers:YES];
        [formatter setUsesGroupingSeparator:YES];
        NSString *groupingSeparator = [[NSLocale currentLocale] objectForKey:NSLocaleGroupingSeparator];
        [formatter setGroupingSeparator:groupingSeparator];
        [formatter setGroupingSize:3];

iPhone-Get ScrolllView SubViews using Block




//Get ScrolllView SubViews using Block

[self.scrollVIew.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if([obj isKindOfClass:[UIButton class]])
{
  UIButton *currentButton = (UIButton *)obj;     NSLog(@"%@",NSStringFromCGRect(currentButton.frame));
}
}];

Friday, 13 February 2015

iPhone-Dynamic SlideShow with Images




 Hey Guys, Today I'm going to give demo on Dynamic SlideShow without using third Party Code. Hope You'll like it cheers!!!

Add ScrollView and Page Controller in xib/StoryBoard File

//In m file
   @interface ViewController ()<UIScrollViewDelegate>
{
     NSArray *Arr;
    int TimeNum;
    BOOL Tend;
    int rowindex;
    IBOutlet UIScrollView *sv;
    IBOutlet UIPageControl *page;
}
@end


@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
      self.automaticallyAdjustsScrollViewInsets = NO;
  
    [NSTimer scheduledTimerWithTimeInterval:1 target: self selector: @selector(handleTimer:)  userInfo:nil  repeats: YES];


    //SlideShow Image Array
    Arr=[[NSArray alloc]initWithObjects:@"2_cloud.png",@"2.png",@"cloudwords.png",@"k.png",nil];
  
    //Add Image to ScrollView
    [self AdImg:Arr];
}


#pragma mark - timer

- (void) handleTimer: (NSTimer *) timer
{
    if (TimeNum % 5 == 0 ) {
      
        if (!Tend) {
            page.currentPage++;
            if (page.currentPage==page.numberOfPages-1) {
                Tend=YES;
            }
        }else{
            page.currentPage--;
            if (page.currentPage==0) {
                Tend=NO;
            }
        }
      
        [UIView animateWithDuration:0.7 //
                         animations:^{//
                             sv.contentOffset = CGPointMake(page.currentPage*self.view.frame.size.width,0);
                         }];
      
      
    }
    TimeNum ++;
}


//Add Dynamic ImageView In ScrollView

-(void)AdImg:(NSArray*)arr{
    //sv.frame=CGRectMake(0, 5+64, 320, 150);
    NSLog(@"%@",sv);
  
    [sv setContentSize:CGSizeMake(self.view.frame.size.width*[arr count], self.view.frame.size.height)];
    page.numberOfPages=[arr count];
  
    for (UIView*v in sv.subviews){
        [v removeFromSuperview];
    }
  
    for ( int i=0; i<[arr count]; i++) {
        UIImageView*img=[[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width*i, 0, self.view.frame.size.width, self.view.frame.size.height)];
        img.image=[UIImage imageNamed:[arr objectAtIndex:i]];
        img.tag=i;
        [sv addSubview:img];
   
    }
}


#pragma mark - scrollView && page
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  
 page.currentPage=scrollView.contentOffset.x/self.view.frame.size.width;
    // [self setCurrentPage:page.currentPage];
  
 }


Project Demo for your reference 
https://github.com/baljeetSingh21/Image-SlideShow

iPhone-Get All contacts from iPhone AddressBook

 Steps:

1.  Add Observer to Handle Changes in Contact Book

2. Asking For Permission to grant access to use Iphone AddressBook

3. If Granted then Read Address Book and store

 

//Observer to handle changes in Contact Boo

- (void)viewDidLoad
{
    [super viewDidLoad];
 ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(nil, nil);
    ABAddressBookRegisterExternalChangeCallback(addressBook, addressBookChanged, (__bridge void *)(self));
}

// Address Book Authorization grant place this code in viewDidAppear

-(void)viewDidAppear:(BOOL)animated
{

    if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusDenied ||
        ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusRestricted)
    {
        NSLog(@"AB Denied");
    }
    else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized)
    {
        NSLog(@"AB Authorized");
      
            [self address_book];
    }
    else
    {
        ABAddressBookRequestAccessWithCompletion(ABAddressBookCreateWithOptions(NULL, nil), ^(bool granted, CFErrorRef error)
                                                 {
                                                     if (!granted) {
                                                        NSLog(@"AB Just denied");
                                                         return;
                                                     }
                                                  
                                                         [self address_book];
                                                   
                                                     NSLog(@"AB Just authorized");
                                                 });
        NSLog(@"AB Not determined");
    }
 }

//Called automatically when  you made any modification in Contacts

void addressBookChanged(ABAddressBookRef addressBook, CFDictionaryRef info, void *context)
{
    NSMutableArray*additions = [[NSMutableArray alloc]init];
    CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
    CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
   
    for (int i = 0; i < nPeople; i++)
    {
        NSMutableDictionary *curContact=[[NSMutableDictionary alloc] init];
        ABRecordRef person=CFArrayGetValueAtIndex(people, i);
       
        NSString *contacName;
       
        CFTypeRef contacNameValue = ABRecordCopyValue(person, kABPersonFirstNameProperty);
        contacName = [[NSString stringWithFormat:@"%@", contacNameValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
        if (contacNameValue)
            CFRelease(contacNameValue);
       
       
        NSString *firstName ;
        NSString *lastName;
       
        //Get FirstName Ref
        CFTypeRef firstNameValue = ABRecordCopyValue(person, kABPersonFirstNameProperty);
        firstName = [[NSString stringWithFormat:@"%@", firstNameValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
        if (firstNameValue)
            CFRelease(firstNameValue);
       
        //Get LastName Ref
        CFTypeRef LastNameValue = ABRecordCopyValue(person, kABPersonLastNameProperty);
       
        if(LastNameValue)
        {
            [contacName stringByAppendingString:[NSString stringWithFormat:@" %@", LastNameValue]];
           
            lastName = [[NSString stringWithFormat:@"%@", LastNameValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
            if (LastNameValue)
                CFRelease(LastNameValue);
        }
        NSData *contactImage;
        //Get Contact Image Ref
        if (ABPersonHasImageData(person) > 0 )
        {
            CFTypeRef contactImageValue = ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail);
            contactImage = (__bridge NSData *)(contactImageValue);
            [curContact setObject:contactImage forKey:@"image"];
            if (contactImageValue)
                CFRelease(contactImageValue);
           
        }
        else {
            contactImage = UIImageJPEGRepresentation([UIImage imageNamed:@"profile_picture.png"], 1);
            [curContact setObject:contactImage forKey:@"image"];
        }
       
        ABMultiValueRef phoneNumber = ABRecordCopyValue(person, kABPersonPhoneProperty);
        ABMultiValueRef emailInfo = ABRecordCopyValue(person, kABPersonEmailProperty);
       
       
        if(contacName != NULL)  [curContact setObject:contacName forKey:@"Name"];
        if(firstName != NULL) [curContact setObject:firstName forKey:@"FirstName"];
        if(lastName != NULL)  [curContact setObject:lastName forKey:@"LastName"];
       
       
        [curContact setObject:@"YES" forKey:@"addressbook"];
       
        NSString *phone,*phone2,*phone3;
        if (ABMultiValueGetCount(phoneNumber) > 0)
        {
            //Get phoneValue Ref
            CFTypeRef phoneValue = ABMultiValueCopyValueAtIndex(phoneNumber, 0);
            phone = [[NSString stringWithFormat:@"%@", phoneValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
            if (phoneValue)
                CFRelease(phoneValue);
        }
       
        if (ABMultiValueGetCount(phoneNumber) > 1)
        {
            CFTypeRef phoneValue = ABMultiValueCopyValueAtIndex(phoneNumber, 1);
            phone2 = [[NSString stringWithFormat:@"%@", phoneValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
            if (phoneValue)
                CFRelease(phoneValue);
           
            phone2 = [phone2 stringByReplacingOccurrencesOfString:@"[^0-9]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [phone2 length])];
            [curContact setObject:phone2 forKey:@"phoneNo2"];
        }
       
        if (ABMultiValueGetCount(phoneNumber) > 2)
        {
            CFTypeRef phoneValue = ABMultiValueCopyValueAtIndex(phoneNumber, 2);
            phone3 = [[NSString stringWithFormat:@"%@", phoneValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
            if (phoneValue)
                CFRelease(phoneValue);
           
            phone3 = [phone3 stringByReplacingOccurrencesOfString:@"[^0-9]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [phone3 length])];
            [curContact setObject:phone3 forKey:@"phoneNo3"];
        }
        //Get emailInfo Ref
        for (int j = 0; j < ABMultiValueGetCount(emailInfo); j++) {
            CFTypeRef emailIdValue = ABMultiValueCopyValueAtIndex(emailInfo, j);
            NSString *emailId = [[NSString stringWithFormat:@"%@", emailIdValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
            if(emailId != NULL) {
                [curContact setObject:emailId forKey:@"UserName"];
               
                [curContact setObject:emailId forKey:[NSString stringWithFormat:@"emailAdday%d",j]];
                [curContact setObject:[NSString stringWithFormat:@"%d",j+1] forKey:@"emailCount"];
               
            }
            if (emailIdValue) {
                CFRelease(emailIdValue);
            }
        }
       if (emailInfo) {
            CFRelease(emailInfo);
        }
      
       
        if( contacName == NULL) {
        }
        else {
            NSString * strippedNumber = [phone stringByReplacingOccurrencesOfString:@"[^0-9]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [phone length])];
            if([strippedNumber length] == 11) {
                strippedNumber = [strippedNumber substringFromIndex:1];
            }
            if(strippedNumber != NULL)
                [curContact setObject:strippedNumber forKey:@"phoneNo"];
          
        }
         [additions addObject:curContact];
        if (phoneNumber)
            CFRelease(phoneNumber);
    }
  NSLog(@"Address Book Contacts : %@",additions );
    NSLog(@"Additions Count: %d",[additions count]);
    NSMutableArray * get_ids_input = [NSMutableArray new];
    for (NSDictionary * person in additions)
    {
        NSMutableDictionary * person_input = [NSMutableDictionary new];
        [person_input setObject:@"" forKey:@"memberId"];
        if (person[@"phoneNo"]) [person_input setObject:person[@"phoneNo"] forKey:@"phoneNo"];
        if (person[@"emailAddy"]) [person_input setObject:person[@"emailAddy"] forKey:@"emailAddy"];
        else [person_input setObject:@"" forKey:@"emailAddy"];
        if (person[@"phoneNo2"]) [person_input setObject:person[@"phoneNo2"] forKey:@"phoneNo2"];
        if (person[@"phoneNo3"]) [person_input setObject:person[@"phoneNo3"] forKey:@"phoneNo3"];
        [get_ids_input addObject:person_input];
    }
      if (people)
    CFRelease(people);
      if (addressBook)
    CFRelease(addressBook);
    NSLog(@"Home -> ABChanged: Recevied notification");
}


//Method to call when Permission Granted

-(void)address_book

{

    [additions removeAllObjects];

    additions = [[NSMutableArray alloc]init];

    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(nil, nil);

    CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);

    CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);

    for (int i = 0; i < nPeople; i++)

    {

        NSMutableDictionary * curContact = [[NSMutableDictionary alloc] init];

        [curContact setObject:@"YES" forKey:@"addressbook"];

        ABRecordRef person = CFArrayGetValueAtIndex(people, i);

        NSString * contacName, * firstName, * lastName;

        NSData * contactImage;

        NSString * phone, * phone2, * phone3;

        CFTypeRef contacNameValue = ABRecordCopyValue(person, kABPersonFirstNameProperty);

        contacName = [[NSString stringWithFormat:@"%@", contacNameValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

        if (contacNameValue)

            CFRelease(contacNameValue);

        // Get FirstName Ref

        CFTypeRef firstNameValue = ABRecordCopyValue(person, kABPersonFirstNameProperty);

        firstName = [[NSString stringWithFormat:@"%@", firstNameValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

        if (firstNameValue)

            CFRelease(firstNameValue);

       

        // Get LastName Ref

        CFTypeRef LastNameValue = ABRecordCopyValue(person, kABPersonLastNameProperty);

        if (LastNameValue)

        {

            [contacName stringByAppendingString:[NSString stringWithFormat:@" %@", LastNameValue]];

            lastName = [[NSString stringWithFormat:@"%@", LastNameValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

            if (LastNameValue)

                CFRelease(LastNameValue);

        }

        // Get Contact Image Ref

        if (ABPersonHasImageData(person) > 0 )

        {

            CFTypeRef contactImageValue = ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail);

            contactImage = (__bridge NSData *)(contactImageValue);

            [curContact setObject:contactImage forKey:@"image"];

            if (contactImageValue)

                CFRelease(contactImageValue);

        }

        else

        {

            contactImage = UIImageJPEGRepresentation([UIImage imageNamed:@"profile_picture.png"], 1);

            [curContact setObject:contactImage forKey:@"image"];

        }

        ABMultiValueRef phoneNumber = ABRecordCopyValue(person, kABPersonPhoneProperty);

        ABMultiValueRef emailInfo = ABRecordCopyValue(person, kABPersonEmailProperty);

        if (contacName != NULL) [curContact setObject: contacName forKey:@"Name"];

        if (firstName != NULL) [curContact setObject: firstName forKey:@"FirstName"];

        if (lastName != NULL) [curContact setObject: lastName forKey:@"LastName"];

        if (ABMultiValueGetCount(phoneNumber) > 0)

        {

            CFTypeRef phoneValue = ABMultiValueCopyValueAtIndex(phoneNumber, 0);

            phone = [[NSString stringWithFormat:@"%@", phoneValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

            if (phoneValue)

            CFRelease(phoneValue);

        }

        if (ABMultiValueGetCount(phoneNumber) > 1)

        {

            CFTypeRef phoneValue = ABMultiValueCopyValueAtIndex(phoneNumber, 1);

            phone2 = [[NSString stringWithFormat:@"%@", phoneValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

            if (phoneValue)

            CFRelease(phoneValue);

            phone2 = [phone2 stringByReplacingOccurrencesOfString:@"[^0-9]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [phone2 length])];

            [curContact setObject:phone2 forKey:@"phoneNo2"];

        }

        if (ABMultiValueGetCount(phoneNumber) > 2)

        {

            CFTypeRef phoneValue = ABMultiValueCopyValueAtIndex(phoneNumber, 2);

            phone3 = [[NSString stringWithFormat:@"%@", phoneValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

             if (phoneValue)

            CFRelease(phoneValue);

            phone3 = [phone3 stringByReplacingOccurrencesOfString:@"[^0-9]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [phone3 length])];

            [curContact setObject:phone3 forKey:@"phoneNo3"];

        }

        //Get emailInfo Ref

        for (int j = 0; j < ABMultiValueGetCount(emailInfo); j++)

        {

            CFTypeRef emailIdValue = ABMultiValueCopyValueAtIndex(emailInfo, j);

            NSString * emailId = [[NSString stringWithFormat:@"%@", emailIdValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

            if ( emailId != NULL &&

                [emailId rangeOfString:@"@facebook.com"].location == NSNotFound)

            {

                [curContact setObject:emailId forKey:@"UserName"];

                [curContact setObject:emailId forKey:[NSString stringWithFormat:@"emailAdday%d",j]];

                [curContact setObject:[NSString stringWithFormat:@"%d", j+1] forKey:@"emailCount"];

            }

            if (emailIdValue) {

                CFRelease(emailIdValue);

            }

        }

        if (emailInfo) {

            CFRelease(emailInfo);

        }

        if (contacName != NULL)

        {

            NSString * strippedNumber = [phone stringByReplacingOccurrencesOfString:@"[^0-9]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [phone length])];

            if ([strippedNumber length] == 11) {

                strippedNumber = [strippedNumber substringFromIndex:1];

            }

            if (strippedNumber != NULL)

                [curContact setObject:strippedNumber forKey:@"phoneNo"];

        }

        [additions addObject:curContact];

        if (phoneNumber)

            CFRelease(phoneNumber);

    }

NSLog(@"Address Book Contacts : %@",additions );

    NSMutableArray * get_ids_input = [NSMutableArray new];

    for (NSDictionary * person in additions)

    {

        NSMutableDictionary *person_input = [NSMutableDictionary new];

        [person_input setObject:@"" forKey:@"memberId"];

        if (person[@"emailAddy"]) [person_input setObject:person[@"emailAddy"] forKey:@"emailAddy"];

        else [person_input setObject:@"" forKey:@"emailAddy"];

        if (person[@"phoneNo"]) [person_input setObject:person[@"phoneNo"] forKey:@"phoneNo"];

        if (person[@"phoneNo2"]) [person_input setObject:person[@"phoneNo2"] forKey:@"phoneNo2"];

        if (person[@"phoneNo3"]) [person_input setObject:person[@"phoneNo3"] forKey:@"phoneNo3"];

        [get_ids_input addObject:person_input];

    }

    if (people)

    CFRelease(people);

     if (addressBook)

    CFRelease(addressBook);

}


Sunday, 11 January 2015

iOS-Convert UIImage to Byte Array and vice versa



 //Convert UIImage to Byte Array


UIImage*imageOBJ;
if (imageOBJ) {       

 NSData *data = UIImagePNGRepresentation([[assist shared] getTranferImage]);

NSUInteger len = data.length;
        uint8_t *bytes = (uint8_t *)[data bytes];NSMutableString *result1 = [NSMutableString  stringWithCapacity:len * 3];

        for (NSUInteger i = 0; i < len; i++) {
            if (i) {
                [result1 appendString:@","];
            }
            [result1 appendFormat:@"%d", bytes[i]];
        }
       
        NSArray*arr=[result1 componentsSeparatedByString:@","];
        [dictnew setObject:arr forKey:@"Picture"];
    }

 //Convert Byte Array to UIImage

 NSArray* bytedata = [self.trans valueForKey:@"Picture"];
        unsigned c = bytedata.count;
        uint8_t *bytes = malloc(sizeof(*bytes) * c);
       
        unsigned i;
        for (i = 0; i < c; i++)
        {
            NSString *str = [bytedata objectAtIndex:i];
            int byte = [str intValue];
            bytes[i] = (uint8_t)byte;
        }
       
        NSData *datos = [NSData dataWithBytes:bytes length:c];
       
        imgTran=[[UIImageView alloc]initWithFrame:CGRectMake(5, 240, 150, 160)];
        [imgTran setImage:[UIImage imageWithData:datos]];