0

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)
}
Lyndsey Scott
  • 37,080
  • 10
  • 92
  • 128
alex
  • 4,804
  • 14
  • 51
  • 86

1 Answers1

1

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.)

Lyndsey Scott
  • 37,080
  • 10
  • 92
  • 128
  • I second using Fabric. Free and will be of immense help! – gikygik Jan 26 '16 at 19:10
  • tx for the Fabric recommendation will check that one out and incorporate it in one of my next builds. But now I am "screwed"?. About the unwrapping I am sure both are not nil as the first visitor data is mine. How can I check my app on different iOS installements in the simulator? – alex Jan 26 '16 at 19:13
  • @alex Testing on different simulators probably won't hep solve your issue, but as of Xcode 7 you can create provisioning profiles directly in Xcode and run an app from any device, including your girlfriend's. How-to: https://livecode.com/how-to-create-a-free-ios-development-provisioning-profile/ – Lyndsey Scott Jan 26 '16 at 19:35
  • choose the "Download Simulators" at the bottom of where you would switch simulator device and choose ios 8.3 to download if thats what you need. – gikygik Jan 26 '16 at 19:35
  • @alex And check the address book to make sure that the First and Last names are in fact typed in separate fields. – Lyndsey Scott Jan 26 '16 at 19:37
  • @LyndseyScott Not exactly understand what you mean I don't use textfields. First and last name are two different variables from my server. Based on a QR code I retrieve some contact data from my server -> show the data in the app -> give the possiblitly to save the data to contact list. And why does it work on my device if I download and install from the app store? Then it should be an iOS issue, correct? – alex Jan 26 '16 at 19:46
  • @alex What code are you using to initialize selectedVisitor? – Lyndsey Scott Jan 26 '16 at 19:54
  • In my main viewcontroller I have ` if let indexPath = tableView.indexPathForCell(sender as! UITableViewCell) { let selectedVisitor = scannedVisitors[indexPath.row] as ScannedVisitor let detailVC = segue.destinationViewController as! DetailViewController detailVC.selectedVisitor = selectedVisitor }` Oh and in detail viewcontroller I set textfield like so lblCompany.text = selectedVisitor?.sCompany – alex Jan 26 '16 at 20:06
  • btw: download ios 8.3 and in Simulator my app works as expected :? Also on simulator io9.2 and my iPhone 5s device ios 8.1.2 – alex Jan 26 '16 at 20:13
  • @alex When exactly does the crash happen? – Lyndsey Scott Jan 26 '16 at 20:21