您正在使用CNContacts
来获取我的联系人,但需要大约两分钟才能显示swift中的所有联系人。有什么方法可以加快我的提取时间吗?
do
{
try store.enumerateContactsWithFetchRequest(request)
{ contact, stop in
contacts.append(contact)
}
}
catch
{
print(error)
}
for contact in contacts
{
let formatter = CNContactFormatter()
formatter.style = .FullName
if(((formatter.stringFromContact(contact))) != nil)
{
for phoneNumber:CNLabeledValue in contact.phoneNumbers
{
let number = (contact.phoneNumbers[0].value as! CNPhoneNumber).valueForKey("digits") as! String
let lable :String = CNLabeledValue.localizedStringForLabel(phoneNumber.label)
if (lable.containsString("mobile"))
{
if((contact.emailAddresses.isEmpty))
{
self.Allemail.addObject((""))
}
else
{
self.Allemail.addObject((contact.emailAddresses[0].value))
}
self.Contactname=NSString(format:"'%@'",(formatter.stringFromContact(contact))!)
let contactnumber=NSString(format:"'%@'",number)
self.ContactsDictionary.addObject(self.Contactname)
self.allNumbers.addObject(contactnumber as String)
}
}
for i in 0..<self.ContactsDictionary.count
{
if(i == 0)
{
self.jsonstring = "[{'Name':\(self.ContactsDictionary.objectAtIndex(i)),'Number':\(self.allNumbers.objectAtIndex(i))}"
}else
{
self.jsonstring = "\(self.jsonstring),{'Name':\(self.ContactsDictionary.objectAtIndex(i)),'Number':\(self.allNumbers.objectAtIndex(i))}"
}
}
self.jsonstring = "\(self.jsonstring)]"
}
}
self.contactupload()