Reputation: 1119
I am designing a webview app in ios. I started making change in my code. And the code change is perfectly alright. The app is responding in simulator(iPhone 7) as it should respond. But when I deploy the app to device(iPhone 7) the app only displays blank page.
It is weird. I read many articles where they were talking about network carrier. Currently it is showing No Service
. I tried re-inserting the sim card. But it was of no use. I dont know if that was of any use or not.
If someone could tell what all should I try to debug this out.
Question Update
How I am loading webview
Case 1: When I take the index.html
from softlink in project directory then I am able to do it in my device
func getLandingPage() -> URLRequest {
let path = Bundle.main.path(forResource: "www", ofType: nil)!
let url = URL(fileURLWithPath: "\(path)/index.html")
return URLRequest(url: url)
}
URL created- "file:///var/containers/Bundle/Application/9890F84F-4CF4-48AB-8874-AC1BC0B77C55/ios.app/www/index.html"
case 2: When I copy all the files from my softlink directory to directory inside documentDirectory of device and then if I try to load index.html
from there then it displaying blank page. And I want this to happen correctly.
func getLandingPage() -> URLRequest {
let docURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let pathData = "\(docURL[0].path)/\(CODE_FOLDER)/index.html"
let url = URL(fileURLWithPath: pathData)
return URLRequest(url: url)
}
URL create- "file:///var/mobile/Containers/Data/Application/427943C3-2238-49A3-AFCC-5561062B7CDA/Documents/CODE/index.html"
Upvotes: 0
Views: 450
Reputation: 452
Try to check that URL through this if its opening or not on a button tap to debug weather its working fine or not in device in your condition.
guard let url = URL(string: "your url string/ path") // or directly your URL
else { return }
if UIApplication.shared.canOpenURL(url)
{
if #available(iOS 10.0, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
}
else
{
print("This doesn't seem to be a valid URL")
}
You can also try this out as documents directory on simulator is different from the real device:
let documentDirUrl = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) // give your url here
let indexFileUrl = documentDirUrl.appendingPathComponent("index.html") // then append the path component of your html file
webView.loadFileURL(indexFileUrl, allowingReadAccessTo: documentDirUrl) // load the webview
Upvotes: 2
Reputation: 844
Maybe try this one for local folders. You can check if your is File exit or not.
func getLandingPage() -> URLRequest {
let docURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let path = "\(CODE_FOLDER)/index.html"
let url = documentURL.appendingPathComponent(path)
if FileManager.default.fileExists(atPath: (url?.path)!) {
return URLRequest(url: url)
} else {
print("File doesn't exists")
}
}
Upvotes: 0