当我尝试将分隔的字符串拆分为数组时,我遇到了一些问题。基本上,我想从MECARD QRCode传递结果并向addressBook添加新条目。
这是我的代码(仅适用于“FirstName”字段)::
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和&在正确的字段中发送正确的数据?
答案 0 :(得分:25)
希望有所帮助
NSArray *chunks = [string componentsSeparatedByString: @";"];