- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 swift 的新手。我使用 APAdressBook Framework 来检索 iPhone 中的联系人。在 IOS 8.4 之前一切正常,但是当在模拟器和 iPhone 设备的 IOS 9 中检查时,它没有访问联系人,甚至没有显示警报消息,就像您想访问任何联系人一样如果可以,可以面对此类问题请给我您宝贵的答案吗?
最佳答案
苹果公司介绍Contacts.framework
来自 iOS 9。因此,最好使用此框架来检索联系人。
这是从通讯录应用中获取电子邮件或整个联系人的方法。
添加Contacts.framework
到您的项目。
创建或添加标题类型的新文件并命名为 yourProjectName-Bridging-Header.h
写#import <Contacts/Contacts.h>
将语句写入文件并保存并从build设置中设置此文件的适当路径。
现在创建方法
func getAllContacts() {
let status = CNContactStore.authorizationStatusForEntityType(CNEntityType.Contacts) as CNAuthorizationStatus
if status == CNAuthorizationStatus.Denied {
let alert = UIAlertController(title:nil, message:"This app previously was refused permissions to contacts; Please go to settings and grant permission to this app so it can use contacts", preferredStyle:UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title:"OK", style:UIAlertActionStyle.Default, handler:nil))
self.presentViewController(alert, animated:true, completion:nil)
return
}
let store = CNContactStore()
store.requestAccessForEntityType(CNEntityType.Contacts) { (granted:Bool, error:NSError?) -> Void in
if !granted {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
// user didn't grant access;
// so, again, tell user here why app needs permissions in order to do it's job;
// this is dispatched to the main queue because this request could be running on background thread
})
return
}
let arrContacts = NSMutableArray() // Declare this array globally, so you can access it in whole class.
let request = CNContactFetchRequest(keysToFetch:[CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey, CNContactFormatter.descriptorForRequiredKeysForStyle(CNContactFormatterStyle.FullName)])
do {
try store.enumerateContactsWithFetchRequest(request, usingBlock: { (contact:CNContact, stop:UnsafeMutablePointer<ObjCBool>) -> Void in
let arrEmail = contact.emailAddresses as NSArray
if arrEmail.count > 0 {
let dict = NSMutableDictionary()
dict.setValue((contact.givenName+" "+contact.familyName), forKey: "name")
let emails = NSMutableArray()
for index in 0...arrEmail.count {
let email:CNLabeledValue = arrEmail.objectAtIndex(index) as! CNLabeledValue
emails .addObject(email.value as! String)
}
dict.setValue(emails, forKey: "email")
arrContacts.addObject(dict) // Either retrieve only those contact who have email and store only name and email
}
arrContacts.addObject(contact) // either store all contact with all detail and simplifies later on
})
} catch {
return;
}
}
}
在你想要的地方调用这个方法self.getAllContacts()
当你想找回
for var index = 0; index < self.arrContacts.count; ++index {
let dict = self.arrContacts[index] as! NSDictionary
print(dict.valueForKey("name"))
print(dict.valueForKey("email"))
}
关于ios - 如何使用 swift 从 iPhone 联系人中检索电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33579794/
对于我的应用程序的一部分,我需要在选择该选项时显示所有联系人的列表(带有电话号码)。 这是按下按钮时调用的 Activity : package com.example.prototype01; im
我正在尝试使用 Google Contact API (C#) 将“生日”值添加到 Google Contact。谁能帮我解决这个问题。 我正在使用 Google 数据 API 设置 (1.4.0.2
如何使用 Google Contact API (c#) 在 Google Contact 中创建新的“自定义字段”? 我用过: ExtendedProperty obj_ExtendedProper
我正在 iPhone 应用程序中使用地址簿框架,并且我想获取项目公司名称。我在 AddressBookUI_Framework.pdf 中找不到此信息,有人可以解释一下吗? 问候 AddressBoo
我正在开发一个数据库来管理一家小公司的客户数据。客户是公司和机构(学校等),当然还有人/联系人。会有更多的范围及时添加,但现在我正在寻找关于核心设计本身的任何输入,如果有任何我在这里遗漏的东西可能会导
我正在使用 Swift Contacts 并尝试确定是否可以将 contacts.phoneNumbers 转换为 NSDictionary?即可以通过以下方式在 contacts.phoneNumb
我想要我的联系人的 ListView。我使用谷歌示例代码。问题是我一遍又一遍地获得相同的联系人: 吉姆 吉姆 吉姆 吉姆 吉姆 安娜 安娜 安娜 安娜 ... 如何获得我的联系人的 DISTINCT
对于我的应用程序,我需要导入 Gmail 地址簿,我可以按照“Gmail Contact API”进行操作。 最近 Gmail 添加了一些不属于 xml 的新字段(即生日、网站等)。 gmail ap
在 NetSuite 中编辑记录时,我有一个按钮需要能够获取所有联系人的名字、姓氏、电子邮件和可能的 Angular 色,以便我可以将其附加到我已经编写的其他代码中。我似乎无法弄清楚如何提取与记录关联
我们需要一种使用 Delphi/Pascal 代码读取(并且可以选择写入).vcf 文件的方法。带有源代码的免费库将是完美的。 最佳答案 AceVCard是delphi 2009的免费开放组件,兼容V
我正在模拟一个电话簿,其中有 ArrayList 。如何覆盖toString()函数为了拥有像这样的东西,我们正在做 System.out.println(phonebook) ? Name: nam
我正在尝试构建一个搜索 XML 表达式以与 Java 中的 Exchange Web 服务一起使用。我试图实现的是我可以通过电子邮件地址搜索所有联系人。我已经浏览了他们的文档,但未能使其正常工作。这是
我有一个项目正在进行,我想自动发送 SMS,并有时间和日期将 SMS 推送给特定的联系人。那么如何以简洁高效的方式从手机中提取联系人呢?基本上我希望用户按下一个按钮,然后应用程序转到联系人列表,然后用
我有一个表格 View ,显示所有联系人都使用 RealmSwift。如何使用谓词按电话号码过滤 Realm 联系人? class Contact: Object { @obj
我正在尝试使用 CNContactVCardSerialization 将联系人保存为 vcf,效果相对较好。我确实发现苹果不包含注释或图像作为 VCF 的一部分。我确实使用了 stackoverfl
我正在读取手机中的所有联系人,如下所示: Cursor cursor = MainApp.get().getContentResolver().query( C
我有具有 list 权限的应用程序 我的 Activity 尝试加载联系人: eDeviceRecordsLoader contactsLoader = new eDeviceRec
我正在尝试编辑组标题和注释, 编辑标题适用于系统组 和用户创建的组, 虽然注释列只有在系统组(例如“联系人”、“ friend ”、“家庭”、“同事”)时才会保留,我假设它不会为用户创建的组保存注释,
在我的应用中,我想将联系人与其他数据相关联。对联系人的引用必须尽可能持久,否则关联的数据将变成垃圾。 首先,我应该使用 ContactsContract.Contact.LOOKUP_KEY 访问聚合
我正在做一个应用程序,因为我显示从设备到 ListView 的所有联系人(姓名、号码、图像)。我想使用工具栏搜索从 ListView 中搜索联系人。我添加了工具栏搜索,但我不知道如何从列表中过滤联系人
我是一名优秀的程序员,十分优秀!