diff --git a/ContactsApp.xcodeproj/project.pbxproj b/ContactsApp.xcodeproj/project.pbxproj index 17ac8a0..9aed019 100644 --- a/ContactsApp.xcodeproj/project.pbxproj +++ b/ContactsApp.xcodeproj/project.pbxproj @@ -9,21 +9,23 @@ /* Begin PBXBuildFile section */ CE3351EC241A65D400BA57CA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3351EB241A65D400BA57CA /* AppDelegate.swift */; }; CE3351EE241A65D400BA57CA /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3351ED241A65D400BA57CA /* SceneDelegate.swift */; }; - CE3351F0241A65D400BA57CA /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3351EF241A65D400BA57CA /* ViewController.swift */; }; CE3351F3241A65D400BA57CA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F1241A65D400BA57CA /* Main.storyboard */; }; CE3351F5241A65D500BA57CA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F4241A65D500BA57CA /* Assets.xcassets */; }; CE3351F8241A65D500BA57CA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F6241A65D500BA57CA /* LaunchScreen.storyboard */; }; + CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */; }; + CEC9A381241C096D00F024EE /* SingleContactViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A380241C096D00F024EE /* SingleContactViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ CE3351E8241A65D400BA57CA /* ContactsApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ContactsApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; CE3351EB241A65D400BA57CA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; CE3351ED241A65D400BA57CA /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - CE3351EF241A65D400BA57CA /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; CE3351F2241A65D400BA57CA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; CE3351F4241A65D500BA57CA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; CE3351F7241A65D500BA57CA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; CE3351F9241A65D500BA57CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactsViewController.swift; sourceTree = ""; }; + CEC9A380241C096D00F024EE /* SingleContactViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleContactViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -58,11 +60,12 @@ children = ( CE3351EB241A65D400BA57CA /* AppDelegate.swift */, CE3351ED241A65D400BA57CA /* SceneDelegate.swift */, - CE3351EF241A65D400BA57CA /* ViewController.swift */, CE3351F1241A65D400BA57CA /* Main.storyboard */, CE3351F4241A65D500BA57CA /* Assets.xcassets */, CE3351F6241A65D500BA57CA /* LaunchScreen.storyboard */, CE3351F9241A65D500BA57CA /* Info.plist */, + CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */, + CEC9A380241C096D00F024EE /* SingleContactViewController.swift */, ); path = ContactsApp; sourceTree = ""; @@ -138,9 +141,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CE3351F0241A65D400BA57CA /* ViewController.swift in Sources */, CE3351EC241A65D400BA57CA /* AppDelegate.swift in Sources */, + CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */, CE3351EE241A65D400BA57CA /* SceneDelegate.swift in Sources */, + CEC9A381241C096D00F024EE /* SingleContactViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ContactsApp.xcodeproj/xcuserdata/user.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ContactsApp.xcodeproj/xcuserdata/user.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..1daeed1 --- /dev/null +++ b/ContactsApp.xcodeproj/xcuserdata/user.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,40 @@ + + + + + + + + + + + + + diff --git a/ContactsApp/Base.lproj/Main.storyboard b/ContactsApp/Base.lproj/Main.storyboard index 25a7638..e26ee0d 100644 --- a/ContactsApp/Base.lproj/Main.storyboard +++ b/ContactsApp/Base.lproj/Main.storyboard @@ -1,24 +1,125 @@ - + + - + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ContactsApp/ContactsViewController.swift b/ContactsApp/ContactsViewController.swift new file mode 100644 index 0000000..3b689df --- /dev/null +++ b/ContactsApp/ContactsViewController.swift @@ -0,0 +1,70 @@ +// +// ContactsViewController.swift +// ContactsApp +// +// Created by User on 3/13/20. +// Copyright © 2020 jheisecke. All rights reserved. +// + +import UIKit +import ContactsUI + +class ContactsViewController: UIViewController { + + @IBOutlet weak var contactsTable: UITableView! + + var contacts = [CNContact]() + let contactStore = CNContactStore() + + override func viewDidLoad() { + super.viewDidLoad() + importContacts() + contactsTable.tableFooterView = UIView(frame: .zero) + } + + func importContacts() { + + let keys = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName)] + //obtengo + let request = CNContactFetchRequest(keysToFetch: keys) + request.sortOrder = CNContactSortOrder.givenName + do { + try self.contactStore.enumerateContacts(with: request) { + (contact, stop) in + // Array containing all unified contacts from everywhere + self.contacts.append(contact) + } + } + catch { + print("unable to fetch contacts") + } + + print(contacts) + } + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if let singleContactVC = segue.destination as? SingleContactViewController { + if let selectedCnt = sender as? CNContact { + singleContactVC.selectedContact = selectedCnt + } + } + } +} +extension ContactsViewController: UITableViewDelegate, UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return contacts.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "contactName")! + cell.textLabel?.text = "\(contacts[indexPath.row].givenName) \(contacts[indexPath.row].familyName)" + return cell + } + + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let selectedContact = contacts[indexPath.row] + performSegue(withIdentifier: "gotocontact", sender: selectedContact) + } + + +} diff --git a/ContactsApp/Info.plist b/ContactsApp/Info.plist index 2a3483c..b6e86d0 100644 --- a/ContactsApp/Info.plist +++ b/ContactsApp/Info.plist @@ -2,6 +2,8 @@ + NSContactsUsageDescription + Voy a spamear a tus contactos CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable diff --git a/ContactsApp/SingleContactViewController.swift b/ContactsApp/SingleContactViewController.swift new file mode 100644 index 0000000..a50014b --- /dev/null +++ b/ContactsApp/SingleContactViewController.swift @@ -0,0 +1,37 @@ +// +// 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! + @IBOutlet weak var phoneNumber: UILabel! + + override func viewDidLoad() { + super.viewDidLoad() + if let contact = selectedContact{ + title = "\(contact.givenName) \(contact.familyName)" + contactFullname.text = "\(contact.givenName) \(contact.familyName)" + phoneNumber.text = contact.phoneNumbers.description + + if contact.imageDataAvailable { + if let image = contact.imageData { + if let imageData = UIImage(data: image){ + profilePic.image = imageData + } + } + } + + } + } + +} diff --git a/ContactsApp/ViewController.swift b/ContactsApp/ViewController.swift deleted file mode 100644 index cf8ebdd..0000000 --- a/ContactsApp/ViewController.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// ViewController.swift -// ContactsApp -// -// Created by User on 3/12/20. -// Copyright © 2020 jheisecke. All rights reserved. -// - -import UIKit - -class ViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - } - - -} -