Created
April 3, 2019 13:34
-
-
Save Fedenieto90/f1ad24e293361302a09b77c56e6ab435 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class TypeFormHelper: NSObject { | |
struct Constants { | |
static let typeFormUrl = "yourTypeformUrl" | |
static let formSubmissionHandler = "formSubmitted" | |
static let TypeForm = "TypeForm" | |
static let html = "html" | |
} | |
static func getTypeFormScript(urlString: String, messageHandlerName: String) -> String { | |
return """ | |
const embedElement = document.querySelector('iframe') // NOTE: `.target-dom-node` is the target DOM element from your website or web app | |
typeformEmbed.makeWidget( | |
embedElement, | |
'\(urlString)', // NOTE: Replace with your typeform URL | |
{ | |
hideHeaders: true, | |
hideFooter: true, | |
opacity: 75, | |
onSubmit: function () { | |
window.webkit.messageHandlers.\(messageHandlerName).postMessage("Form Submitted"); | |
} | |
} | |
) | |
""" | |
} | |
static func getTypeFormHtml() -> String? { | |
let htmlFile = Bundle.main.path(forResource: Constants.TypeForm, ofType: Constants.html) | |
let html = try? String(contentsOfFile: htmlFile!, encoding: String.Encoding.utf8) | |
return html | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment