Ios 如何从联系人获取联系人图像URL?

Ios 如何从联系人获取联系人图像URL?,ios,iphone,objective-c,uiimage,abaddressbook,Ios,Iphone,Objective C,Uiimage,Abaddressbook,我需要从通讯录中获取每个联系人的图像url。我现在可以获取图像,但问题是我需要获取特定人物图像的资产URL。目前我正在通过 [UIImage imageWithData:(__bridge NSData *)ABPersonCopyImageData(person)] 请帮助我获取该特定图像的资产URL。谢谢我认为您需要制作数据的本地副本,然后在数据库中保存对该本地副本的引用: //create a fileName perhaps based on the contact name or a

我需要从通讯录中获取每个联系人的图像url。我现在可以获取图像,但问题是我需要获取特定人物图像的资产URL。目前我正在通过

[UIImage imageWithData:(__bridge NSData *)ABPersonCopyImageData(person)]

请帮助我获取该特定图像的资产URL。谢谢

我认为您需要制作数据的本地副本,然后在数据库中保存对该本地副本的引用:

//create a fileName perhaps based on the contact name or a GUID
    NSError *err;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);//find the cache dir. You might want to consider using the doc dir instead
    NSString * path = [paths  objectAtIndex:0];
    path = [path stringByAppendingPathComponent:fileName];
   [imgData writeToFile:path options:NSDataWritingAtomic error:&err];
   if(!err)
   {
   ///save path to the DB
   }

SWIFT 3及以上版本的简单解决方案

var users = [User]()   
     func getContact(){
            if #available(iOS 9.0, *) {
                let contactStore = CNContactStore()
                _ = [
                    CNContactFormatter.descriptorForRequiredKeys(for: .fullName),
                    CNContactEmailAddressesKey]

                // Get all the containers
                var allContainers: [CNContainer] = []
                do {
                    allContainers = try contactStore.containers(matching: nil)
                } catch {
                    print("Error fetching containers")
                }


                do {
                    try contactStore.enumerateContacts(with: CNContactFetchRequest(keysToFetch: [CNContactGivenNameKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor, CNContactEmailAddressesKey as CNKeyDescriptor, CNContactImageDataKey as CNKeyDescriptor])) {
                        (contact, cursor) -> Void in
                        if (!contact.emailAddresses.isEmpty){
                            //self.email.append(String(contact.emailAddresses))
                            for emailAdd:CNLabeledValue in contact.emailAddresses {
                                let a = emailAdd.value
                                if a as String != ""{
                                    for (index, data) in self.users.enumerated(){
                                        if a as? String == data.email{
                                            print("Emial found in Contact",index,a as String)
                                            if contact.isKeyAvailable(CNContactImageDataKey) {
                                                if let img = contact.imageData{
                                                    self.users[index] = User( id: self.users[index].id, firstName: self.users[index].firstName, lastName: self.users[index].lastName, email: self.users[index].email, user_type: self.users[index].user_type,user_image: UIImage(data: img))
                                                    print("imag",img)
                                                }
                                            }
                                        }
                                    }
                                    self.email.append(a as String)
                                }
                            }
                        }
                    }
                }
                catch{
                    print("Handle the error please")
                }
            }else{
                // Fallback
            }
            filteredData = email
            dropDown.dataSource = filteredData
        }

我不认为你可以得到资产的网址,你可以读图像和写它。为什么需要URL?@EsbenB,因为我需要将其保存到DB,我认为将图像作为数据保存到DB不是一个好主意。如果你有其他建议,对我会更有帮助。谢谢