However, I'm trying to send a message from swift to display in a hype document (web app converted to native app in Xcode using @Photics wrapping app - which is amazing! )
Has anyone managed to achieve this? My plan is once I have worked out how to do this, I am going to send data to and from a hype document to store in coreData on a iOS device. Therefore making apps that can save and reload information. I just have to work out the communication part first.
Communicating the other way is done via calling WKWebView's evaluateJavaScript method. Just give it a string to do whatever you'd want, like call a JS function that was already defined in the head and does some work. If you need more substantial data transfer, you can first use NSJSONSerialization to convert objects into a JSON string to send across in the call.
Thanks for your quick replies to this query. I've spent a few hours this morning trying to get this to work and I think its way above my ability. I just can't get my head around how messages are passed from Swift back into Hype. However, the other way round, I'm absolutely fine with. I just can't seam to work it out.
I've tried @MarkHunte method but I can't even seam to get that to work. When I run the app, it simply displays "Hello world" rather than the app interface. Any ideas what I'm doing wrong?
I won't give up but this is more difficult than I first imagine it would be!
Thanks @MarkHunte - works perfectly now! However I still can't get it working how I need it to work so might have to go back to the drawing board on how I'm going to implement a save and load feature in my future apps.
I'm trying to send a line of text to swift and back to store in CoreData to create a save and load feature within my app.
I am currently trying to update some apps that I have previously created. My apps help people with learning disabilities understand health appointments / procedures however I want to be able to let the user make choices which, after being save, will load on the next time the app loads up.
I've managed to use local.storage to save different lines of text within web apps. See an example of my work at www.chardie.co.uk. If you click on the settings button on the second scene, you'll be able to change the text within the easy read document to say whatever you need it to say.
I was hoping if I could get data to and from swift and hype, then I could use coreData instead of local.storage meaning that there is less chance of the data being deleted easy or timing out in a native app.
Any help I can get with this would be really appreciated.
Can I suggest you watch these. The are 4 short videos that take you through coreData.
Ignore the parts that talk about the table, you are not using one. Instead you will use your data from hype.
Here is a quick example ( very thrown together as proof of concept ) of using stuff from the video.
Personally though I would push the text that needs editing to the App and use the app to edit ( similar to what the video shows in the name edits ) rather than a textArea or whatever on the scene.
Although I expect bugs in it due to it just being a proof of concept, thats one is odd.
I am still on Xcode Version 12.4 (12D4e) and MacOs Catalina.
So that could be it.
I just re downloaded the one I posted and it works.
Did you edit anything ?
I am assuming it means the st1 value is returning nil ?
Note also I have been playing with a different approach which does away with the textAreas as editors and uses the App as the editor. ( as mentioned above )
Again proof of concept to get started. But not worth posting just yet also we kinda need to get the other one working first..
Just a quick update. I have tried to load the files in Xcode on my partners laptop to run the code and the same error happens. I'll try play around with this next week to see if I can get any success with it working on my set up but it does appear to be something related to running it on a newer version of Xcode.
Hi @MarkHunte. Sorry I haven’t got back to you today. I’ve been really busy but will look at this tomorrow. I did managed to hard code the string value very briefly and it worked so I’m wondering if it’s something to do with my set ups.