2

I have ViewController which has one button to navigate to CNContactViewController every thing works good I can go back and press the button again and so on .But my problem when I do one action on the CNContactViewController which is Share Contact the top navigation bar will disappear and for sure I'll stuck in this view .. this is the code:

    @IBAction func dothis(sender: AnyObject) {

    let contact = CNMutableContact()
    contact.givenName = "first Name"
    contact.familyName = "Last Name"
    contact.phoneNumbers = [CNLabeledValue(
        label:"Mobile",
        value:CNPhoneNumber(stringValue:"123456789")),
        CNLabeledValue(
            label:"Work Phone",
            value:CNPhoneNumber(stringValue:"1234"))]

    let workEmail = CNLabeledValue(label:"Work Email", value:"ex@whatever.com")
    contact.emailAddresses = [workEmail]

    let controller = CNContactViewController (forContact: contact)
    controller.contactStore = self.store
    controller.allowsEditing = false

    controller.displayedPropertyKeys =
        [CNContactPhoneNumbersKey,CNContactEmailAddressesKey, CNContactPostalAddressesKey]

    self.navigationController?
        .pushViewController(controller, animated: true)

}

Do I need to implement something more for share contact and other actions on the CNContactViewController ?

Notes:

1- All actions on contact card work good like Call or Send Message except Share Contact causing the problem.

2- When I compare the actions on my VC with the Contacts app I notice that the pop up options view of Share Contact comes over the navigation bar but in my app the options view come behind the navigation bar .

See Contacts app on the left and my app on the right :

Contacts App hereMy App

My Project file : Here it's small project

Zizoo
  • 1,694
  • 5
  • 20
  • 42
  • are you hidden the navigation bar in anywhere in your CNContactViewController – Anbu.Karthik Sep 07 '16 at 08:37
  • @Anbu.Karthik This is the only code I have , I made new project has one class which has this action to make sure the problem not in my old code – Zizoo Sep 07 '16 at 08:39
  • Are you seeing any error messages in the console? Your IBAction, do you also have a segue to the `CNContactViewController` in the storyboard? – Fogmeister Sep 07 '16 at 08:56
  • @Fogmeister No errors showing on console + no segue in the storyboard – Zizoo Sep 07 '16 at 08:57
  • @fogmeister you can see the project in the question , only one VC and one class – Zizoo Sep 07 '16 at 09:07
  • Need a help please – Zizoo Sep 07 '16 at 12:02
  • I download your demo, and test it with Xcode 8,iOS 10.The navigation bar will reappear when you click cancel button. Maybe you should try it. – wj2061 Sep 11 '16 at 11:06

2 Answers2

2

This is a bug according to this https://stackoverflow.com/a/33762209/3378099

Here is a non-elegant solution:

  1. Create an new class extending UINavigationController
  2. Assign it to your NavigationController in Storyboard
  3. Override function func setNavigationBarHidden(hidden: Bool, animated: Bool)

Reuploaded your project here

Community
  • 1
  • 1
korgx9
  • 1,234
  • 22
  • 30
  • actually I got more problems than before – Zizoo Sep 12 '16 at 21:16
  • What problems do you have now? – korgx9 Sep 13 '16 at 04:19
  • UI problems , like when I press create new contact and pop up view came the cancel button doesn't work also when trying to send email to the contact email it will open the mail app but behind the top bar navigation and more .. – Zizoo Sep 13 '16 at 11:25
1

I did update Xcode to version 8.0 with Swift 3 and the problem solved without changing the code.

Zizoo
  • 1,694
  • 5
  • 20
  • 42