How do I make a button in Swift to execute a line of HTML code? - swift

I am working on a small desktop app that will open websites on the click of a button. It's sort of a bookmark launcher in app form. I need to be able to connect a button in Swift to a single line of HTML code and have the button execute the code.
This is not an iOS app, it is macOS only. I am not looking to launch a UIWebView, I just need a single line of HTML executed.
Can anyone help? Thanks in advance.

I don't understand what you mean by "execute html code"
if you have a link and want to open it you can do:
NSWorkspace.shared.open(url:"your url")
https://developer.apple.com/documentation/appkit/nsworkspace

Related

Xcode Swift 5 MacOs app empty window when archived but works when running it from Xcode

I am building an app for Mac which logs into a website based on login and password collected from textfield and secure text field, then app opens an url which is created in my app based on date range selection with use of two date picker cell calendars. Next app displays html data in webWiev (using WKWebView), converts html to string using extension NSAttributedString and then saves retrieved data as txt file. Everything works as expected as long as app is run from Xcode "play" button. Problem is if I archive this app and launch it, it will bring up an empty window without any button, calendar or textfield. There are no errors, no crash logs on organizer, nothing.
I decided to perform a little test. I build another view controller with only one button which upon clicking will show my app main view controller. After archiving this modified app and running it outside of Xcode a window shows view controller with one button which is correct. But after clicking it nothing happens. App works great if running "inside" Xcode, a pushbutton shows main ViewController correctly. Do You have any clue what can be wrong? thank You!
Edit 1. So I found a discussion on apple which mention this problem. It is associated with IB WKWebView and problem is already known since some time. Now I have to get around the problem. Apple forum link: https://forums.developer.apple.com/thread/116047
Did you embed WebKit.framework to your app?
After comment that I wrote, I founded a solution and solved with this method.
Please check it out.

how to open the app store when clicking button

enter image description hereI want to open the app store when I click a certain button but, I have looked everywhere, and the code I have tried takes me to a safari link or doesn't do anything at all. can anyone help me? what i want it to achieve is that i hit the button and it opens up the app store with my specified app
UPDATE: i tried the method below and it opened oped up safari saying it could open the page
Zenprogrammer79 if your using the iOS simulator the link won't work because there is no App Store on the simulator but it should work on a real iOS device
zenProgrammer79 if you have a link to another app in the App Store, you can put this code in the section of where your button gets pressed (the IBAction) (objective-c)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"link to the application link looks like https://itunes.apple.com/au/app/sugar-calculator/id1000071935?mt=8"]];
if you are using swift i believe this will work
UIApplication.sharedApplication().openURL(NSURL(string: "https://itunes.apple.com/au/app/sugar-calculator/id1000071935?mt=8")!)
if this doesn't work then your link to the app is probably wrong.

How to have image target new window or _blank using FPDF?

In my app the PDF gets opened in the web page and in the below example, when the users clicks on Logo.png it's getting redirected to FPDF site in the same page, but i want to open the link in the new window, instead of opening in the same window, so the users has the PDF opened.
$pdf->Image('logo.png',10,10,30,0,'','http://www.fpdf.org');
Yes I have tried some workarounds for this but its seem to not possible currently. But I have achieved this using ViewerJS.
Just display pdf using viewerjs(pdf js). Just put this line $('a').attr('target', '_blank'); after div.setAttribute('data-loaded', true); inside viewer.js file.
And you will find target blank. Hope this helps!
Sorry, I am pretty sure that this is not possible currently.

Open Mail.app on IPhone from webpage that's INSIDE an app

our app loads profile pages from our website INSIDE the app. They have been optimized for iPhone css, but they are still an html page. Our mailto link isnt working as expected.
When clicked, nothing happens. However, when clicked and held (tap and hold), the menu slides up with "new message", "create new contact", "copy", etc.
How should this be formatted to get the Mail.app to automatically launch?
<a class="action_bubble" target="_blank" rel="external" href="mailto:bob#bob.com">Send Email</a>
The "call" link works as expected.
<a class="action_bubble" href="tel:1234567890">Call</a>
So, not sure what to do with this...
Here is a project on GitHub that addresses your issue. Basically, when you use a UIWebView controller, you need to decide how to manage the links using the delegate handler for UIWebView. In Interface Builder you can have it automatically recognize phone numbers which is probably why your phone numbers work and it will recognize http links as default behavior. However, mailto and some of the other special href options will need to be handled manually.
make sure "Detection" property is set for your UIWebView like "Phone","Address". you can set it from your IB.
or from code
self.webView.dataDetectorTypes = UIDataDetectorTypeAll;
Could it be, that you have just tried within the simulator? The simulator does not have a mail app, so it couldn't be opened. Try on a device. I think your code actually works.
I've just tested on a device: your code works.
A little late to the party but I've found out the following:
iOS has some weird ways to deal with web content
DON'T encapsulate your email address within an A tag, just put it there as plain text
Make sure that in your storyboard (if using one) the webView has the Addresses property checked and you're done ... same goes for phone numbers

Closing an opened window on mobile safari with javascript?

In app mode, if I open a new window using javascript, the newly-opened window cannot close itself (on an on-click event) using the standard window.close() or self.close(). Does anyone know if there's an alternate method?
What I find most beguiling about this is that it goes against Apple's very own design guidelines: essentially a site has the ability to open a new window but the user cannot get out of it without closing the webapp using the Home button.
Any ideas? Thanks!
JavaScript:window.self.close() is how to do that.
you can try this js code snippet.
var win = window.open('','_self');
win.close();