UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

HyperLinks

Forums > Swift

In my app I have the following function:

    static func createMessageBodyForImportingJSON(greeting: String, body: String) -> String {
        let htmlHdrTop = "<!DOCTYPE html><html><body>"
        let htmlHdrBot = "</body></html>"
        let openP = "<p>"
        let closeP = "</p>"
        let salutation = "<br>Thank you,"

        let body = body

        let haveAppInstructions = String(localized: "** IMPORTANT - THE EASY WAY ** Before you import this file make sure you have HymnTracker installed on your device. If you do not have the app installed, go to the AppStore and download the app. Once installed, you can then tap the file and choose HymnTracker to open it.<br><br>** THE LONG WAY ** If you want, you can take the long way around by following the instructions below for saving the file to the Files App and then selecting the file and importing it.", table: "EmailAndPDF+Strings", comment: "Instructions for getting the Hymn Tracker App")

        let saveFileInstructions = String(localized: "Instructions for saving attached file.", table: "EmailAndPDF+Strings", comment: "List of instruction on how to save the backup copy of the library.") + "<br>" + "&nbsp&nbsp&nbsp&nbsp&nbsp" +
            String(localized: "1. Long press on the attached file", table: "EmailAndPDF+Strings", comment: "Step 1 on saving the library.") + "<br>" + "&nbsp&nbsp&nbsp&nbsp&nbsp" +
            String(localized: "2. Tap 'Save to Files'", table: "EmailAndPDF+Strings", comment: "Step 2 on saving the library.") + "<br>" + "&nbsp&nbsp&nbsp&nbsp&nbsp" +
            String(localized: "3. Choose a folder in iCloud Drive", table: "EmailAndPDF+Strings", comment: "Step 3 on saving the library.") + "<br>" + "&nbsp&nbsp&nbsp&nbsp&nbsp" +
            String(localized: "4. Tap 'Save' in the upper right corner", table: "EmailAndPDF+Strings", comment: "Step 4 on saving the library.") + "<br><br>"

        let importFileInstructions = String(localized: "Instructions for importing attached file once it's saved in the Files app.", table: "EmailAndPDF+Strings", comment: "List of instructions on how to import a library.") + "<br>" + "&nbsp&nbsp&nbsp&nbsp&nbsp" +
            String(localized: "1. Tap Programs Tab", table: "EmailAndPDF+Strings", comment: "Step 1 on importing the selected library.") + "<br>" + "&nbsp&nbsp&nbsp&nbsp&nbsp" +
            String(localized: "2. Tap menu button in the upper right corner of the screen.", table: "EmailAndPDF+Strings", comment: "Step 2 on importing the selected library.") + "<br>" + "&nbsp&nbsp&nbsp&nbsp&nbsp" +
            String(localized: "3. Tap 'Import Programs From Files' option in the drop down menu.", table: "EmailAndPDF+Strings", comment: "Step 3 on importing the selected library.") + "<br>" + "&nbsp&nbsp&nbsp&nbsp&nbsp" +
            String(localized: "4. From the file importer screen find where you saved the file 'HymnTracker-Library.htData' and select it.", table: "EmailAndPDF+Strings", comment: "Step 3 on importing the selected library.") + "<br>" + "&nbsp&nbsp&nbsp&nbsp&nbsp" +
            String(localized: "5. Importing will then begin and close the screen.", table: "EmailAndPDF+Strings", comment: "Step 4 on importing the selected library.")

        let mainBody = openP + greeting + "<br><br>" + haveAppInstructions + "<br><br>" + body + "<br><br>" + saveFileInstructions + importFileInstructions + "<br><br>" + closeP

        return htmlHdrTop + mainBody + openP + salutation + closeP + htmlHdrBot
    }

This returns an email message body.

I would like to be able to add a hyperlink that would say "Download The App" when you tap that in the email it would take you to the app store. I have the URL, but if I create a NSMutuableAttributedString then it won't let me concatenate that with strings. So, I don't quite not how to get a hyperlink in the email body.

Any help would be appreciated. Taz

3      

I would like to add the hyperlink into the function I showed above. Just not quite sure how to do that, or if its even possible?

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.