无法使用在线签名模式创建信封 [英] Cannot create an Envelope using online signing mode
问题描述
我正在尝试创建一个信封并使用在线模式对其进行签名.
I'm trying to create an Envelop and sign it using online mode.
首先,我登录了我的帐户
At first, I logged in to my account
@IBAction private func signDocument(_ sender: UIButton) {
guard let hostURL = URL(string: Environment.current.docuSignHost) else { return }
isLoading = true
DSMManager.login(withEmail: Environment.current.docuSignUserID,
password: Environment.current.docuSignPass,
integratorKey: Environment.current.docuSignIntegratorKey,
host: hostURL) { [weak self] info, error in
self?.isLoading = false
if let error = error {
self?.error = error
} else {
self?.showDocuSign(info: info)
}
}
}
// MARK: - Helpers
private func showDocuSign(info: DSMAccountInfo?) {
guard let info = info else { return }
envelopManager.perform(with: info, presentingController: self)
}
之后,我创建了我的测试信封:
After that, I created my test Envelop:
final class EnvelopeManager {
private let envelopesManager = DSMEnvelopesManager()
private let templateManager = DSMTemplatesManager()
// MARK: - Lifecycle
func perform(with config: DSMAccountInfo, presentingController: UIViewController) {
guard let documentURL = R.file.tgkCapitalPortfolioBAgreementPdf(),
let documentData = try? Data(contentsOf: documentURL) else { return }
let envelopDefinition = DSMEnvelopeDefinition()
envelopDefinition.envelopeName = "Some name"
envelopDefinition.emailSubject = "Please Sign Envelope on Document"
envelopDefinition.emailBlurb = "Hello, Please sign my Envelope"
let document = DSMDocument()
document.name = R.file.tgkCapitalPortfolioBAgreementPdf.name
document.documentId = "1"
document.documentBase64 = documentData.base64EncodedString()
envelopDefinition.documents = [document]
let signHere = DSMSignHere()
signHere.documentId = document.documentId
signHere.pageNumber = 1
signHere.recipientId = "1"
signHere.anchorXOffset = 100
signHere.anchorYOffset = 100
signHere.tabId = "1"
let tabs = DSMTabs()
tabs.signHereTabs = [signHere]
let signer = DSMSigner()
signer.canSignOffline = false
signer.email = config.email
signer.name = config.userName
signer.recipientId = "1"
signer.tabs = tabs
let signers: [DSMSigner] = [signer]
let recipients = DSMRecipients()
recipients.signers = signers
envelopDefinition.recipients = recipients
envelopDefinition.status = "sent"
envelopesManager.composeEnvelope(with: envelopDefinition, signingMode: .online) { [weak self] envelopID, error in
if let envelopID = envelopID {
print(envelopID)
self?.presentSigning(presenter: presentingController,
envelopeID: envelopID)
} else {
print(error.localizedDescription)
}
}
}
private func presentSigning(presenter: UIViewController, envelopeID: String) {
envelopesManager.presentSigning(withPresenting: presenter,
envelopeId: envelopeID,
animated: true) { (viewController, error) in
if let viewController = viewController {
print(viewController)
}
if let error = error {
print(error.localizedDescription)
}
}
}
}
但是这里
envelopesManager.composeEnvelope(with: envelopDefinition, signingMode: .online) { [weak self] envelopID, error in
if let envelopID = envelopID {
print(envelopID)
self?.presentSigning(presenter: presentingController,
envelopeID: envelopID)
} else {
print(error.localizedDescription)
}
}
我有一个错误:
目前不支持在线创建信封.请试试离线模式
Envelope creation online is not supported at this moment. Please try offline mode
当我切换到离线模式时,我无法使用该方法
When I switched to offline mode I can't use the method
envelopesManager.presentSigning(withPresenting:, enveloped: , animated:, completeion)
因为它仅适用于以在线模式创建的信封.在我的情况下,完成块不会执行.
Because it works only for envelops which were created in the online mode. And in my case completion block is not executed.
如何解决此问题?如何在在线模式下创建信封并签名?我做错了什么?我只想选择包含在项目包中的pdf文件,并在某个位置添加符号.
此处提供的示例项目与我的要求不符.因为使用服务器中的模板并通过 presentComposeEnvelopeController
方法创建信封以选择文档等.
The sample project which was provided here doesn't match my requirements. Because there is using a template from server and creating envelop via presentComposeEnvelopeController
method for choosing document and etc.
通过CocoaPods将XCode 12.4,iOS 13/14,DocuSign 2.4.1包含在项目中.
XCode 12.4, iOS 13/14, DocuSign 2.4.1 included in the project via CocoaPods.
我已经更新了我的 perform
方法:
I have updated my perform
method:
func perform(with config: DSMAccountInfo, presentingController: UIViewController) {
guard let documentURL = R.file.tgkCapitalPortfolioBAgreementPdf(),
let documentData = try? Data(contentsOf: documentURL) else { return }
let envelopDefinition = DSMEnvelopeDefinition()
envelopDefinition.envelopeName = "Some name"
envelopDefinition.emailSubject = "Please Sign Envelope on Document"
envelopDefinition.emailBlurb = "Hello, Please sign my Envelope"
let document = DSMDocument()
document.name = R.file.tgkCapitalPortfolioBAgreementPdf.name
document.documentId = "1"
document.documentBase64 = documentData.base64EncodedString()
envelopDefinition.documents = [document]
let signHere = DSMSignHere()
signHere.documentId = document.documentId
signHere.pageNumber = 1
signHere.recipientId = "1"
signHere.frame = .init(originX: 100,
originY: 100,
width: 100,
height: 100,
originYOffsetApplied: 50)
signHere.tabId = "1"
let tabs = DSMTabs()
tabs.signHereTabs = [signHere]
let signer = DSMSigner()
signer.email = config.email
signer.name = config.userName
signer.recipientId = "1"
signer.tabs = tabs
let signers: [DSMSigner] = [signer]
let recipients = DSMRecipients()
recipients.signers = signers
envelopDefinition.recipients = recipients
envelopDefinition.status = "created"
envelopesManager.composeEnvelope(with: envelopDefinition, signingMode: .offline) { [weak self] envelopID, error in
if let envelopID = envelopID {
print(envelopID)
self?.presentSigning(presenter: presentingController,
envelopeID: envelopID)
} else {
print(error.localizedDescription)
}
}
}
和 presentSigning
方法也是如此:
private func presentSigning(presenter: UIViewController, envelopeID: String) {
envelopesManager.resumeSigningEnvelope(withPresenting: presenter,
envelopeId: envelopeID) { (viewController, error) in
if let viewController = viewController {
print(viewController)
}
if let error = error {
print(error.localizedDescription)
}
}
}
但是现在我在 presentSigning
方法中遇到了错误:信封已准备好进行同步,无法恢复签名.
But now I have got the error in the presentSigning
method: Envelope is ready for sync and can not be resumed for signing.
并且没有显示带有我的pdf文档的任何屏幕.怎么解决呢?我如何预览此文档,然后再添加用户签名的功能?
And any screen with my pdf document was not shown. How to resolve it? How I can preview this document and after that add the ability for a user to sign it?
EnvelopManager
类的工作代码:
final class EnvelopeManager {
private let envelopesManager = DSMEnvelopesManager()
private let templateManager = DSMTemplatesManager()
// MARK: - Lifecycle
func sync() {
envelopesManager.syncEnvelopes()
}
func perform(with config: DSMAccountInfo, presentingController: UIViewController) {
guard let path = Bundle.main.path(forResource: R.file.tgkCapitalPortfolioBAgreementPdf.name, ofType: "pdf") else { return }
let envelopDefinition = DSMEnvelopeDefinition()
envelopDefinition.envelopeName = "Some name"
envelopDefinition.emailSubject = "Please Sign Envelope on Document"
envelopDefinition.emailBlurb = "Hello, Please sign my Envelope"
let builder = DSMDocumentBuilder()
builder.addDocumentId("1")
builder.addName(R.file.tgkCapitalPortfolioBAgreementPdf.name)
builder.addFilePath(Bundle.main.path(forResource: R.file.tgkCapitalPortfolioBAgreementPdf.name,
ofType: "pdf")!)
let document = builder.build()
envelopDefinition.documents = [document]
let signHere = DSMSignHere()
signHere.documentId = document.documentId
signHere.pageNumber = 1
signHere.recipientId = "1"
signHere.frame = .init(originX: 100,
originY: 100,
width: 100,
height: 100,
originYOffsetApplied: 50)
signHere.tabId = "1"
let tabs = DSMTabs()
tabs.signHereTabs = [signHere]
let signer = DSMSigner()
signer.email = config.email
signer.name = config.userName
signer.userId = config.userId
signer.clientUserId = config.userId
signer.routingOrder = 1
signer.recipientId = "1"
signer.tabs = tabs
let signers: [DSMSigner] = [signer]
let recipients = DSMRecipients()
recipients.signers = signers
envelopDefinition.recipients = recipients
envelopDefinition.status = "created"
envelopesManager.composeEnvelope(with: envelopDefinition, signingMode: .offline) { [weak self] envelopID, error in
if let envelopID = envelopID {
print(envelopID)
self?.presentSigning(presenter: presentingController,
envelopeID: envelopID)
} else {
print(error.localizedDescription)
}
}
}
private func presentSigning(presenter: UIViewController, envelopeID: String) {
envelopesManager.resumeSigningEnvelope(withPresenting: presenter,
envelopeId: envelopeID) { (viewController, error) in
if let viewController = viewController {
print(viewController)
}
if let error = error {
print(error.localizedDescription)
}
}
}
}
您将在文档签名后不要忘记在顶视图控制器上调用 sync
方法
After you will have signed the document do not forget to call the sync
method on the top view controller
推荐答案
但是现在我在presentSigning方法中遇到了错误:信封已准备好进行同步,无法恢复签名.
信封已准备好进行同步,无法恢复签名.
表示信封没有本地签名者等待签名的状态.出于某些原因,可能会发生这种情况.
But now I have got the error in the presentSigning method: Envelope is ready for sync and can not be resumed for signing.
Envelope is ready for sync and can not be resumed for signing.
denotes the state that envelope has no local signers awaiting signing. This could happen because of a few reasons.
看看指南,这会将远程签名者"添加到本地信封中.
Taking a look at the adding recipient section of guide, this adds a Remote Signer to local envelope.
// Create an envelope recipient with name and email and assign an id and type with routing order
DSMEnvelopeRecipient *recipient = [[[[[[DSMRecipientBuilder builderForType: DSMRecipientTypeSigner]
addRecipientId: @"1"]
addSignerName: @"Jane Wood"]
addSignerEmail: @"JaneWood@docusign.com"]
addRoutingOrder: 1]
build];
未添加任何本地签名者来捕获签名.如果您需要添加本地签名者,则它们可能代表以下情况:
- 经过
- SDK身份验证的帐户可以用作签名者(
DSMRecipientTypeSigner
).在示例中:@"JaneWood@docusign.com"
是使用routingOrder
(或SigningOrder)为1
的SDK登录的. - SDK身份验证帐户可以用作亲自签名者(
DSMRecipientTypeInPersonSigner
)的主机.以下示例将为主机添加@"JaneWood@docusign.com"
的亲自签名人: - SDK authenticated account could be used as a signer (
DSMRecipientTypeSigner
). In the example:@"JaneWood@docusign.com"
is logged in with SDK withroutingOrder
(or SigningOrder) of1
. - SDK authenticated account could be used as a host to an in-person-signer (
DSMRecipientTypeInPersonSigner
). The following example would add an in-person-signer for@"JaneWood@docusign.com"
as host:
No local signers have been added to capture signatures. If you need to add a local signer they could represent following cases:
// Create an envelope recipient with name and email and assign an id and type with routing order
DSMEnvelopeRecipient *recipient = [[[[[[[DSMRecipientBuilder builderForType: DSMRecipientTypeInPersonSigner]
addRecipientId: @"1"]
addHostName: @"Jane Wood"]
addHostEmail: @"JaneWood@docusign.com"]
addSignerName: @"IPS - John Local Doe"]
addRoutingOrder: 1]
build];
- 只有远程签名者(非本地SDK帐户)已添加到信封:在此类信封上调用
syncEnvelopes
会发送文档并通过电子邮件发送给远程签名者以完成签名. - Only remote signers (non-local SDK account) have been added to envelope: Invoking
syncEnvelopes
on such envelopes will send documents and email the remote-signers to complete signing.
注意:所有本地签名者都已经完成签名:捕获所有本地签名后,您将遇到这种情况,并使用 syncEnvelopes
将信封发送到DocuSign服务器.
Note: All of the local signers have already completed signing: You'd reach this case once all local signatures have been captured, and using syncEnvelopes
would send envelope to DocuSign servers.
这篇关于无法使用在线签名模式创建信封的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!