請隨時與我們聯繫以獲得更具創意的解決方案,但是在iPad上獲取簽名的最簡單方法是將簽名圖像集合委託給DocuSign。這裏是一種獲取模板簽名的方法(您也可以使用文檔字節流來完成)。這取自GitHub的要點:https://gist.github.com/Ergin008/5645812。
用於簽名的視圖可以顯示在iOS應用程序的webview中。
//
// API Walkthrough 8 - Launch the signing (recipient) view of an envelope in an embedded session
//
// To run this sample:
// 1. Copy the below code into your iOS project
// 2. Enter your email, password, integrator key, name, templateId, and roleName and save
// 3. Run the code
//
- (void)embeddedSigning
{
// Enter your info:
NSString *email = @"<#email#>";
NSString *password = @"<#password#>";
NSString *integratorKey = @"<#integratorKey#>";
NSString *name = @"<#name#>";
// use same name as template role you saved through the Console UI
NSString *roleName = @"<#roleName#>";
// need to login to the console and copy a valid templateId into this string
NSString *templateId = @"<#templateId#>";
///////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (retrieves accountId and baseUrl)
///////////////////////////////////////////////////////////////////////////////////////
NSString *loginURL = @"https://demo.docusign.net/restapi/v2/login_information";
NSMutableURLRequest *loginRequest = [[NSMutableURLRequest alloc] init];
[loginRequest setHTTPMethod:@"GET"];
[loginRequest setURL:[NSURL URLWithString:loginURL]];
// set JSON formatted X-DocuSign-Authentication header (XML format also accepted)
NSDictionary *authenticationHeader = @{ @"Username": email, @"Password" : password, @"IntegratorKey" : integratorKey };
// jsonStringFromObject() function defined below...
[loginRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:@"X-DocuSign-Authentication"];
// also set the Content-Type header (other accepted type is application/xml)
[loginRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
//*** make an asynchronous web request
[NSURLConnection sendAsynchronousRequest:loginRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *loginResponse, NSData *loginData, NSError *loginError) {
if (loginError) { // succesful GET returns status 200
NSLog(@"Error sending request %@. Got Response %@ Error is: %@", loginRequest, loginResponse, loginError);
return;
}
// we use NSJSONSerialization to parse the JSON formatted response
NSError *jsonError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:loginData options:kNilOptions error:&jsonError];
NSArray *loginArray = responseDictionary[@"loginAccounts"];
// parse the accountId and baseUrl from the response and use in the next request
NSString *accountId = loginArray[0][@"accountId"];
NSString *baseUrl = loginArray[0][@"baseUrl"];
//--- display results
NSLog(@"\naccountId = %@\nbaseUrl = %@\n", accountId, baseUrl);
///////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create Envelope via Template and send the envelope
///////////////////////////////////////////////////////////////////////////////////////
// append "/envelopes" URI to your baseUrl and use as endpoint for signature request call
NSString *envelopesURL = [NSString stringWithFormat:@"%@/envelopes",baseUrl];
NSMutableURLRequest *signatureRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:envelopesURL]];
[signatureRequest setHTTPMethod:@"POST"];
[signatureRequest setURL:[NSURL URLWithString:envelopesURL]];
// construct a JSON formatted signature request body (multi-line for readability)
NSDictionary *signatureRequestData = @{@"accountId": accountId,
@"emailSubject" : @"Embedded Sending API call",
@"emailBlurb" : @"email body goes here",
@"templateId" : templateId,
@"templateRoles" : [NSArray arrayWithObjects: @{@"email":email, @"name": name, @"roleName": roleName, @"clientUserId": @"1001" }, nil ],
@"status" : @"sent"
};
// convert request body into an NSData object
NSData* data = [[self jsonStringFromObject:signatureRequestData] dataUsingEncoding:NSUTF8StringEncoding];
// attach body to the request
[signatureRequest setHTTPBody:data];
// authentication and content-type headers
[signatureRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:@"X-DocuSign-Authentication"];
[signatureRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
// Send the signature request...
[NSURLConnection sendAsynchronousRequest:signatureRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *envelopeResponse, NSData *envelopeData, NSError *envelopeError) {
NSError *jsonError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:envelopeData options:kNilOptions error:&jsonError];
NSLog(@"Signature request sent, envelope info is: \n%@\n", responseDictionary);
// parse envelopeId from resposne as it will be used in next request
NSString *envelopeId = responseDictionary[@"envelopeId"];
///////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - Get the Embedded Signing View (aka recipient view) of the envelope
///////////////////////////////////////////////////////////////////////////////////////
// append /envelopes/{envelopeId}/views/recipient to baseUrl and use in request
NSString *embeddedURL = [NSString stringWithFormat:@"%@/envelopes/%@/views/recipient", baseUrl, envelopeId];
NSMutableURLRequest *embeddedRequest = [[NSMutableURLRequest alloc] init];
[embeddedRequest setHTTPMethod:@"POST"];
[embeddedRequest setURL:[NSURL URLWithString:embeddedURL]];
// simply set the returnUrl in the request body (user is directed here after signing)
NSDictionary *embeddedRequestData = @{@"returnUrl": @"http://www.docusign.com/devcenter",
@"authenticationMethod" : @"none",
@"email" : email,
@"userName" : name,
@"clientUserId" : @"1001" // must match clientUserId set is step 2
};
// convert request body into an NSData object
NSData* data = [[self jsonStringFromObject:embeddedRequestData] dataUsingEncoding:NSUTF8StringEncoding];
// attach body to the request
[embeddedRequest setHTTPBody:data];
// set JSON formatted X-DocuSign-Authentication header (XML format also accepted)
NSDictionary *authenticationHeader = @{ @"Username": email, @"Password" : password, @"IntegratorKey" : integratorKey };
// jsonStringFromObject() function defined below...
[embeddedRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:@"X-DocuSign-Authentication"];
// also set the Content-Type header (other accepted type is application/xml)
[embeddedRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
//*** make an asynchronous web request
[NSURLConnection sendAsynchronousRequest:embeddedRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *embeddedResponse, NSData *embeddedData, NSError *embeddedError) {
if (embeddedError) { // succesful POST returns status 201
NSLog(@"Error sending request %@. Got Response %@ Error is: %@", embeddedRequest, embeddedResponse, embeddedError);
return;
}
// we use NSJSONSerialization to parse the JSON formatted response
NSError *jsonError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:embeddedData options:kNilOptions error:&jsonError];
NSString *embeddedURLToken = responseDictionary[@"url"];
//--- display results
NSLog(@"URL token created - please navigate to the following URL to start the embedded signing workflow:\n\n%@\n\n", embeddedURLToken);
}];
}];
}];
}
- (NSString *)jsonStringFromObject:(id)object {
NSString *string = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:object options:0 error:nil] encoding:NSUTF8StringEncoding];
return string;
}
問題 - 你試圖做什麼?您是否嘗試單獨進行簽名,然後將完成的信封上傳到DocuSign,或者您是否想將DocuSign圖像作爲選定的電子簽名從系統中提供給您? – mikebz
我正試圖在iPad上爲親筆簽名構建一個應用程序。我想建立我自己的用戶界面,用於簽名(基本上允許他畫他的標誌),然後將簽名圖像發送給Docusign以將其附加到信封上。 – user2608913
給我發郵件和你的郵件。我不知道這樣做是否是一個簡單的答案,堆棧溢出不適用於後退和第四次發現。 – mikebz