Swift Error : Classes implemented in two places but files I don't touch? - ios

I am testing out swifts UIWebView, I have placed a simple UIWebview on my storyboard and this is my viewController code
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = URL(string: "https://mywebsitehere.com")
webView.loadRequest(URLRequest(url: url!))
} }
Unfortunately I am getting this Error below, I have added App transport security settings to my app like other answers to a similar question have said to do but it still isn't working...
Can anyone help?
objc[946]: Class PLBuildVersion is implemented in both
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices
(0x124feecc0) and
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices
(0x124e056f0). One of the two will be used. Which one is undefined.

This is bug with xCode while simulating the real iOS device, some time it through such kind of error.
Please check whether your url is active or not.
let url = URL(string: "https://google.com")
webView.loadRequest(URLRequest(url: url!))
I used the same code with google URL and it is working.

Related

WKWebView is not loading web page on iOS 13

I am trying to load a webpage with WKWebView on iOS 13 with Swift. It works fine in iOS 12. The problem is the WKWebView shows a white screen on iOS 13. The same url used for both (iOS 12/iOS 13) so I am 100% sure that there is no problem in the URL. Here is my UIViewController where I load the webpage:
import UIKit
import WebKit
class WebViewController: UIViewController , WKNavigationDelegate{
var param : String!
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://google.com")!
webView.load(URLRequest(url: url))
}
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
}
safari inspector result :
for iOS 13 similator is about:blank
for real device iOS 12.4 is www.google.com
One way to ensure you will always have a valid URL before making the request is by using an 'if' instead of force unwrapping.
override func viewDidLoad() {
super.viewDidLoad()
if let url = URL(string: MyData.url){
webView.load(URLRequest(url: url))
}
}
You can also add an else statement on there or use an early return to print something out if you don't go inside.
Other than doing this to check the url is valid you can debug and check the webview to see if that is nil. If this is the case then your solution is to add your code to viewWillAppear instead of viewDidLoad.
I tried it also with iOS 12.2 version on simulator and gives the same problem , so I see that the simulators does not support WKWebView , on the real device it works fine

Enable zooming in WKWebView in Swift 4, Xcode 10, for iOS 12

I am trying to enable zooming/magnification (by pinching) in a very simple WebView in a simple app. (I am pretty new to this).
The Swift code that loads the web page is this and it works fine, I got from here, I think.
import UIKit
import WebKit
class SecondViewController: UIViewController {
#IBOutlet weak var WebViewSchedule: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// load the page
let url = URL(string: "https://mywebsite.com")
let request = URLRequest(url: url!)
WebViewSchedule.load(request)
//how do i make it zoomable ????
}
}
I've looked at a number of answers about this, and they all refer to a property "allowsMagnification". I have tried various ways of using this and got nowhere.
So could some kind person give me a beginners' guide to how to make my iOS Web page zoomable?

Swift webview PROXY

With the code below I create a webview navigating to a URL. It works perfectly. But I need this navigation to be through an HTTP proxy.
How do I put proxy in a webview?
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
webView = WKWebView()
webView.navigationDelegate = self
view = webView
let url = URL(string: "https://www.iphub.info")!
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
}
}
Unfortunately, there's no simple way to achieve that.
You may intercept deprecated UIWebView with custom NSURLProtocol subclass, which utilizes NSURLSession inside. You'd easily set HTTP proxy configuration to the connectionProxyDictionary property of the NSURLSessionConfigurtion. Here's the example. That would work, but you may see slightly worse performance than with WKWebView.
Alternatively, you may consider using NetworkExtension.framework, if the proxy server supports tunneling. Here's a sample project which utilizes Network Extension.

How to setup EVURLCache in iOS Swift 3

I create a app for loading a website. It loads fine but it takes 2 to 3 min every time. So I choose to implement EVURLCache.
I use the pod for EVURLCache. And I import that in MainVC.But I don't know how to setup it.
my Aim is to reduce the load time one time it loaded.
GitHub of EVURLCache : https://github.com/evermeer/EVURLCache
MainVC
import UIKit
import EVURLCache
class MainVC: UIViewController, UIWebViewDelegate {
#IBOutlet weak var webView: UIWebView!
#IBOutlet weak var activityIndicator: UIActivityIndicatorView!
override func viewDidLoad() {
super.viewDidLoad()
activityIndicator.startAnimating()
webView.delegate = self
let BASE_URL = "http://www.xeoscript.com/"
let url = URL(string: BASE_URL)
let request = URLRequest(url: url!)
webView.loadRequest(request)
}
func webViewDidFinishLoad(_ webView: UIWebView) {
activityIndicator.stopAnimating()
}
}
As you can see in the appdelegate of the demo, it's enough to add the following line in your didFinishLaunchingWithOptions.
EVURLCache.activate()
See the demo appdelegate for the available configuration options.
If you then run the app, then all your content will be downloaded to a Cache folder in your documents folder. The next time you start the app the files will be loaded from there. It's also possible to include that cache folder inside your app so that people will have the data available directly after downloading your app. The only thin you have to do for this is copying the content from the Cache folder to a PreCache folder in the root of your application.
See the demo app to see how it is setup.

ArcGIS iOS Map does not pan or zoom

I am walking through the basic iOS guide to add a map to my App here: https://developers.arcgis.com/ios/10-2/swift/guide/develop-your-first-map-app.htm
When running the app, it displays the basemap I have added but it does not seem to respond to any actions so I can not pane/zoom.
Here is my exact Swift controller code:
import UIKit
import ArcGIS
class ViewController: UIViewController, AGSMapViewLayerDelegate {
#IBOutlet var mapView: AGSMapView!
override func viewDidLoad() {
super.viewDidLoad()
let tiledLayer = AGSLocalTiledLayer(name: "Norfolk")
self.mapView.addMapLayer(tiledLayer, withName: "Norfolk")
mapView.locationDisplay.startDataSource()
}
}
I have tested on both an iPad and iPhone and the behavior is the same.
I am using ArcGIS 10.2.5
Where is your map url?
let url = NSURL(string: "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer")
let tiledLayer = AGSTiledMapServiceLayer(URL: url)
self.mapView.addMapLayer(tiledLayer, withName: "Basemap Tiled Layer")
And have you added Privacy - Location When In Use Usage Description into info.plist of your app? You should do that if you call
mapView.locationDisplay.startDataSource()
I am not sure what I did incorrectly the first time, but I removed the view and re added it and it worked the 2nd time.

Resources