When the user taps on a button i want to check if they have opera crypto browser installed. If they have it installed already then i want to open the url in opera crypto browser otherwise they will be redirected to app store to install the app.
The only problem with this code is that it will just open the opera crypto browser app instead of opening and loading the url that i have given. Everything else works fine. Is there anything i am doing wrong in the url or code?
let appScheme = "\("cryptobrowser")://app"
let appUrl = URL(string: appScheme)
if UIApplication.shared.canOpenURL(appUrl! as URL){
guard let url = URL(string: "cryptobrowser://reizor.com/backup8march/test2.php?token=10000000000000000000") else {return}
UIApplication.shared.open(url)
}else{
guard let url = URL(string: "https://apps.apple.com/pk/app/opera-crypto-browser/id1604311726") else {return}
UIApplication.shared.open(url)
}
So basically what i was doing wrong was that in my if condition where i checked to see if user has cryptobrowser installed and then i converted my url string to URL and opened it using UIApplication.shared.open() function. My URL was wrong.
I had to change my URL slightly from:
guard let url = URL(string: "cryptobrowser://reizor.com/backup8march/test2.php?token=10000000000000000000") else {return}
UIApplication.shared.open(url)
to:
guard let url = URL(string: "cryptobrowser://open-url?url=https://reizor.com/backup8march/test2.php?token=10000000000000000000") else {return}
UIApplication.shared.open(url)
Basically adding "open-url?url=https://" after the "cryptobrowser" which is the name of browser i want the link to load in. Because apparently, to open URl in some browsers you just have to write "browserName://yourUrl" and it would open but in most case you have to include "https://" in your URL after writing the name of browser
Related
Thank you in advanced for giving your valuable time for reading this.
I have tried to implement dynamic link through firebase sdk.
Have gone through provided documents for implementing this by firebase.
Issue I face is when I share dynamic link through application generated using below code
guard let link = URL(string: "\(Constant.dynamicLinkBaseUrl)\(urlPathComponent)/\(encShareDetail ?? "")") else { return }
let dynamicLinksDomainURIPrefix = Constant.DomainURIPrefix
let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: dynamicLinksDomainURIPrefix)
linkBuilder?.iOSParameters = DynamicLinkIOSParameters(bundleID: Bundle.main.bundleIdentifier ?? Constant.AppBundleID)
linkBuilder?.navigationInfoParameters?.isForcedRedirectEnabled = true
linkBuilder?.iOSParameters?.fallbackURL = URL(string:Constant.AppStoreFallbackUrl)
linkBuilder?.androidParameters = DynamicLinkAndroidParameters(packageName: Constant.AndroidPackageName)
linkBuilder?.androidParameters?.fallbackURL = URL(string: Constant.AndroidFallbackUrl)
linkBuilder?.shorten() { url, warnings, error in
print("URL :: \(String(describing: url?.absoluteString))\nWarnings :: \(String(describing: warnings?.debugDescription))\nError :: \(String(describing: error?.localizedDescription))")
guard let url = url, error == nil else { return }
print("The short URL is: \(url)")
tabBarControllerObj?.presentDefaultShare(videoURL: url.absoluteString)
}
On taping the generated link in device, my application is launched and it am able to get the generated dynamic link in
scene(_ scene: UIScene, continue userActivity: NSUserActivity)
method, I'm able to get the link with the below code
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL,
let host = url.host else {
return
}
print("URL :: \(url.absoluteString)\nHost :: \(host.debugDescription)")
but not able to get the deep link I have created as when I called the method
DynamicLinks.dynamicLinks().handleUniversalLink(url)
It returns with error as "The operation couldn’t be completed. Universal link URL could not be parsed by Dynamic Links."
Don't found any solution related to this as the same Dynamic link is working fine for Android app.
Please help me as I'm stuck with it for around 4 days.
I was able to solve this issue by adding all my url prefixes to info.plist.
<key>FirebaseDynamicLinksCustomDomains</key>
<array>
<string>https://<custom domain>/login</string>
<string>https://<custom domain>/</string>
</array>
More details at https://firebase.google.com/docs/dynamic-links/custom-domains#console
I have download file and saved it into application memory
/Users/MYName/Library/Developer/CoreSimulator/Devices/EDE3E3-E3E5-444C-B04F-6F8F971F2739/data/Containers/Data/Application/6A7D0012-9ACC-4383-BDBA-A98B89018C8C/Library/Caches/CreatedURLDirectory/sample.pdf
How to load Caches/MyDictionaryCreated -> sample.pdf on WKWebView.
*if let url = URL(string: url.path) {
DispatchQueue.main.async {
let request = URLRequest(url: url)
self.webView.load(request)
self.webView.isHidden = false
}
}*
Above url is my file path...
But I know this is not proper way to load
If you want to load a local file into web view you should use loadFileURL instead, for example:
let url = URL(fileURLWithPath: pathToYourFile)
webView.loadFileURL(url, allowingReadAccessTo: url)
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"
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
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")
}
}
I don't want to write the link " https://stackoverflow.com/questions/ask" as shown in this line. I want url to receive the last copied URL from clipboard, what should I add?
let url = URL(string: "https://stackoverflow.com/questions/ask")
Copy
let url = URL(string: "https://stackoverflow.com/questions/ask")
UIPasteboard.general.string = url
Paste
if let url = UIPasteboard.general.string {
url = url
}
I've seen that you can download an image in IOS through a URL. However, this requires that the URL be public. I'd much rather do it in such a way where my application makes a request to the server and if the necessary requirements are met, the server responds with an image. I do not want my images to be visible from the web.
The easiest option is to put the password in the URL:
let url = NSURL(string: "http://exapmle.com/2XwLZAgAO2VP9JqXg1s73zmB/foo.png")
let dataOptional: NSData? = NSData(contentsOfURL: url)
if let data = dataOptional {
let image = UIImage(data: data)
} else {
println("Error loading \(url)")
}