Can't see anything in Web.load(URLRequest(url: URL(string: "https://google.com")!)) - swift

I am trying to make a macOS app using Xcode 12.4 , that opens webpages. When I try to use Web.load(URLRequest(url: URL(string: "https://google.com")!)) , I see an empty window.
I use a WKWebView in Main.storyboard
Here is the ViewController.swift code:
import Cocoa
import WebKit
let webView = WKWebView()
class ViewController: NSViewController {
#IBOutlet weak var Search: NSSearchField!
#IBOutlet weak var Web: WKWebView!
var web: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
Web.load(URLRequest(url: URL(string: "https://google.com")!))
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}

I just found the simplest solution to this problem: remove the App Sandbox! More information about this here: https://developer.apple.com/forums/thread/92265

Related

Particles Speed Up When Recording A Video Using ARVideoKit

We have an ARKit & SceneKit app that records videos using ARVideoKit pod (link). Inside our scene we have a fire particle. Fire is playing at a slow speed. However, when you start recording a video the fire particle speeds up. I can't figure out why the fire particle is speeding up. Please see the video (here) to see the issue.
Here's a sample project which you can use to test the issue: Project
I would appreciate if anyone can explain why this is happening.
Edit 1: Below is my ViewController Code
import UIKit
import ARKit
import SceneKit
import ARVideoKit
class ViewController: UIViewController, ARSCNViewDelegate {
#IBOutlet var sceneView: ARSCNView!
#IBOutlet weak var photoButton: UIButton!
#IBOutlet weak var videoButton: UIButton!
#IBOutlet weak var takeVideoButtonPressedLabel: UILabel!
// ARVideoKit Variables
var recorder : RecordAR?
var takenImage: UIImage?
var takenVideoAtURL : URL?
let recordingQueue = DispatchQueue(label: "recordingThread", attributes: .concurrent)
var arTrackingConfig = ARWorldTrackingConfiguration()
override func viewDidLoad() {
super.viewDidLoad()
sceneView.delegate = self
sceneView.scene = SCNScene(named: "art.scnassets/fire.scn")!
self.resetTracking()
}
func resetTracking() {
arTrackingConfig = ARWorldTrackingConfiguration()
arTrackingConfig.isLightEstimationEnabled = true
sceneView.session.run(arTrackingConfig, options: [.resetTracking,
.removeExistingAnchors])
}
}
// MARK: - ARVideoKit Implementation
extension ViewController {
#IBAction func takePhoto(_ sender: UIButton) {
// Do Nothing
}
#IBAction func takeVideo(_ sender: UIButton) {
setupCamera()
startRecording()
}
func setupCamera() {
recorder = RecordAR(ARSceneKit: sceneView)
recorder?.prepare(arTrackingConfig)
}
func startRecording() {
takeVideoButtonPressedLabel.isHidden = false
recordingQueue.async {
self.recorder?.record(forDuration: 5) { path in
self.takenVideoAtURL = path
DispatchQueue.main.async {
self.takeVideoButtonPressedLabel.isHidden = true
}
}
}
}
}
Edit 2: Added sample project for testing.
While getting the image from SCNRenderer using snapshot method pass 0 as time , this way force rendering will not happen and animations will be smoother. In your case particles will not speed up

Q: How to change language PDF page indicator?

I want to change the language of the page indicator, it should be german and not english. If you scroll inside of a pdf file it shows you "1 of 6" that's what i want to change.
Any ideas?
import UIKit
import WebKit
class PDFViewController: UIViewController {
var pdfName: String?
#IBOutlet weak var wkWebView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let pdfFilePath = Bundle.main.url(forResource: pdfName!, withExtension: "")
let urlRequest = URLRequest.init(url: pdfFilePath!)
wkWebView.load(urlRequest)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Xcode Project -> Info -> Localizations add German
was the answer!
Thanks #Retterdesdialogs

Mac OSX app not loading URL in Webkit View

I am trying to load a URL inside a Webkit View in a Mac OX app using Swift.
This is how my code looks like right now:
import Cocoa
import AppKit
import Foundation
import CoreData
import WebKit
class ViewController: NSViewController, WKUIDelegate {
#IBOutlet weak var rightBox: NSView!
#IBOutlet weak var leftBox: NSView!
#IBOutlet var myWebView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
self.view.wantsLayer = true
// Do any additional setup after loading the view.
}
override func viewWillAppear() {
leftBox.layer?.backgroundColor = NSColor.blue.cgColor
rightBox.layer?.backgroundColor = NSColor.red.cgColor
let myURL = URL(string: "https://www.apple.com")
let myRequest = URLRequest(url: myURL!)
myWebView.load(myRequest)
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
When I run the code, I only see blank white box.
I have tried placing the url loading code both in the viewDidLoad as well as viewWillAppear. Same result.
I am trying to figure out what I might be doing wrong.
Any suggestions?
Thanks
Have you enabled outgoing connections for your application?
Had it been an http:// URL you'd also have to turn on NSAllowsArbitraryLoads in your Info.plist.

image is complaining fatal error: unexpectedly found nil while unwrapping an Optional value

I have a master/detail app, where I need to get the image from the master and put it in the detail
It's complaining on the imageView line although I have a file called Gerbera.png image but it won't show. Also how do I call the image from the master to the detail page?
class DetailViewController: UIViewController {
#IBOutlet weak var webView: UIWebView!
#IBOutlet weak var detailDescriptionLabel: UILabel!
#IBOutlet weak var imageView: UIImageView!
#IBOutlet weak var btnCall: UIButton!
func configureView() {
// Update the user interface for the detail item.
if let detail: AnyObject = detailItem {
if let myWebview = webView {
let stringRepresentation = MasterViewController.MyVariables.urlString?.joined(separator:"")
print ("urlString", MasterViewController.MyVariables.urlString)
print ("sR",stringRepresentation)
let url = NSURL(string: stringRepresentation as! String)
let request = URLRequest(url: url! as URL)
myWebview.scalesPageToFit = true
myWebview.loadRequest(request)
}
imageView.image = UIImage(named:"Gerbera.png")!
}
}
Please try this line
imageView.image = UIImage(named:"Gerbera")!
I found the answer for this. My Detail View shows image on the top then web view on the bottom. I realized that the detail view should show code for the image first before code for the web view. So I put it under viewDidLoad() and it worked!
override func viewDidLoad() {
super.viewDidLoad()
imageView1.image = MasterViewController.MyVariables.flowerImage!.first

Why isn't my WKWebView resizing properly inside my subview?

I am creating a minimal WebKit browser for a Mac OS App using the following Swift code to load the new WKWebView into an Custom View Object.
When I run the App the web page loads correctly and fills the window, however if the window is resized the subview does not resize with the window.
Any Help would be most appreciated.
import Cocoa
import WebKit
import AppKit
#NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate {
#IBOutlet weak var window: NSWindow!
#IBOutlet weak var customView: NSView!
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
var url = NSURL(string:"http://www.google.com/")
var request = NSURLRequest(URL:url!)
var theWebView:WKWebView = WKWebView(frame: customView.bounds)
self.customView.autoresizingMask = NSAutoresizingMaskOptions.ViewWidthSizable | NSAutoresizingMaskOptions.ViewHeightSizable
self.customView.addSubview(theWebView)
theWebView.loadRequest(request)
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
}