WebKit WKWebView attempts to make service calls to Apple when using local URL - xcode

I'm using Webkit WKWebView to display locally stored HTML files in my OSX application for specific formatted pages.
Each of the WebView objects is linked to a WKWebview object in the storyboard of the application and is initialized using:
#IBOutlet var webView: WKWebView! = WKWebView()
I then display a local HTML using WebView:
let url = Bundle.main.url(forResource: "termsandconditions", withExtension: "html")
let urlRequest = NSURLRequest(url: url!)
outputView.load(urlRequest as URLRequest)
For each of the Webview Objects defined, XCode returns a warning
Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
Am I initializing the WebViews correctly? Why is it trying to connect to the Apple service if I'm only using a local URL?

Determined that this is an Xcode issue making a call to the Apple. When compiled and running on a different device I cannot pick up the call being made.

Related

WKWebView process terminates without sandbox entitlement

I'm trying to build a simple MacOS app with a web view. I'm using WKWebView and for no obvious reason the webViewWebContentProcessDidTerminate() method is called immediately after the web view is initialized without the web view even trying to load anything. After hours of looking in the documentation and in issues online, I cannot figure out why this is happening and how to prevent it. The only thing suggested online was to reload the web view when this happens which results in the method getting called again a moment later and so on endlessly. I'm now down to a completely empty MacOS app with the following source code:
class AppDelegate: NSObject, NSApplicationDelegate {
#IBOutlet weak var window: NSWindow!
var webView: WKWebView!
func applicationDidFinishLaunching(_ aNotification: Notification) {
webView = WKWebView(frame: .zero, configuration: WKWebViewConfiguration())
webView.navigationDelegate = self
}
}
extension AppDelegate: WKNavigationDelegate {
func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {
print("web view process did terminate")
webView.reload()
}
}
It doesn't matter if the web view is in the view hierarchy, has a non-zero frame and generally if it is visible or not. I've also enabled arbitrary loads just for the sake of trying out everything.
I would really appreciate some help on this. I'm compiling against 10.13 SDK and running on a MacOS 10.12.
Thanks.
I managed to figure it out. For anybody else struggling with this, you need to add the com.apple.security.network.client entitlement to your app.
If wkwebview is getting terminated, you can add reload method inside webViewWebContentProcessDidTerminate method, which basically reloads the webview.
Check the below code,
file name: CRAWKWebView.m
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView
{
RCTLogWarn(#"Webview Process Terminated");
if (webView) {
[webView reload];
}
}
reload instance is provided by wkwebview.

Open Native iOS app from Xamarin.Forms

I have an native iOS sample app installed in my iPad and also my sample xamarin.Forms App installed. I want to open native iOS app from Xamarin.forms when clicked on button. I have set URL schema in my native iOS app in info.plist.
How do I open native app from xamarin.forms on click of a button. I already tried
var request = Device.OnPlatform(
string.Format("native app url"),
string.Format("native app url"),
string.Format("native app url"));
Device.OpenUri(new Uri(request));
but its not working.
It's basically how you are doing it.
var url = Device.OnPlatform(iOSUrl, androidUrl, winPhoneUrl);
Device.OpenUri(new Uri(request));
Be aware that each platform have some requirements in the way to url is configured and parameters are sent.
Let say to get the maps app open in each platform you would use these urls schemes:
// iOS doesn't like %s or spaces in their URLs, so manually replace spaces with +s
var iOSUrl = string.Format("http://maps.apple.com/maps?q={0}&sll={1}", name.Replace(' ', '+'), loc);
var androidUrl = string.Format("geo:0,0?q={0}({1})", string.IsNullOrWhiteSpace(addr) ? loc : addr, name);
var winPhoneUrl = $"bingmaps:?cp={loc}&q={name}";
var url = Device.OnPlatform(iOSUrl, androidUrl, winPhoneUrl);
Also you cannot open any arbitrary app unless you know its Url scheme.
Anyway, if the Device.OpenUri() doesn't fulfill your requirements you are good to create your own implementations using the native APIs.
Please go through the below link and attached photo
Link:-launch-an-app-from-within-another-iphone
I am using below code in xamarin forms
NSUrl request = new NSUrl("Camera://");
var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(request.ToString()));
if (!canOpen)
{ Task.FromResult(false); }
else
{
Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl(request.ToString())));
}

xcode swift: how to display a website as pop-over

I am working on an app with links to external websites. I have been using code that opens safari separately, but I would like code that opens the website as a pop-over. Is this an option?
UIApplication.sharedApplication().openURL(NSURL(string:"http://www.bing.com")!)
You can use a UIWebView and load the url into it, you can add that to an existing view or create a view controller with a web view in it and present it as a popover.
let aWebView = UIWebView()
let myUrl = NSURL(string: "http://www.google.com")
let urlRequest = NSURLRequest(URL: myUrl!)
aWebView.loadRequest(urlRequest)
self.view.addSubview(aWebView)

WebView load HTML page with all resources from a local directory

I am developing a COCOA application. It's a requirement of the application to load HTML page from a local directory. The HTML page includes links to many resources such as images, JavaScript, XML and CSS file. Hence it's more like a local website without any server. How can I achieve this using WebView control? I am developing application for Mac OS X.
Any help would be highly appreciated,
Farooq-
You can simply use this code -
[[yourWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:pathOfLocalWebPage]]];
Hope this helps :)
Swift 3:
let urlpath = Bundle.main.path(forResource: "index", ofType: "html");
let requesturl = URL(string: urlpath!)
let request = URLRequest(url: requesturl!)
webView.mainFrame.load(request)

how to make web browser in Xcode load a web page automatically

I am building a web browser in Xcode cocoa application, using the interface builder. I have it all working when it comes to typing in web address and clicking go.
but I would like for it to automatically load a web page instead of seeing white when I open my project, I looked in inspector to see if you can set a specific web address but I couldn't find anything to do this.
How about if you load the URL that you would like in the viewdidload function:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *targetURL = [NSURL fileURLWithPath:WebsitePath];
NSURLRequest *WebRequest = [NSURLRequest requestWithURL:targetURL];
[self.WebViewer loadRequest:WebRequest];
self.WebViewer.scalesPageToFit = YES;
}
Maybe you can try to load the WebView when the application finish launching,just add the URL Request in the applicationDidFinishLauching parameter,else if your WebView is on the MainView you can add a loadingScreen that appear while the webView is loading!
Lucky!

Resources