I am using EPSignature CocoaPods for drawing my signs. App was working until I did some changes to code and updated to newest version of xCode. Last time lib update was: July, 2018. I found some newest version on github but norhing...
Here is what is happening/ was happened when I tried to draw sign and click done button. App freezes and crashes each time I click done button.
Function -> getSignatureBoundsInCanvas
open func getSignatureBoundsInCanvas() -> CGRect {
return bezierPath.bounds
}
Function -> onTouchButton
@objc func onTouchDoneButton() {
if let signature = signatureView.getSignatureAsImage() {
if switchSaveSignature.isOn {
let docPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
let filePath = (docPath! as NSString).appendingPathComponent("sig.data")
try? signatureView.saveSignature(to: URL(string: filePath)!)
}
signatureDelegate?.epSignature!(self, didSign: signature, boundingRect: signatureView.getSignatureBoundsInCanvas())
} else {
showAlert("You did not sign", andTitle: "Please draw your signature")
}
}
App delegate error shows this
Thread 1: "-[Control.SignatureViewController epSignature:didSign:boundingRect:]: unrecognized selector sent to instance 0x10a040c00"
And when I want to jump to function ePSignature here is a code
extension SignatureViewController: EPSignatureDelegate {
func epSignature(_: EPSignatureViewController, didSign path: UIBezierPath?) {
path?.origin = .zero
path?.scaleToFit(size: Const.signatureSize, insets: Const.signatureInsets)
model.signed?(path)
}
func epSignature(_: EPSignatureViewController, didCancel error: NSError) {
model.cancelled?(error)
}
}
Thanks a lot
CodePudding user response:
Thank you sir for the answer. I am really appreciate. The main problem is the next one:
This code snippet is not written by me, it's by the owner/ publisher of the framework.
signatureDelegate?.epSignature!(self, didSign: signature, boundingRect: signatureView.getSignatureBoundsInCanvas())
I tried to figure it out but couldn't do it propertly. At the top of the class there's a var for signatureDelegate
open weak var signatureDelegate: EPSignatureDelegate?
The first method of the code
func epSignature(_: EPSignatureViewController, didSign path: UIBezierPath?) {
...
}
is now changed by this one
func epSignature(_: EPSignatureViewController, didSign path: UIBezierPath?, boundingRect: CGRect) {
path?.origin = .zero
path?.scaleToFit(size: Const.signatureSize, insets: Const.signatureInsets)
model.signed?(path)
}
I know method in the class EPSignatureViewController takes three params,viewcontroller, UIImage and CGRect. But writing "didSign signatureImage" instead of "didSign path: UIBezierPath?" can not access the path of the image.
CodePudding user response:
In the last code snippet, you have declared the following method:
func epSignature(_: EPSignatureViewController, didSign path: UIBezierPath?) {
...
}
But if you check the original declaration of the EPSignatureDelegate protocol, you'll see that it takes three parameters: the viewcontroller, a UIImage and a CGRect – nothing like your method.
// MARK: - EPSignatureDelegate
@objc public protocol EPSignatureDelegate {
@objc optional func epSignature(_: EPSignatureViewController, didCancel error : NSError)
@objc optional func epSignature(_: EPSignatureViewController, didSign signatureImage : UIImage, boundingRect: CGRect)
}
In the second snippet, this very dubious line from the library tries to call the method declared by the protocol (note the three parameters passed), which really doesn't exist in your case.
signatureDelegate?.epSignature!(self, didSign: signature, boundingRect: signatureView.getSignatureBoundsInCanvas())
Just make sure you use the correct signature everywhere and the crash should go away.