PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 6, 2022

[FIXED] How to open Edit Contact UI for existing contact in swift using Contact UI

 November 06, 2022     contacts, ios, swift     No comments   

Issue

I am working on iOS application in which I want to Add new contact in Phonebook using Contact UI. I know how to open Contact UI for New Contact but I am facing difficulty in opening the existing Contact in Contact UI for Edit.

I am opening New Contact UI as

    let contact = CNMutableContact()
    
    let localizedLabelString = CNLabeledValue<NSString>.localizedString(forLabel: CNLabelPhoneNumberMobile)
    let phoneNumber = CNPhoneNumber(stringValue: contacTNumber )
    let labeledPhoneNumber = CNLabeledValue(label: localizedLabelString, value: phoneNumber)
    contact.phoneNumbers.append(labeledPhoneNumber)
    
    let controller = CNContactViewController(forNewContact: contact)
    controller.delegate = self
    controller.displayedPropertyKeys = [CNContactPhoneNumbersKey, CNContactGivenNameKey]
    let nav = UINavigationController(rootViewController: controller)
    self.present(nav, animated: true, completion: nil)

Below is the Edit contact UI that I want to open.

enter image description here


Solution

There are different constructors for the view controller depending on whether the contact is new, existing or unknown.

init(for: CNContact)
Initializes a view controller for an existing contact.

init(forUnknownContact: CNContact)
Initializes a view controller for an unknown contact.

init(forNewContact: CNContact?)
Initializes a view controller for a new contact.

You code is using init(forNewContact:). Try using init(for:)



Answered By - Dale
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing