Friday, 24 February 2012

converting the contact in the Vcard represantation and Sending Mail + iphone

- (NSString *)vCardRepresentation
{
  NSMutableArray *mutableArray = [[NSMutableArray alloc] init];

  [mutableArray addObject:@"BEGIN:VCARD"];
  [mutableArray addObject:@"VERSION:3.0"];

  [mutableArray addObject:[NSString stringWithFormat:@"FN:%@", self.name]];

  [mutableArray addObject:[NSString stringWithFormat:@"ADR:;;%@",
                           [self addressWithSeparator:@";"]]];

  if (self.phone != nil)
    [mutableArray addObject:[NSString stringWithFormat:@"TEL:%@", self.phone]];

  [mutableArray addObject:[NSString stringWithFormat:@"GEO:%g;%g",
                           self.latitudeValue, self.longitudeValue]];

  [mutableArray addObject:[NSString stringWithFormat:@"URL:http://%@",
                           self.website]];

  [mutableArray addObject:@"END:VCARD"];

  NSString *string = [mutableArray componentsJoinedByString:@"\n"];

  [mutableArray release];

  return string;
}
For sending mail for vcf file
 CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
  
 if ([MFMailComposeViewController canSendMail]){
       
    NSData *vCards = (NSData *) ABPersonCreateVCardRepresentationWithPeople(allPeople);
   
    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; 
    mc.mailComposeDelegate = self; 
   
    [mc setSubject:@"Contact"];
   
    [mc setMessageBody:@"<p>My message...<p>" isHTML:YES];
       
        ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, 1);
       
       
      //  CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
       
     //   NSString *contactFirst = [NSString stringWithFormat: @"%@", (NSString *)firstName];
       
     //  NSString *label = ([allPeople count] == 1)? (NSString *)ABRecordCopyCompositeName([allPeople objectAtIndex:0]): @"Contacts";
   
    [mc addAttachmentData:vCards mimeType:@"text/x-vcard" fileName:@"All.vcf"];//
   
    [self presentModalViewController:mc animated:YES]; 
    [mc release]; 
  
    }

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{  
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Result: canceled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Result: saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Result: sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Result: failed");
            break;
        default:
            NSLog(@"Result: not sent");
            break;
    }
    [self becomeFirstResponder];
   
    [controller dismissModalViewControllerAnimated:YES];
}

Weather Demo + iphone

http://learningiphoneprogramming.com/pages/samplecode.html

Mail from gmail or yahoo account + iphone

http://sourceforge.net/projects/nimitparekh/files/mail%20transfer%20using%20GMAIL/mailTransfer.zip/download

Creating the contact group in iphone

ABAddressBookRef  addressBook = ABAddressBookCreate();   
    CFErrorRef err = nil;
    ABRecordRef group = ABGroupCreate();
    ABRecordSetValue(group, kABGroupNameProperty, @"MCA", &err);
   
   ABAddressBookRemoveRecord(addressBook,group, &err);
    ABAddressBookSave(addressBook, &err);
 //Removing group
-(BOOL)removeGroup{
    BOOL res;
    CFErrorRef error;
    ABAddressBookRef ab = ABAddressBookCreate();
   
    NSArray *groups = (NSArray *) ABAddressBookCopyArrayOfAllGroups(ab);
   
    for (id _group in groups)
    {
        NSString *currentGroupName = [[NSString alloc] init];
        currentGroupName = (NSString*) ABRecordCopyValue(_group, kABGroupNameProperty);
       
        if ([@"MCA" isEqualToString:currentGroupName])
        {
            [currentGroupName release];
            res = ABAddressBookRemoveRecord(ab, _group, &error);
            ABAddressBookSave(ab, nil);
            return res;
        }
        [currentGroupName release];
    }
   
    return NO;
}

parsing of Images tag from the string in + iphone

- (NSString *)getFirstImage:(NSString *)htmlString{
  NSString *urlImage=nil;
    NSScanner *theScanner = [NSScanner scannerWithString:htmlString];
    // find start of IMG tag
    [theScanner scanUpToString:@"<img" intoString:nil];
    do {
        [theScanner scanUpToString:@"src" intoString:nil];
        NSCharacterSet *charset = [NSCharacterSet characterSetWithCharactersInString:@"\"'"];
        [theScanner scanUpToCharactersFromSet:charset intoString:nil];
        [theScanner scanCharactersFromSet:charset intoString:nil];
        [theScanner scanUpToCharactersFromSet:charset intoString:&urlImage];

        if([urlImage rangeOfString:@"imagebutton.gif"].location == NSNotFound) return urlImage;


    }while (![theScanner isAtEnd]  );


    if([theScanner isAtEnd]) return nil;
     return urlImage;
}

custom progressView + iphone

   http://www.obsessivecode.com/projects/ocprogress/

Wenggling and vibrations of any object + iphone

- (void)startWobble {
    resultImage.transform = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-5));
   
    [UIView animateWithDuration:0.25
                          delay:0.0
                        options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse)
                     animations:^ {
                         resultImage.transform = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(5));
                     }
                     completion:NULL
     ];

}
[self startWobble];
- (void)stopWobble {
 [UIView animateWithDuration:0.25
      delay:0.0
      options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear)
      animations:^ {
       itemView.transform = CGAffineTransformIdentity;
      }
      completion:NULL
  ];
}
//For the shake/vibration of unbutton
https://github.com/jonasschnelli/UIView-I7ShakeAnimation