diff options
Diffstat (limited to 'iPhone/CordovaLib/Classes/CDVContact.m')
-rwxr-xr-x | iPhone/CordovaLib/Classes/CDVContact.m | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/iPhone/CordovaLib/Classes/CDVContact.m b/iPhone/CordovaLib/Classes/CDVContact.m index 9389207..9efaf10 100755 --- a/iPhone/CordovaLib/Classes/CDVContact.m +++ b/iPhone/CordovaLib/Classes/CDVContact.m @@ -1146,7 +1146,7 @@ static NSDictionary* org_apache_cordova_contacts_defaultFields = nil; if (fields == nil) { // no name fields requested return nil; } - id __weak value; + CFStringRef value; NSObject* addresses; ABMultiValueRef multi = ABRecordCopyValue(self.record, kABPersonAddressProperty); CFIndex count = multi ? ABMultiValueGetCount(multi) : 0; @@ -1174,7 +1174,13 @@ static NSDictionary* org_apache_cordova_contacts_defaultFields = nil; id key = [[CDVContact defaultW3CtoAB] valueForKey:k]; if (key && ![k isKindOfClass:[NSNull class]]) { bFound = CFDictionaryGetValueIfPresent(dict, (__bridge const void*)key, (void*)&value); - [newAddress setObject:(bFound && value != NULL) ? (id) value:[NSNull null] forKey:k]; + if (bFound && (value != NULL)) { + CFRetain(value); + [newAddress setObject:(__bridge id)value forKey:k]; + CFRelease(value); + } else { + [newAddress setObject:[NSNull null] forKey:k]; + } } else { // was a property that iPhone doesn't support [newAddress setObject:[NSNull null] forKey:k]; @@ -1221,16 +1227,28 @@ static NSDictionary* org_apache_cordova_contacts_defaultFields = nil; NSMutableDictionary* newDict = [NSMutableDictionary dictionaryWithCapacity:3]; // iOS has label property (work, home, other) for each IM but W3C contact API doesn't use CFDictionaryRef dict = (CFDictionaryRef)ABMultiValueCopyValueAtIndex(multi, i); - NSString* __weak value; // all values should be CFStringRefs / NSString* + CFStringRef value; // all values should be CFStringRefs / NSString* bool bFound; if ([fields containsObject:kW3ContactFieldValue]) { // value = user name bFound = CFDictionaryGetValueIfPresent(dict, kABPersonInstantMessageUsernameKey, (void*)&value); - [newDict setObject:(bFound && value != NULL) ? (id) value:[NSNull null] forKey:kW3ContactFieldValue]; + if (bFound && (value != NULL)) { + CFRetain(value); + [newDict setObject:(__bridge id)value forKey:kW3ContactFieldValue]; + CFRelease(value); + } else { + [newDict setObject:[NSNull null] forKey:kW3ContactFieldValue]; + } } if ([fields containsObject:kW3ContactFieldType]) { bFound = CFDictionaryGetValueIfPresent(dict, kABPersonInstantMessageServiceKey, (void*)&value); - [newDict setObject:(bFound && value != NULL) ? (id)[[CDVContact class] convertPropertyLabelToContactType:value]:[NSNull null] forKey:kW3ContactFieldType]; + if (bFound && (value != NULL)) { + CFRetain(value); + [newDict setObject:(id)[[CDVContact class] convertPropertyLabelToContactType:(__bridge NSString*)value] forKey:kW3ContactFieldType]; + CFRelease(value); + } else { + [newDict setObject:[NSNull null] forKey:kW3ContactFieldType]; + } } // always set ID id identifier = [NSNumber numberWithUnsignedInt:ABMultiValueGetIdentifierAtIndex(multi, i)]; @@ -1311,13 +1329,14 @@ static NSDictionary* org_apache_cordova_contacts_defaultFields = nil; // get the temp directory path NSString* docsPath = [NSTemporaryDirectory ()stringByStandardizingPath]; NSError* err = nil; - NSFileManager* fileMgr = [[NSFileManager alloc] init]; - // generate unique file name - NSString* filePath; - int i = 1; - do { - filePath = [NSString stringWithFormat:@"%@/photo_%03d.jpg", docsPath, i++]; - } while ([fileMgr fileExistsAtPath:filePath]); + NSString* filePath = [NSString stringWithFormat:@"%@/photo_XXXXX", docsPath]; + char template[filePath.length + 1]; + strcpy(template, [filePath cStringUsingEncoding:NSASCIIStringEncoding]); + mkstemp(template); + filePath = [[NSFileManager defaultManager] + stringWithFileSystemRepresentation:template + length:strlen(template)]; + // save file if ([data writeToFile:filePath options:NSAtomicWrite error:&err]) { photos = [NSMutableArray arrayWithCapacity:1]; @@ -1694,7 +1713,7 @@ static NSDictionary* org_apache_cordova_contacts_defaultFields = nil; for (NSString* member in fields) { NSString* abKey = [[CDVContact defaultW3CtoAB] valueForKey:member]; // im and address fields are all strings - NSString* __weak abValue = nil; + CFStringRef abValue = nil; if (abKey) { NSString* testString = nil; if ([member isEqualToString:kW3ContactImType]) { @@ -1708,8 +1727,10 @@ static NSDictionary* org_apache_cordova_contacts_defaultFields = nil; if (testString != nil) { BOOL bExists = CFDictionaryGetValueIfPresent(dict, (__bridge const void*)abKey, (void*)&abValue); if (bExists) { + CFRetain(abValue); NSPredicate* containPred = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@", testString]; - bFound = [containPred evaluateWithObject:abValue]; + bFound = [containPred evaluateWithObject:(__bridge id)abValue]; + CFRelease(abValue); } } } |