From 0c9cb8b3650ed8412ccadb5bdeb2417479db7cea Mon Sep 17 00:00:00 2001 From: touchbee Date: Wed, 11 Apr 2012 18:34:44 -0700 Subject: [PATCH 1/2] Pull the owners profile photo from the address book. --- JBDeviceOwner/JBDeviceOwner.h | 1 + JBDeviceOwner/JBDeviceOwner.m | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/JBDeviceOwner/JBDeviceOwner.h b/JBDeviceOwner/JBDeviceOwner.h index 81daf7c..3574d7c 100644 --- a/JBDeviceOwner/JBDeviceOwner.h +++ b/JBDeviceOwner/JBDeviceOwner.h @@ -20,5 +20,6 @@ @property (strong, nonatomic, readonly) NSString *lastName; @property (strong, nonatomic, readonly) NSString *middleName; @property (strong, nonatomic, readonly) NSString *phone; +@property (strong, nonatomic, readonly) UIImage *photo; @end diff --git a/JBDeviceOwner/JBDeviceOwner.m b/JBDeviceOwner/JBDeviceOwner.m index 774f931..b33e939 100644 --- a/JBDeviceOwner/JBDeviceOwner.m +++ b/JBDeviceOwner/JBDeviceOwner.m @@ -19,6 +19,7 @@ @interface JBDeviceOwner () @property (strong, nonatomic, readwrite) NSString *lastName; @property (strong, nonatomic, readwrite) NSString *middleName; @property (strong, nonatomic, readwrite) NSString *phone; +@property (strong, nonatomic, readwrite) UIImage *photo; - (void)populateFromAddressBook; @@ -34,6 +35,8 @@ @implementation JBDeviceOwner @synthesize lastName; @synthesize middleName; @synthesize phone; +@synthesize photo; + #pragma mark - Creation/Removal Methods @@ -45,8 +48,10 @@ - (id)initWithDevice:(UIDevice *)aDevice { NSMutableString *deviceName = [NSMutableString stringWithString:self.device.name]; NSArray *stringsToStrip = [NSArray arrayWithObjects:@"'s", + @"’s", @"ipad", - @"iphone" + @"iphone", + @"ipod", @"ipod touch", nil]; for (NSString *stringToStrip in stringsToStrip) { @@ -104,6 +109,29 @@ - (void)populateFromAddressBook { } CFRelease(phoneMultiValue); + + // Photo + if( ABPersonHasImageData( owner )) { + + if( &ABPersonCopyImageDataWithFormat != nil ) { + + // iOS >= 4.1 + CFDataRef data = ABPersonCopyImageDataWithFormat( owner, kABPersonImageFormatThumbnail ); + + self.photo = [UIImage imageWithData:(__bridge NSData *)data]; + + CFRelease( data ); + } + else + { + // iOS < 4.1 + CFDataRef data = ABPersonCopyImageData( owner ); + + self.photo = [UIImage imageWithData:(__bridge NSData *)data]; + + CFRelease( data ); + } + } } CFRelease(addressBook); From 42a94b3dcb415422917f6b04aaa03af5438b8fdf Mon Sep 17 00:00:00 2001 From: touchbee Date: Fri, 13 Apr 2012 19:25:57 -0700 Subject: [PATCH 2/2] Pulled "iPod touch" before "iPod". Removed image retrieval for iOS < 4.2. Reformatted code. --- JBDeviceOwner/JBDeviceOwner.m | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/JBDeviceOwner/JBDeviceOwner.m b/JBDeviceOwner/JBDeviceOwner.m index b33e939..9bf8e49 100644 --- a/JBDeviceOwner/JBDeviceOwner.m +++ b/JBDeviceOwner/JBDeviceOwner.m @@ -51,8 +51,8 @@ - (id)initWithDevice:(UIDevice *)aDevice { @"’s", @"ipad", @"iphone", - @"ipod", - @"ipod touch", nil]; + @"ipod touch", + @"ipod", nil]; for (NSString *stringToStrip in stringsToStrip) { [deviceName replaceOccurrencesOfString:stringToStrip @@ -110,28 +110,18 @@ - (void)populateFromAddressBook { CFRelease(phoneMultiValue); - // Photo - if( ABPersonHasImageData( owner )) { + // Photo + if( ABPersonHasImageData( owner )) { - if( &ABPersonCopyImageDataWithFormat != nil ) { + if( &ABPersonCopyImageDataWithFormat != nil ) { - // iOS >= 4.1 - CFDataRef data = ABPersonCopyImageDataWithFormat( owner, kABPersonImageFormatThumbnail ); + CFDataRef data = ABPersonCopyImageDataWithFormat( owner, kABPersonImageFormatThumbnail ); - self.photo = [UIImage imageWithData:(__bridge NSData *)data]; + self.photo = [UIImage imageWithData:(__bridge NSData *)data]; - CFRelease( data ); - } - else - { - // iOS < 4.1 - CFDataRef data = ABPersonCopyImageData( owner ); - - self.photo = [UIImage imageWithData:(__bridge NSData *)data]; - - CFRelease( data ); - } - } + CFRelease( data ); + } + } } CFRelease(addressBook);