Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

ios - 仅从iPhone获取新的/修改的电话联系人(Get only new/modified phone contacts from iPhone)

I want to import all phone contacts into app first time only and save on server.

(我只想在第一次将所有电话联系人导入应用程序并保存在服务器上。)

Second time wants to imports only new, modified and deleted contacts into an app and sync with contacts saved on the server which should be done according to created/modified date of contacts.

(第二次想只将新的,已修改和已删除的联系人导入应用程序,并与服务器上保存的联系人同步,这应根据联系人的创建/修改日期来完成。)

From iOS 9, Apple won't allow to get create/modified date using Contacts Framework

(从iOS 9开始,Apple不允许使用Contacts Framework获取创建/修改日期)

How can I achieve with better approach?

(如何更好地实现?)

  ask by Harshal Wani translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should add observer for change contact list notification like this:

(您应该为更改联系人列表通知添加观察者,如下所示:)

    NotificationCenter.default.addObserver(self,selector: #selector(self.addressBookDidChange(_:)), name: NSNotification.Name.CNContactStoreDidChange,object: nil)

And then

(然后)

@objc func addressBookDidChange(_ notification: Notification){
    print(notification.object as Any, notification.userInfo as Any)
    //remove observer so far to prevent double method calling when making operations with contacts
    NotificationCenter.default.removeObserver(self, name: NSNotification.Name.CNContactStoreDidChange, object: nil)

    //processing


    //at some point return observer
    NotificationCenter.default.addObserver(self,selector: #selector(ContactsListVC.addressBookDidChange(_:)), name: NSNotification.Name.CNContactStoreDidChange,object: nil)



}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...