Swift 3 Open Link
Use guard to unwrap the textfield text property, replacing the occurrences, add percent encoding to the result and create an URL from the resulting string:
Try like this:
guard
let text = birdName.text?.replacingOccurrences(of: " ", with: "+"),
let query = text.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let url = URL(string: "https://google.com/#q=" + query)
else { return }
if #available(iOS 10.0, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
How to open another View from links within UIWebview in Swift 3?
From inside if block, you need to return false, and it should work.
By returning false the delegate method tells that the webView should not start loading the url.
public func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if request.url?.scheme == "myapp" {
// do your work here
UIApplication.shared.open(request.url!, options: [:], completionHandler: nil)
//Add the below line of code to the existing code
return false
}
return true
}
How to open an URL in Swift?
All you need is:
guard let url = URL(string: "http://www.google.com") else {
return //be safe
}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
How to open an URL with parameter in Swift3
Yea I figure out the problem path parameter
not working anymore but query parameter
working
func shareToInstagram() {
let instagramURL = URL(string: "instagram://user?username=mark20")
if (UIApplication.shared.canOpenURL(instagramURL! as URL)) {
UIApplication.shared.open(instagramURL!, options: ["":""], completionHandler: nil)
print("miss you so much ")
} else {
print(" Instagram isn't installed ")
}
}
more check this link instagram iPhone Hooks
Opening an url in the background with swift 3?
I believe what you're looking for is an HTTP request. This is what browsers do to get content from a webpage. There are many ways to do an HTTP request to a url in iOS. One such way is with the URLSession class.
let url = URL(string: "http://www.google.com/") //Or your URL
var request = URLRequest(url: url!)
request.httpMethod = "POST"
request.httpBody = "Data to send to your backend".data(using: .utf8)!
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if error != nil {
//There was an error
} else {
//The HTTP request was successful
print(String(data: data!, encoding: .utf8)!)
}
}
task.resume()
This will send the data in the httpBody
property to your backend in a HTTP request.
Related Topics
How to Add Frameworks into the Swift Project
How to Create a Scnnode from a .Usdz
How to Programatically Create a UIviewcontroller in Swift
Error | [Ios] File Patterns: the 'Source_Files' Pattern Did Not Match Any File
Swift 4.2 Make Bottom of Tableview Move Up When Keyboard Shows
Can't Pan Image Taken from Camera with Uiimagepicker
Proper Sequence to Get Registration Token for Gcm Push Notification on iOS? Is Gcm Unreliable
Replacement for Arkit in iOS10
iOS Add Button to Widget Extension
Initialization of 'Unsafepointer<Int>' Results in a Dangling Pointer
Testflight Sdk and iOS Simulator - How to Use
Didreceiveremotenotification Not Called in Background Mode
Programmatically Change Multiplier of Alignment Constraint of Center X/Y
iOS Facebook Sdk Error Domain Com.Facebook.Sdk Code 2 and Code 7