2016-08-15 45 views
3

私はcontactsUI CNContactViewController.init(forNewContact: a)を表示専用に使用し、その値をサーバーに取得します。しかし、今は、アドレスブック/連絡先アプリに連絡先を追加することもできますが、これを防ぐことは可能でしょうか?連絡先を追加せずにCNContactViewControllerを使用する(スウィフト)

+0

あなたは、このためのソリューションを見つけますか? – beseder

+0

@beseder contactViewControllerデリゲートを使用すると、doneをクリックした直後にCNcontactが取得されるため、そのcncontactから識別子を取得して削除します。 ForNewContactを使用する - > done - >私たちのサーバー/アプリケーションにデータを送信する - >プログラムから連絡先をiosから削除する –

+0

ありがとう!それは私がまた終わったものです:-)しかし、それは悪いと感じる...そして何よりも:私は実際には必要ないユーザーの連絡先への書き込みアクセスが必要です。したがって、 'CNContactViewController'の' contactStore'プロパティは、文書化されているように動作しません。 – beseder

答えて

0

コンタクトFrameworkリファレンス:https://developer.apple.com/library/ios/documentation/Contacts/Reference/Contacts_Framework/

サンプル:ViewController.swift

import UIKit 
import ContactsUI 

class ViewController: UIViewController, CNContactPickerDelegate { 

let contactPickerViewController = CNContactPickerViewController() 
@IBOutlet var titleLabel: UILabel! 
@IBOutlet var valueLabel: UILabel! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    contactPickerViewController.delegate = self 
    // Do any additional setup after loading the view, typically from a nib. 

} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 

    // Dispose of any resources that can be recreated. 
} 

@IBAction func touchUpInside(sender: UIButton) { 
    self.presentViewController(contactPickerViewController, animated: true, completion: nil) 
} 

func contactPicker(picker: CNContactPickerViewController, didSelectContactProperty contactProperty: CNContactProperty) { 

    titleLabel.text = "" 
    valueLabel.text = "" 

    if let label = contactProperty.label { 
     titleLabel.text = CNLabeledValue.localizedStringForLabel(label) 
    } 

    if let phone = contactProperty.value as? CNPhoneNumber { 
     valueLabel.text = phone.stringValue 
    } 

    if let stringData = contactProperty.value as? String { 
     valueLabel.text = stringData 
    } 

    if let adress = contactProperty.value as? CNPostalAddress { 
     let adressString = adress.street + " " + adress.city + " " + adress.country + " " + adress.postalCode 
     valueLabel.text = adressString 
    } 

} 
} 

ダウンロードプロジェクトファイル:https://www.dropbox.com/s/yqdhqld0osp508b/Archive.zip?dl=0

+0

このソリューションは役に立ちましたか? –

関連する問題