Saturday, 4 February 2012

urldemo 6

//    SKU=Stock Keeping Unit

//For the custom progressView
    http://www.obsessivecode.com/projects/ocprogress/

//For the parsing of <img src> tag from the string
- (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;
}


//For Rss links for iPhone themes

    http://iphonethemes.net/rss1/Abstract
    1 to 26

 //creating group
  
      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;
}


//For sending mail from gmail or yahoo account
http://sourceforge.net/projects/nimitparekh/files/mail%20transfer%20using%20GMAIL/mailTransfer.zip/download

//For the weather demo
http://learningiphoneprogramming.com/pages/samplecode.html

///For the converting the contact in the Vcard form

- (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];
}
   
//For the sending one mail to bulkPeople
- (IBAction)emailBtnPress {
    if ([appDel connectedToInternet]==YES) {
        if ([MFMailComposeViewController canSendMail]  ){
            ABAddressBookRef addressBook = ABAddressBookCreate();
           
            CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
           
           
            CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
           
            NSMutableArray *emailIdArray= [[NSMutableArray alloc] init];
            for (int i = 0; i < nPeople; i++) {
               
                ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
                 
                ABMultiValueRef multiValue = ABRecordCopyValue(ref, kABPersonEmailProperty);
                NSLog(@"%@",multiValue);
               
                int count = ABMultiValueGetCount(multiValue);
                NSLog(@"%d",count);
                int j;
                for(j = 0; j < count; j++) {
                    NSString *label = (NSString *)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multiValue, j));
                    NSString *value = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, j);
                   
                    NSLog(@"Email for %@: %@", label, value);
                    [emailIdArray addObject:value];
                }               
             }
            NSLog(@"%@",emailIdArray);
            MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
            mailController.mailComposeDelegate = self;
            [mailController setCcRecipients:emailIdArray];
            [mailController setSubject:@"Sending bulk Email"];
            [self presentModalViewController:mailController animated:YES];
            [mailController release];
        }
        else{
            [appDel showAlert:@"!Opps" message:@"Your Device should not configured the mail account."];
        }
    }
    else{
        [appDel showAlert:@"!Opps" message:@"Check your network connection."];
    }
}
- (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];
}
 

No comments:

Post a Comment