How to get attribute's value from a text box?

Thanks a lot! It works perfectly! Now the sliders work in Hype reflect .

But, There are some other problems I encounter.
my questions are :

  1. how can I reset the slider’s value back to Zero? (because now every time when the player visit the slider page again. The sliders do not refresh themselves. )

I tried to put the following script inside the head script file but it did not work.
Thanks a million and please advise.

<script type="text/javascript">

window.onpageshow = function(event) {
if (event.persisted) {
window.location.reload();

}

};

  1. by the way, I have found the sliders disappeared when I try to preview in xcode’s iphone simulator. The sliders appears perfectly in the web browser . it looks incomplete with the xcode’s iphone simulator. (i already downloaded the latest xcode version today). Please suggest! Thanks

The attached image shows the sliders look incomplete in the iPhone simulator.

1,
Reset the slider with

   $( "#item1" ).slider('value',0)
   $( "#item2" ).slider('value',0)

i.e

$( "#item1" ).slider();
    $( "#item2" ).slider();
    
   $( "#item1" ).slider('value',0)
   $( "#item2" ).slider('value',0)
    
    $( ".selector" ).on( "slide", function( event, ui ) {
  
 hypeDocument.getElementById(event.target.id + 'result').innerHTML = ui.value
   
    
    
    } );
1 Like

Great thanks for the reset code! They work perfectly!
by the way, I have found the sliders’ tips disappeared when I tried to preview them in the xcode’s iphone simulator. The sliders appears perfectly in the web browser but it looks incomplete with the xcode’s iphone simulator. Please suggest! Thanks
[/quote]

Not sure what that is.. ??

I know in a normal browser I had the whole of the slider widget disappear on me at one point but not been able to repeat that.


In Xcode I normally plug my iPhone or iPad in and use that. For me this gives me a closer real world experience of how code will run. Thats not saying the simulator does not work. It is a Marvel but I just prefer to use something with the real Hardware if I can.

I use the simulator only for layout change testing in an App for devices I do not have. But that just me.

Hi! I am now submitting this iOS to Apple for verification but the Big problem is I suddenly find the mail button does not work when I preview it in Xcode and created a build and have it displayed in my iPAD. (the mail button so far only work if I use the internet browser in my computer and with my iPad’s web browser). Please help, since this is my App’s key feature. (final nail of the coffin before submitting to Apple )

In short, how could I get the mail button work when creating an iOS app? (building it with xCode. )

Try this out?

1 Like

Hi , thanks for your reply.
my original script “mail()” in Tumult in Hype contains
win = window.location.href = “mailto:”+ mailto + “?subject=speakNcomm Report&body=”

Could yo please give me a hint of how I could amend or update my current mail() script? (in order to get my mail button work in xCode for iOS app )

Any help will be very much appreciated! Please help! Thanks!

Did you try the suggestion above?

Yes, I have tried that.
I added the following code in the mail() , then i preview it with Xcode on my iPad screen. The mail button does not work.

Please suggest.
Thanks for your attention!

What ? wait!..

The Objective - C code should be in your Xcode code. And probably in there it is using swift…???

Not in a Hype function!. :open_mouth:

Thanks for your attention and following up.
unfortunately, swift is a bit out of my knowledge as my reason to purchase and use Tumult Hype is I wanted to use it to help me to create my iOS app without too much coding. It is because I am from the art background. Please suggest how I could possibly get that button working again in iOS environment? (previously the button was working but only in the web browser. )
Please help. Any help will be appreciated!

This is beyound the normal scope of this forum…

But if you are able zip a copy of you xcode project you are using and PM it to me I will see if I can add the code to a copy to do the open in mail. ( no promises )

If so PM it without your hype files. I say this so you are not giving away anything related to your actual app.

1 Like

Thanks so much! That is so kind of you!
may I know which is the best way to PM (private message ) you the Zipped Xcode project file to take a look? Your Facebook page message or email or send space …? Same name? MarkHunte?
Anyway, really thank you for your help!

Best regards

if it is under 3MB then PM the file directly, If it is over then you can use Dropbox and PM me the download link

Thanks Mark, thanks for the explanation.
May I assume PM means facebook’s private message?

Thanks a lot for your help! I will do it soon!
Best regards

Click my name in one of these posts and then hit the message button. PM is private Message on this site.

@brucelay

I am posting back here as I want others to be able to use this if they want to.

Looking at the Xcode it is very basic.

I have change it a bit.

The main changes are how the Hype page operates with the App.

I have set it up so when the Hype mail button is clicked it sends the App the details.

The App then presents the in App mail composer.
I did it this way because although I got the original mailto open Url to work, it takes you out of your app and into to mail but once the mail is completed it does not take you back to your app.

this way you never leave your app.

The code in the View controller now looks like this.

//
//  ViewController.swift
//  speakNcomm
//
//  Created by Mark  Hunte 2018.
//  Copyright © 2018 Mark  Hunte All rights reserved.
//

import UIKit
import WebKit
import MessageUI

class ViewController: UIViewController, WKNavigationDelegate  ,WKScriptMessageHandler, MFMailComposeViewControllerDelegate{
    
