renja01

Post-crash user feedback in Swift

Discussion created by renja01 Employee on Feb 14, 2015
Latest reply on Apr 1, 2015 by whibr08

The 14.4.1 release notes give an Objective-C example of using the new Feedback Reporting feature. Here is an example of how to implement this in Swift:

 

First we register for MAA crash notifications in our initial View Controller's viewDidLoad() function:

 

    // Register with MAA to receive crash notifications

    NSNotificationCenter.defaultCenter().addObserver(self, selector: "notifyCrash:", name: CAMAA_CRASH_OCCURRED, object: nil)

 

The example above assumes the existence of a "notifyCrash()" function in the View Controller which will segue to another Storyboard called "crashReport" to gather the user's feedback. Here is the notifyCrash() function:

 

    // Crash notification receiver

    func notifyCrash(crashNotification: NSNotification) {

        let crashData:NSDictionary = crashNotification.userInfo!

        let sb = UIStoryboard(name: "Main", bundle: nil)

        let crashVC = sb.instantiateViewControllerWithIdentifier("crashReport") as UIViewController

        self.presentViewController(crashVC, animated: true, completion: nil)           

    }

 

The View Controller for crashReport than calls the MAA setCustomerFeedback function to send the user's feedback:

 

    CAMDOReporter.sharedInstance().setCustomerFeedback("App crashed...")

Outcomes