SingleContactViewController.swift 2.2 KB
Newer Older
Javier Heisekce committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//
//  SingleContactViewController.swift
//  ContactsApp
//
//  Created by User on 3/13/20.
//  Copyright © 2020 jheisecke. All rights reserved.
//

import UIKit
import ContactsUI

class SingleContactViewController: UIViewController {
    
    @IBOutlet weak var contactFullname: UILabel!
    var selectedContact : CNContact?
    @IBOutlet weak var profilePic: UIImageView!
17 18 19 20
    @IBOutlet weak var phoneNumber: UIButton!
    @IBOutlet weak var otherPhoneNumber: UIButton!
    @IBOutlet weak var otherPhoneLabel: UILabel!
    @IBOutlet weak var phoneLabel: UILabel!
Javier Heisekce committed
21 22 23
    
    override func viewDidLoad() {
        super.viewDidLoad()
Javier Heisekce committed
24
        if let contact = selectedContact {
Javier Heisekce committed
25 26
            title = "\(contact.givenName) \(contact.familyName)"
            contactFullname.text = "\(contact.givenName) \(contact.familyName)"
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
            if let phones = contact.phoneNumbers.first {
                let phoneTitle :String  =  CNLabeledValue<NSString>.localizedString(forLabel: phones.label! )
                phoneLabel.text = phoneTitle
                phoneNumber.setTitle(phones.value.stringValue, for: .normal)
                phoneLabel.isHidden = false
                phoneNumber.isHidden = false
            }
            if contact.phoneNumbers.last != contact.phoneNumbers.first, let phones = contact.phoneNumbers.last {
                let phoneTitle :String  =  CNLabeledValue<NSString>.localizedString(forLabel: phones.label! )
                otherPhoneLabel.text = phoneTitle
                otherPhoneNumber.setTitle(phones.value.stringValue, for: .normal)
                otherPhoneLabel.isHidden = false
                otherPhoneNumber.isHidden = false
            }
            if let image = contact.imageData {
                profilePic.layer.cornerRadius = profilePic.frame.height / 2
                if let imageData = UIImage(data: image){
                    profilePic.image = imageData
Javier Heisekce committed
45 46 47 48
                }
            }
        }
    }
49 50
    
    @IBAction func callButton(_ sender: Any) {
Javier Heisekce committed
51 52
        guard let number = URL(string: "tel://" + (selectedContact!.phoneNumbers.first?.value.stringValue)!) else { return }
        UIApplication.shared.open(number)
53 54
    }
    
Javier Heisekce committed
55 56
    @IBAction func callSpecificNumber(_ sender: Any) {
    }
Javier Heisekce committed
57
}