SingleContactViewController.swift 2.37 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
            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 {
42 43 44 45
                profilePic.layer.cornerRadius = (profilePic?.frame.width ?? 0.0) / 2
                profilePic.clipsToBounds = true
                profilePic.layer.borderWidth = 3.0
                profilePic?.layer.borderColor = UIColor.white.cgColor
46 47
                if let imageData = UIImage(data: image){
                    profilePic.image = imageData
Javier Heisekce committed
48 49 50 51
                }
            }
        }
    }
52 53
    
    @IBAction func callButton(_ sender: Any) {
Javier Heisekce committed
54 55
        guard let number = URL(string: "tel://" + (selectedContact!.phoneNumbers.first?.value.stringValue)!) else { return }
        UIApplication.shared.open(number)
56 57
    }
    
Javier Heisekce committed
58 59
    @IBAction func callSpecificNumber(_ sender: Any) {
    }
Javier Heisekce committed
60
}