当我尝试将定界字符串拆分为数组时,我遇到了一个小问题。基本上,我想传递来自MECARD QRCode的结果并将新条目添加到addressBook。

这是我的代码(仅适用于“名字”字段)::

NSLog(@"found CB");
NSLog(@"_code.text = %@", code.content);
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();

NSString *_n = [NSString stringWithFormat:@"_code.text = %@", code.content];
NSArray *n = [_n componentsSeparatedByString:@";"];
NSLog(@"_code.text = %@",n);

ABRecordSetValue(person, kABPersonFirstNameProperty, _name, nil);

ABAddressBookAddRecord(addressBook, person, nil);
CFRelease(addressBook);

ABNewPersonViewController *c = [[ABNewPersonViewController alloc] init];
[c setNewPersonViewDelegate:self];
[c setDisplayedPerson:person];
CFRelease(person);
[self.navigationController pushViewController:c animated:YES];
[c release];

MECARD QRCode已正确解码,并且显示了viewController ...但是所有URL(如:“MECARD:N:name; ORG:company; TEL:89878978; ...等等”)都进入第一个字段(FistName字段)...

分隔我的MECARD URL和在正确的字段中发送正确的数据时缺少什么?

最佳答案

希望能帮助到你

NSArray *chunks = [string componentsSeparatedByString: @";"];

07-26 07:06