    //-- declare a WKWebView
    var webView: WKWebView!
    
     //-- declare a mail vars
    var addr :String = ""
    var subj :String = ""
    var body :String = ""
    
    
    //-- webkit message  handler delegate //-- handles messages from hype page
    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        
        //-- messages from Hype page
        if message.name == "address"{
       
            addr   =  message.body as! String
         }
        
        if message.name == "subject"{
 
            subj   =  message.body as! String
         }
        
        if message.name == "body"{
            
            body   =  message.body as! String
            
        }
        
        if message.name == "send"{
            
            //-- compose Mail in App view
            if MFMailComposeViewController.canSendMail() {
                let mail = MFMailComposeViewController()
                mail.mailComposeDelegate = self
                mail.setToRecipients([addr])
                mail.setSubject(subj )
                mail.setMessageBody(body , isHTML: true)
                
                present(mail, animated: true, completion: nil)
            } else {
                
                
                // show failure alert
            }
            
        }
     
        
    }
    

    //-- mail didFinishWith delegate
    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
        controller.dismiss(animated: true, completion: nil)
    }
    

    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        //-- configure the WKWebView
        
        //-- init config and controller
        let wconfiguration = WKWebViewConfiguration()
        let wcontroller = WKUserContentController()
        
        //-- We must add the webkit scripts we expect to get from the Hype Page to the controller
        wcontroller.add(self, name: "address")
        wcontroller.add(self, name: "subject")
        wcontroller.add(self, name: "body")
        wcontroller.add(self, name: "send")
        
        //-- attach controller, config to WKWebview 
        wconfiguration.userContentController = wcontroller;
        webView =  WKWebView(frame: .zero, configuration: wconfiguration)
        
        
        
        let htmlPath = Bundle.main.path(forResource: "speakNcomm_iPad", ofType: "html")
        
        let folderPath = Bundle.main.bundlePath
        
        let baseUrl = URL(fileURLWithPath: folderPath, isDirectory: true)
        
        do {
            
            let htmlString = try NSString(contentsOfFile: htmlPath!, encoding: String.Encoding.utf8.rawValue)
            
            webView.loadHTMLString(htmlString as String, baseURL: baseUrl)
            
        } catch {
            
            // catch error
            
        }
        
        webView.navigationDelegate = self
        
        view = webView
        
    }
    
    
    
    
}

The Hype Javascript also needs to change.

I did not have the original function but this should make sense in the parts you need to replace in your function.

    var results =itemValues.toString().replace(",","<br>")
 		
 	 
 	window.webkit.messageHandlers.address.postMessage(mailto_);  // post the to address
 	window.webkit.messageHandlers.subject.postMessage("Report");  // post the subject
 	window.webkit.messageHandlers.body.postMessage(results);  // post the result
 	window.webkit.messageHandlers.send.postMessage(true);  // post the the send //-- which triggers the compose window in the App

I tested this on my iPhone and all works.
Note : you must use a correctly structured email address when testing or that field will be blank in the composer.
The mail controller validates it…

(The code is as is. It is only as sound as my research in to helping you getting something going goes. In other words it works but i have not put a lot of effort to check or track any bugs that may spring up.
You will need to put you error checks, bounds and catches in yourself if they are needed… :wink: )

3 Likes

Thanks a lot! I am trying to apply those changes!

Hi Thanks a lot Mark,
Now the mail button works perfectly! Thanks so much for your advice and the information!
But the interesting thing is I just have one little or minor concern which is I find the slider graphic,which I created with jQuery previously, partially looks incomplete when I preview it with my iPad. (although it looks perfect in my web browser)
do you have any clue?

27 AM

Anyway, great thanks for your help! Best regards

You have a couple of options I think.

which I think it could be related to

  • Recreate the sliders in Hype using the built in drag controls.

I admit dragging in hype for sliders is not always a good user experience and can be hard to get right.

  • Use the Skip button or 2 minute end to trigger another webkit… call to the iOS app.

The call will be to instruct the App to load another ViewController.

In the app the new viewController will have iOS sliders and labels to hold the value and a send button to trigger the Mail send…

Of these the last one IMHO is the easiest way to go. I did a quick test and it works well and did not take that long to set up.

This is something you will need to figure out yourself how to do…

But a small help.

  • I added a new viewController in IB , I then added a new Coco Touch Class file to the project ( UIVieweController )

  • Set the Class of the viewController in IB to the new files class name.

  • Added and configured sliders to the viewController in IB.

  • Linked them to Value Change actions in the new UIVieweController file

  • Added labels for each slider in the viewController in IB.

Linked them to the new UIVieweController file as outlets

In each Action for a slider I used something like;

    @IBAction func vGrammer(_ sender: UISlider) {
      vGrammerValue.text =  "\( Int(sender.value) )"
    }

You can then add a button in the viewController in IB to compose the mail. ( you already have this code )


  • I add an action on the Skip button to run a new function in Hype.

window.webkit.messageHandlers.showMailer.postMessage(true);

In the original ViewController, I add new postMessage to the WKUserContentController. and a new handler condition in the the userContentController. function.
The new condition calls presents the new viewController


Thats all I have now as this is getting way off topic…

2 Likes