问题
My small task is, how to mail crash report? I don't know whether this example is right or wrong.
Coding:
override func viewDidLoad() {
super.viewDidLoad()
func exceptionHandler(exception : NSException) {
print("\n\n \(exception)")
print("\n\n \(exception.callStackSymbols)")
mailAcn() // SENDING MAIL ACTION WHEN EXCEPTION CAUGHT
}
NSSetUncaughtExceptionHandler(exceptionHandler) //Error: A C Function pointer cannot be formed from a local function captures context
// Do any additional setup after loading the view, typically from a nib.
}
I am following this link,, How to use NSSetUncaughtExceptionHandler to show exception message on UIView in Swift
Some unknown error is receiving. Kindly guide me, how to solve this?
回答1:
mailAcn()
means self.mailAcn()
, i.e. it is calling an instance method on self
. Thus, the function captures the variable self
from the surrounding scope, and it cannot be used as a C function.
You can try to make mailAcn
a top-level function instead.
来源:https://stackoverflow.com/questions/39265162/xcode7-how-to-mail-crash-report-in-swift