You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2015/12/01 15:37:07 UTC

cordova-plugin-contacts git commit: CB-6979 Don't create duplicates for extracted contacts photos

Repository: cordova-plugin-contacts
Updated Branches:
  refs/heads/master dbf415ac0 -> ecf040a74


CB-6979 Don't create duplicates for extracted contacts photos

This closes #89


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/ecf040a7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/ecf040a7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/ecf040a7

Branch: refs/heads/master
Commit: ecf040a7406e4b52b3c56fb174b2e83a5a9da496
Parents: dbf415a
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Thu Nov 26 15:21:57 2015 +0300
Committer: Vladimir Kotikov <v-...@microsoft.com>
Committed: Tue Dec 1 17:36:42 2015 +0300

----------------------------------------------------------------------
 src/ios/CDVContact.m | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ecf040a7/src/ios/CDVContact.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVContact.m b/src/ios/CDVContact.m
index 0149a92..a1dd85d 100644
--- a/src/ios/CDVContact.m
+++ b/src/ios/CDVContact.m
@@ -1328,6 +1328,7 @@ static NSDictionary* org_apache_cordova_contacts_defaultFields = nil;
     NSMutableArray* photos = nil;
 
     if (ABPersonHasImageData(self.record)) {
+        CFIndex photoId = ABRecordGetRecordID(self.record);
         CFDataRef photoData = ABPersonCopyImageData(self.record);
         if (!photoData) {
             return nil;
@@ -1337,17 +1338,10 @@ static NSDictionary* org_apache_cordova_contacts_defaultFields = nil;
         // write to temp directory and store URI in photos array
         // get the temp directory path
         NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath];
-        NSError* err = nil;
-        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)];
+        NSString* filePath = [NSString stringWithFormat:@"%@/contact_photo_%ld", docsPath, photoId];
 
         // save file
-        if ([data writeToFile:filePath options:NSAtomicWrite error:&err]) {
+        if ([data writeToFile:filePath atomically:YES]) {
             photos = [NSMutableArray arrayWithCapacity:1];
             NSMutableDictionary* newDict = [NSMutableDictionary dictionaryWithCapacity:2];
             [newDict setObject:filePath forKey:kW3ContactFieldValue];


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org