如何在iPhone中创建联系人二维码

时间:2012-05-02 11:56:26

标签: iphone contacts qr-code

我正在为Qr生成器应用程序工作,为此我有一个很好的kyupay库。

在该库中,我需要传递字符串值,然后返回QR图像。

它适用于文字,电子邮件等......

但是现在我想为联系人和事件创建QR图像我不知道该怎么做。

所以我的问题应该是那个????

的逻辑

请建议我或如果您有相应的代码,请分享。

2 个答案:

答案 0 :(得分:2)

感谢您回答我的问题。

我最终创建了一个返回联系Qr代码字符串的函数。

这很容易但是太长了。

我们必须检查来自用户的数据输入并根据数据追加sting并创建字符串。

我发布我的代码,这样可以帮助他人并节省他们的时间。

-(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;
}

...谢谢

答案 1 :(得分:0)

如果您在此站点创建联系QR代码:http://zxing.appspot.com/generator/它会为您提供用于创建QR代码的字符串。也许你可以用它作为灵感?