mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Added rudimentary handling of address information. Since we can't really parse
it into the detailed format the iPhone's Address Book API wants, we punt a bit and instead just break it into multiple pieces, each on a separate line, and store that as the 'street' part of the 'Home' address for the contact we're creating. That way, at least the information is captured rather than lost, and the user can sync it to their computer, copy-and-paste it into the appropriate fields, and then sync it back to the iPhone. Not idea, but better than nothing, which is what we had before. git-svn-id: https://zxing.googlecode.com/svn/trunk@589 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
6db50e0b79
commit
c7949c34d1
|
@ -120,13 +120,45 @@
|
|||
}
|
||||
|
||||
if (self.address) {
|
||||
/*
|
||||
// we can't parse all the possible address formats, alas, so we punt by putting
|
||||
// the entire thing into a multi-line 'street' address.
|
||||
// This won't look great on the phone, but at least the info will be there,
|
||||
// and can be syned to a desktop computer, adjusted as necessary, and so on.
|
||||
|
||||
// split the address into parts at each comma or return
|
||||
NSArray *parts =
|
||||
[self.address componentsSeparatedByCharactersInSet:
|
||||
[NSCharacterSet characterSetWithCharactersInString:@",;\r\n"]];
|
||||
NSMutableArray *strippedParts = [NSMutableArray arrayWithCapacity:[parts count]];
|
||||
// for each part:
|
||||
for (NSString *part in parts) {
|
||||
// strip the part of whitespace
|
||||
NSString *strippedPart =
|
||||
[part stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
||||
if ([strippedPart length] > 0) {
|
||||
// if there is anything in this address part, add it to the list of stripped parts
|
||||
[strippedParts addObject:strippedPart];
|
||||
}
|
||||
}
|
||||
// finally, create a 'street' address by concatenating all the stripped parts, separated by linefeeds
|
||||
NSString *street = [strippedParts componentsJoinedByString:@"\n"];
|
||||
|
||||
CFMutableDictionaryRef addressDict =
|
||||
CFDictionaryCreateMutable(NULL,
|
||||
1,
|
||||
&kCFTypeDictionaryKeyCallBacks,
|
||||
&kCFTypeDictionaryValueCallBacks);
|
||||
CFDictionarySetValue(addressDict, kABPersonAddressStreetKey, street);
|
||||
|
||||
ABMutableMultiValueRef addressMultiValue =
|
||||
ABMultiValueCreateMutable(kABStringPropertyType);
|
||||
ABMultiValueCreateMutable(kABStringPropertyType);
|
||||
ABMultiValueAddValueAndLabel(addressMultiValue,
|
||||
NULL, NULL,
|
||||
addressDict,
|
||||
kABHomeLabel,
|
||||
NULL);
|
||||
*/
|
||||
ABRecordSetValue(person, kABPersonAddressProperty, addressMultiValue, error);
|
||||
CFRelease(addressMultiValue);
|
||||
CFRelease(addressDict);
|
||||
}
|
||||
|
||||
ABUnknownPersonViewController *unknownPersonViewController =
|
||||
|
|
Loading…
Reference in a new issue