alex
alex

Reputation: 4924

App in the appstore crashes when adding person to contacts?

After 8 days and a minor metadata fix, I was glad my app was in the app store. But unfortunately it crashes on my girlfriend's iPhone IOS 8.3 and I created it with 8.1 in mind.

1/ As this is my first app, where can I find the crash report of my app(if one exists)?

2/ How can I check the authorization to contacts after I have installed the app ?

3/ And what could be the cause of the crash, when adding a contact to the contact list?

    @IBAction func addToContacts(sender: AnyObject) {
        let authorizationStatus = ABAddressBookGetAuthorizationStatus()
        switch authorizationStatus {
        case .Denied, .Restricted:
            //1
        print("Denied")
        displayCantAddContactAlert()

        case .Authorized:
        //2
        print("Authorized")
        addVisitorToContacts()
        case .NotDetermined:
        //3
        print("Not Determined")
        promptForAddressBookRequestAccess(addContacts)
        }
        print("Add to contacts")
    }

     // MARK: - Permissions
        func promptForAddressBookRequestAccess(addContacts: UIButton) {
            //var err: Unmanaged<CFError>? = nil

            ABAddressBookRequestAccessWithCompletion(addressBookRef) {
                (granted: Bool, error: CFError!) in
                dispatch_async(dispatch_get_main_queue()) {
                    if !granted {
                        print("Just denied")
                        self.displayCantAddContactAlert()
                    } else {
                        print("Just authorized")
                        self.addVisitorToContacts()
                    }
                }
            }
        } 

addToContacts function

func addVisitorToContacts() {

    let selectedVisitor = self.selectedVisitor!
    print(" hello \(selectedVisitor.sFirstName!) ")
    if let visitorRecordIfExists: ABRecordRef = getVisitorRecordCoreData(selectedVisitor) {// was 2
        displayContactExistsAlert(visitorRecordIfExists)
        return
    }
    let visitorRecord: ABRecordRef = makeAndAddVisitorRecordCoreData(selectedVisitor)
    let contactAddedAlert = UIAlertController(title: "\(selectedVisitor.sLastName!) added.",
        message: nil, preferredStyle: .Alert)
    contactAddedAlert.addAction(UIAlertAction(title: "Add 2 \"Visitors\" Group", style: .Default, handler: { action in
        self.addVisitorToGroup(visitorRecord)
    }))
    contactAddedAlert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
    presentViewController(contactAddedAlert, animated: true, completion: nil)
}

Upvotes: 0

Views: 102

Answers (1)

Lyndsey Scott
Lyndsey Scott

Reputation: 37300

In addVisitorToContact, you unwrap the selected contact's first and last name, neither of which is a required field when creating a contact. My guess is that you're attempting to unwrap a nil value, thus the crash.

(In order to check crash info in the future though, I recommend installing Fabric in your app. It's free.)

Upvotes: 1

Related Questions