Sarafaraz Babi
Sarafaraz Babi

Reputation: 480

How to Create Contact QR code in iphone

I am working for Qr generator application and for that I have nice kyupay Library.

In that Library I need to pass string value and it returns QR Image.

It's working nice for text,Email and etc...

But Now i wants to create QR Image for Contact and Event And i don't know how to do this.

so My problem is what should be the logic for that ????

please suggest me or if you have code for that then please Share it.

Upvotes: 1

Views: 2257

Answers (2)

Sarafaraz Babi
Sarafaraz Babi

Reputation: 480

Thanks for respond me on my question.

I finally creates a function that returns contact Qr code string.

It's easy but too long.

we have to check for data inputs from user and append sting as per data and create string.

I am Posting my code so it may help others and save theirs time.

-(NSString *)GenerateStringForContact{

    NSString *str = @"";
    NSMutableArray *arr1 =[[NSMutableArray alloc] init];

    for (int i=0 ; i<[arrayAttributeName count]; i++) {

        if ([[arrayAttributeName objectAtIndex:i] isEqualToString:@"First Name"]) {
            if ([strContactType isEqualToString:@"ContactMecard"]) {
             [arr1 addObject:@"N:"];
            }else{
             [arr1 addObject:@"FN:"];   
            }
        }else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:@"Last Name"]) {
//            [arr1 addObject:@"N:"];
        }else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:@"Phone"]) {
            [arr1 addObject:@"TEL:"];
        }else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:@"Email"]) {
            [arr1 addObject:@"EMAIL:"];
        }else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:@"URL"]) {
            [arr1 addObject:@"URL:"];
        }else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:@"Nickname"]) {
            [arr1 addObject:@"NICKNAME:"];
        }else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:@"Title"]) {
            [arr1 addObject:@"TITLE:"];
        }else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:@"Organization"]) {
            [arr1 addObject:@"ORG:"];
        }else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:@"Birthday"]) {
            [arr1 addObject:@"BDAY:"];
        }else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:@"Note"]) {
            [arr1 addObject:@"NOTE:"];
        }

    }

    NSMutableArray *contDetail = arrayAttributeValue;

    if ([strContactType isEqualToString:@"ContactMecard"]) {
        str = @"MECARD:";
//         arr1 = [[NSArray alloc] initWithObjects:@"N:",@"TEL:",@"EMAIL:",@"URL:",@"NOTE:",@"NICKNAME:",@"BDAY:",@"ADR:",nil];

    }else{

       str = @"BEGIN:VCARD";
//       arr1 = [[NSArray alloc] initWithObjects:@"N:",@"TEL:",@"EMAIL:",@"URL:",@"NOTE:",@"NICKNAME:",@"BDAY:",@"ADR:",@"TITLE:",@"ORG:",nil];
    }

    BOOL count = TRUE;
    for (int i =0; i <[contDetail count]; i++) {

        if (![[contDetail objectAtIndex:i] isEqualToString:@""]) {

            NSString *tmp2 =@"";

            if (i == 0 || i == 1) {
                if (count) {


                    if ([strContactType isEqualToString:@"ContactMecard"]) {

                        tmp2 = [NSString stringWithFormat:@"%@,%@",[contDetail objectAtIndex:0],[contDetail objectAtIndex:1]];

                        NSString *tmp = [NSString stringWithFormat:@"%@%@",[arr1 objectAtIndex:i],tmp2];

                    str = [NSString stringWithFormat:@"%@;%@",str,tmp];

                    }else{
                        tmp2 = [NSString stringWithFormat:@"%@ %@",[contDetail objectAtIndex:0],[contDetail objectAtIndex:1]];

                        NSString *tmp = [NSString stringWithFormat:@"%@%@",[arr1 objectAtIndex:i],tmp2];

                        str = [NSString stringWithFormat:@"%@\n%@",str,tmp];
                    }

                    count = FALSE;
                }

            }else{

                tmp2 = [contDetail objectAtIndex:i];
                NSString *tmp = [NSString stringWithFormat:@"%@%@",[arr1 objectAtIndex:i-1],tmp2];

                if ([strContactType isEqualToString:@"ContactMecard"]) {

                    str = [NSString stringWithFormat:@"%@;%@",str,tmp];

                }else{
                    str = [NSString stringWithFormat:@"%@\n%@",str,tmp];
                }


            }

        }
    }

    if (![strContactType isEqualToString:@"ContactMecard"]) {
        str = [NSString stringWithFormat:@"%@\nEND:VCARD",str];


    }
    NSLog(@"here string for generate code %@",str);    

    return str;
}

Thanks....

Upvotes: 2

esreli
esreli

Reputation: 5071

If you create a Contact QR code at this site: http://zxing.appspot.com/generator/ it provides for you the string it uses to create the QR Code. Maybe you can use this as inspiration?

Upvotes: 0

Related Questions