> For the complete documentation index, see [llms.txt](https://docs.sharinpix.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sharinpix.com/documentation/integrations/other-apps/sharinpix-webview-on-a-native-ios-mobile-application.md).

# SharinPix WebView on a Native iOS Mobile Application

A WebView (or WKWebView on iOS) is a component inside a Swift application which allows the display of a web app inside a mobile application. By running the SharinPix web app inside a WebView, your native Swift application will contain the SharinPix experience usually available on Salesforce and the web. It can be seen as the equivalent of an iframe tag in HTML.

{% hint style="info" %}

* The folks at AppCoda have a [simple tutorial](https://www.appcoda.com/swiftui-wkwebview/) on how to include a basic WebView in your application. You can follow it and try embedding SharinPix in your own app.
* You have to use the link **<https://app.sharinpix.com/?token=XXXXX>** in your created WebView with a generated token.
  {% endhint %}

Below is an example how to generate token:

```apex
    token = sharinpix.Client.getInstance().token(
                    new Map<String, Object> {
                        'Id' => wOrder.Id,
                        'exp' => 0,
                        'path' => '/pagelayout/' + wOrder.Id,
                        'abilities' => new Map<String, Object> {
                            wOrder.Id => new Map<String, Object> {
                                'Access' => new Map<String, Boolean> {
                                    'see' => true,
                                    'image_list' => true,
                                    'image_upload' => true,
                                    'image_delete' => true
                                }
                            },
                            'Display' => new Map<String, Object> {
                                'tags'=> true
                            }
                        }
                    }
                );
                if (Trigger.isInsert) {
                    updatedWOrders.add(new WorkOrder(
                        Id = wOrder.Id,
                        SharinPix_Token__c = token
                    ));
                } else {
                    wOrder.SharinPix_Token__c = token;
                }
```

## Example of a WebView with the link

```swift
    import SwiftUI
    import WebKit
     
    struct WebView: UIViewRepresentable {
     
        var url: URL = URL(string: "https://app.sharinpix.com/?token=XXXXX")!;
        var webViewController: WebViewController = WebViewController()
     
        func makeUIView(context: Context) -> WKWebView {
            return WKWebView()
        }
     
        func updateUIView(_ webView: WKWebView, context: Context) {
            let contentController = webView.configuration.userContentController
            contentController.add(webViewController, name: "sharinpixOnEvent")
            let request = URLRequest(url: url)
            webView.load(request)
        }
    }
```

## ContentController

{% hint style="info" %}

* You have to add a **contentController** to listen to all events/post messages sent by the SharinPix application.
* The **WebViewController** should be added.
  {% endhint %}

### Example of a ContentController

```apex
    let contentController = webView.configuration.userContentController;
    contentController.add(webViewController, name: "sharinpixOnEvent");
```

## Example of a WebViewController

```apex
    class WebViewController: NSObject, WKScriptMessageHandler, WKNavigationDelegate {
        func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
            let dict = message.body as? NSDictionary
            print(dict ?? "SharinPix null")
            guard let string = dict?["name"] as? String else { return }
            print("SharinPix: " + string)
            showAlert(message: string)
        }
        .
        .
        .
    }
```

{% hint style="success" %}
The WebViewController class will allow the Swift application to get every event that is sent by the SharinPix application
{% endhint %}

## iOS Permissions

### Accessing the native camera

To be able to open the native camera on your Swift application, you should include the permission "**Privacy - Camera Usage Description (NSCameraUsageDescription)**" in Info in your XCode project.

If the permission is not allowed hence the user will not get the native camera.

* Go to your XCode Project
* Click on the project
* Click on Info
* Add a new property by clicking on the arrow **up down** on the permission "**Privacy - Camera Usage Description**" (See screenshot below).

<figure><img src="/files/4lAddX6G9wyusxrUAXN3" alt=""><figcaption></figcaption></figure>

Below is the screenshot where the Permission **Privacy - Camera Usage Description** is asked.

<figure><img src="/files/2IbWautbtrDFpkibG32c" alt=""><figcaption></figcaption></figure>

The screenshot below shows images that are uploaded on the SharinPix application.

<figure><img src="/files/Km6N2wReEjN8csGbjFie" alt=""><figcaption></figcaption></figure>

The screenshot shows a native alert being shown on the mobile application with the event that has been triggered when deleting an image on the SharinPix application.

<figure><img src="/files/k4gY8za468HzVTdjoUox" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sharinpix.com/documentation/integrations/other-apps/sharinpix-webview-on-a-native-ios-mobile-application.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
