> You are reading the Docusign Developer Documentation. For clean Markdown of any page, append .md to the page URL.
>
> Documentation indexes by section:
> - APIs and SDKs: https://docusign.docs.buildwithfern.com/docs/llms.txt
> - Platform 101: https://docusign.docs.buildwithfern.com/platform/llms.txt
> - Extension Apps: https://docusign.docs.buildwithfern.com/extension-apps/llms.txt
> - Docusign CLI: https://docusign.docs.buildwithfern.com/docusign-cli/llms.txt
>
> Authentication (OAuth, JWT Grant, M2M): https://docusign.docs.buildwithfern.com/platform/auth
> Webhooks and Connect: https://docusign.docs.buildwithfern.com/platform/webhooks
>
> OpenAPI specifications: https://docusign.docs.buildwithfern.com/openapi.json
> MCP server: https://docusign.docs.buildwithfern.com/_mcp/server

# How to create an envelope for offline signing (from a template)

> Learn how to create an envelope with the iOS SDK from a template for offline signing.

This topic demonstrates how to create an [envelope](/docs/esign-rest-api/esign101/concepts/envelopes) from a [template](/docs/esign-rest-api/esign101/concepts/templates) for offline signing.

## Required data

Running the code in this how-to requires this data:

| Data element    | Description                                                                                                                                                                                                                                                                                              |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \{ROLE_NAME}    | A string value for the role name associated with the template recipient. This value can be defined upon template creation. This value must exactly match (case-sensitive) the value shown in the Role field assigned to the recipient in the template.                                                   |
| \{SIGNER_EMAIL} | A string value for the email address where the signer will receive a notification of the signing request.                                                                                                                                                                                                |
| \{SIGNER_NAME}  | A string value for the full name of the signer.                                                                                                                                                                                                                                                          |
| \{TAB_LABEL}    | A string value identifying a text-based tab to override in the template. This value can be defined upon template creation using the Data Label field. This value must exactly match (case-sensitive) the value shown in the tab’s Data Label field in the template.                                      |
| \{TAB_VALUE}    | A string value to assign to the text tab in the template.                                                                                                                                                                                                                                                |
| \{TEMPLATE_ID}  | A [GUID](http://guid.one/) value that identifies a Docusign [template](/docs/esign-rest-api/esign101/concepts/templates) that is used to create a Docusign [envelope](/docs/esign-rest-api/esign101/concepts/envelopes). This value is automatically generated by Docusign when the template is created. |

## Step 1. Log in to Docusign

To make the API call shown in this how-to, you must be logged in to Docusign.

See [How to log in to Docusign from your app](/docs/mobile-sdks/ios-sdk/how-to/log-in) for details.

## Step 2. Cache template

Use the method shown to cache the template you wish to use to construct your envelope.

**`Objective-C`**

```text title="Objective-C"
[self.templatesManager cacheTemplateWithId: @"{TEMPLATE_ID}"
    completion:^(NSError * _Nullable error) {
    if (error) {
        NSLog(@"%@", error.localizedDescription);
        return;
    }
}];
```

**`Swift`**

```swift title="Swift"
DSMTemplatesManager().cacheTemplate(withId: "{TEMPLATE_ID}") { (error) in
    guard error == nil else {
        print(error)
        return
    }
})
```

## Step 3. Create envelope defaults

When creating an envelope definition with a template, the documents, tabs, and most of the other envelope data will be automatically populated by your chosen template. To create an envelope from a template, you must:

* Specify the ID of the template.
* Specify the names, emails, and role names for each role in the template.
* Provide a custom string to be assigned as the value of any tab objects identified by \{TAB_LABEL} that you wish to override.

> **Note:** Only text-based tabs are supported for tab defaults.

**`Objective-C`**

```text title="Objective-C"
DSMEnvelopeDefaults *envelopeDefaults = [[DSMEnvelopeDefaults alloc] init];

// Add recipients to Template
DSMRecipientDefault *recipient1 = [[DSMRecipientDefault alloc] init];
recipient1.recipientRoleName = @"{ROLE_NAME}";
recipient1.recipientSelectorType = DSMEnvelopeDefaultsUniqueRecipientSelectorTypeRecipientRoleName;
recipient1.recipientName = @"{SIGNER_NAME}";
recipient1.recipientEmail = @"{SIGNER_EMAIL}";

envelopeDefaults.recipientDefaults = @[recipient1];

// Add Tabs
NSDictionary * tabData = @{@"{TAB_LABEL}":@"{TAB_VALUE}"};

envelopeDefaults.tabValueDefaults = tabData;
```

**`Swift`**

```swift title="Swift"
let envelopeDefaults = DSMEnvelopeDefaults()

// Add recipients to Template
let recipient1 = DSMRecipientDefault()
recipient1.recipientRoleName = "{ROLE_NAME}"
recipient1.recipientSelectorType = .recipientRoleName
recipient1.recipientName = "{SIGNER_NAME}"
recipient1.recipientEmail = "{SIGNER_EMAIL}"

envDefaults.recipientDefaults = [recipient1]

// Add Tabs
let tabs = ["{TAB_LABEL}":"{TAB_VALUE}"]
envelopeDefaults.tabValueDefaults = tabs
```

## Step 4. Create the envelope

Next, use the envelope defaults you created in the previous step to create an envelope.

**`Objective-C`**

```text title="Objective-C"
[[[DSMTemplatesManager alloc] init] presentSendTemplateControllerWithTemplateWithId: @"{TEMPLATE_ID}"
    envelopeDefaults:envelopeDefaults
    pdfToInsert:nil
    insertAtPosition:0
    signingMode:DSMSigningModeOffline
    presentingController:self
    animated:YES
    completion:^(UIViewController * _Nullable viewController, NSError * _Nullable error) {
    if (error) {
        NSLog(@"%@", error.localizedDescription);
        return;
    }
}];
```

**`Swift`**

```swift title="Swift"
DSMTemplatesManager().presentSendTemplateControllerWithTemplate(withId: "{TEMPLATE_ID}",
    envelopeDefaults: envelopeDefaults,
    pdfToInsert: nil,
    insertAtPosition: .end,
    signingMode: .offline,
    presenting: self,
    animated: true,
    completion: { viewController, error  in
    guard error == nil else {
        print(error)
        return
    }
})
```

## Expected response

If the account used for authentication is set as the signer for the envelope, you will see the iOS SDK’s native offline signing screen, and be prompted to complete the offline signing process.

![IOS SDK native offline signing interface](/_fern-files/_img/959af1282553fd5bc6b22ca18d2d0008c5499fea7af52419d08f28fa08224ff8.webp)

Once signing has been completed, or if the envelope has a remote signer, the envelope will be cached directly for sync later. You will receive a [DSMEnvelopeCachedNotification](https://docusign.github.io/native-ios-sdk/documentation/docusignsdk/dsmenvelopecachednotification/) to keep track of the signing process.

## Next steps

* Learn [How to sync offline signed envelopes](/docs/mobile-sdks/ios-sdk/how-to/sync-offline).
* Learn [How to create an envelope for offline signing (PDF)](/docs/mobile-sdks/ios-sdk/how-to/offline-signing-pdf).
* See [Support Guide: How do I create a template?](https://support.docusign.com/s/articles/How-do-I-create-a-template)