when using CNContactViewController to present a contact detail info, the system CNContactViewController appear some UI issues.
On iOS 26, the Poster avatar overlaps with the title "Edit device contact"
On iPadOS26 with device(not simulator), when click 'Add photo', the CNContactViewController will auto dismiss, and the console output some error log:
below are the sample code:
AppDelegate.swift:
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
let window: UIWindow = UIWindow()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let vc = SplitViewController(primary: TabBarViewController(), secondary: ViewController())
window.rootViewController = vc
window.makeKeyAndVisible()
return true
}
}
SplitViewController.swift:
import UIKit
class SplitViewController: UISplitViewController {
init(primary: UIViewController, secondary: UIViewController) {
super.init(nibName: nil, bundle: nil)
preferredDisplayMode = .oneBesideSecondary
presentsWithGesture = false
delegate = self
viewControllers = [primary, secondary]
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension SplitViewController: UISplitViewControllerDelegate {
}
TabBarViewController.swift:
import UIKit
class BaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class HomeViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
navigationItem.title = "Home"
tabBarItem = UITabBarItem(title: "Home", image: UIImage(systemName: "house"), tag: 0)
}
}
class TabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let homeVC = HomeViewController()
let homeNav = UINavigationController(rootViewController: homeVC)
viewControllers = [homeNav]
ContactManager.shared.getAllContactIdentifiers()
}
}
ViewController.swift:
import UIKit
import Contacts
import ContactsUI
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemPink
let button = UIButton(frame: .zero)
button.backgroundColor = .orange
button.setTitle("show contact", for: .normal)
button.addTarget(self, action: #selector(showContactInfo), for: .touchUpInside)
button.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(button)
button.widthAnchor.constraint(equalToConstant: 200).isActive = true
button.heightAnchor.constraint(equalToConstant: 60).isActive = true
button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
button.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}
@objc private func showContactInfo() {
print("showContactInfo")
let identifier = ContactManager.shared.identifiers[0]
let currentContact = try? CNContactStore().unifiedContact(withIdentifier: identifier, keysToFetch: [CNContactViewController.descriptorForRequiredKeys()])
guard let contact: CNMutableContact = currentContact?.mutableCopy() as? CNMutableContact else {
return
}
let vc = CNContactViewController(forNewContact: contact)
vc.delegate = self
vc.title = "Edit Device Contact"
vc.allowsActions = false
vc.contactStore = CNContactStore()
let navigationVC: UINavigationController = UINavigationController(rootViewController: vc)
let appDelegate = UIApplication.shared.delegate as? AppDelegate
appDelegate?.window.rootViewController?.present(navigationVC, animated: true, completion: nil)
}
}
extension ViewController: CNContactViewControllerDelegate {
public func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) {
viewController.dismiss(animated: true, completion: nil)
}
}