Force a WebView link to launch Safari?

To expand upon what Randy said, this is what I use in my application to make every http://, https://, and mailto:// URL open in the external Safari or Mail applications: -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; { NSURL *requestURL =[ [ request URL ] retain ]; if ( ( [ [ requestURL scheme ] isEqualToString: @”http” … Read more

How to call Objective-C from Javascript?

The standard workaround for UIWebView is to set a UIWebViewDelegate, and implement the method webView:shouldStartLoadWithRequest:navigationType:. In your JavaScript code, navigate to some fake URL that encodes the information you want to pass to your app, like, say: window.location = “fake://myApp/something_happened:param1:param2:param3”; In your delegate method, look for these fake URLs, extract the information you need, take … Read more

WKWebView and NSURLProtocol not working

Updated answer for iOS 11 and macOS 10.13 Since iOS 11 it is possible to declare an object that conforms to the WKURLSchemeHandler protocol and register it in the WKWebView configuration: -[WKWebViewConfiguration setURLSchemeHandler:forURLScheme:]. Old answer WKWebView makes requests and renders content out-of-process, meaning your app does not hear the requests they make. If you are … Read more

Go vs. return button in iOS keyboard for HTML input forms

Update 2020/2021 As Cameron Cobb pointed out, Safari Mobile supports the new HTML attribute enterkeyhint since version 13.7 ~ Sept. 2020 (https://caniuse.com/mdn-html_global_attributes_enterkeyhint). The following values are possible (https://mixable.blog/ux-improvements-enterkeyhint-to-define-action-label-for-the-keyboard-of-mobile-devices/): <input enterkeyhint=”enter”> <input enterkeyhint=”done”> <input enterkeyhint=”go”> <input enterkeyhint=”next”> <input enterkeyhint=”previous”> <input enterkeyhint=”search”> <input enterkeyhint=”send”> Original Answer Aha… The ‘Go’ button is only shown, if the <input> tag … Read more

How to delete WKWebview cookies

Apple released new APIs for iOS 9 and newer versions, so now we can remove domain-specific cookies stored for WKWebView with the below code. Swift 4/5 version: let dataStore = WKWebsiteDataStore.default() dataStore.fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in dataStore.removeData( ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(), for: records.filter { $0.displayName.contains(“facebook”) }, completionHandler: completion ) } Below is the Swift 3 version let … Read more

Insert CSS into loaded HTML in UIWebView / WKWebView

You can do it like this: – (void)webViewDidFinishLoad:(UIWebView *)webView { NSString *cssString = @”body { font-family: Helvetica; font-size: 50px }”; // 1 NSString *javascriptString = @”var style = document.createElement(‘style’); style.innerHTML = “https://stackoverflow.com/questions/33123093/%@”; document.head.appendChild(style)”; // 2 NSString *javascriptWithCSSString = [NSString stringWithFormat:javascriptString, cssString]; // 3 [webView stringByEvaluatingJavaScriptFromString:javascriptWithCSSString]; // 4 } What this code does: // 1 : … Read more

iPhone Development – Setting UIWebView font

It worked when i modified the string like this. Your right chris, it shouldn’t make any difference. NSString *myDescriptionHTML = [NSString stringWithFormat:@”<html> \n” “<head> \n” “<style type=\”text/css\”> \n” “body {font-family: \”%@\”; font-size: %@;}\n” “</style> \n” “</head> \n” “<body>%@</body> \n” “</html>”, @”helvetica”, [NSNumber numberWithInt:kFieldFontSize], content];

How to show HTML text from API on the iPhone?

As David Liu said, UIWebview is the way to go. I would recommend a few building the HTML string separately and then passing it to the UIWebView. Also, I’d make the background transparent, using [webView setBackgroundColor:[UIColor clearColor]] so that you have an easier time making things look as they should. Here’s a code sample: – … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)