openURL: deprecated in iOS 10
Write like this.
Handle completionHandler
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:@"http://www.google.com"];
[application openURL:URL options:@{} completionHandler:^(BOOL success) {
if (success) {
NSLog(@"Opened url");
}
}];
Without handling completionHandler
[application openURL:URL options:@{} completionHandler:nil];
Swift Equivalent:- open(_:options:completionHandler:)
UIApplication.shared.open(url)
How to use openURL in iOS 10?
You should write it like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"] options:@{} completionHandler:nil];
OpenURL in iOS10
Swift 3+:
func open(scheme: String) {
if let url = URL(string: scheme) {
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:],
completionHandler: {
(success) in
print("Open \(scheme): \(success)")
})
} else {
let success = UIApplication.shared.openURL(url)
print("Open \(scheme): \(success)")
}
}
}
Usage:
open(scheme: "tweetbot://timeline")
Source
OpenUrl not working on iOS10
Add LSApplicationQueriesSchemes
key in info.plist file.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>comgooglemaps</string>
</array>
Use this....
Objective c
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"comgooglemaps://maps.google.com/maps"] options:@{} completionHandler:nil];
Swift 4
guard let url = URL(string: "comgooglemaps://maps.google.com/maps") else {
return //be safe
}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: instead in Swift 3
Use like
//inside scope use this
let myUrl = "http://www.google.com"
if let url = URL(string: "\(myUrl)"), !url.absoluteString.isEmpty {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
// or outside scope use this
guard let url = URL(string: "\(myUrl)"), !url.absoluteString.isEmpty else {
return
}
UIApplication.shared.open(url, options: [:], completionHandler: nil)
For more reference see this sample link.
Can't make native call programmatically in ios10
openURL(_:) is deprecated in iOS 10.
The new UIApplication method openURL:options:completionHandler:, which
is executed asynchronously and calls the specified completion handler
on the main queue (this method replaces openURL:).
New method in iOS 10:
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options
completionHandler:(void (^ __nullable)(BOOL success))completion
Like,
UIApplication *application = [UIApplication sharedApplication];
[application openURL:URL options:@{} completionHandler:nil];
Example:
NSURL *URL = [NSURL URLWithString:@"tel:37146903"];
if([[UIDevice currentDevice].systemVersion floatValue] >= 10.0){
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
[application openURL:URL options:@{}
completionHandler:^(BOOL success) {
NSLog(@"Open %@: %d",scheme,success);
}];
} else {
BOOL success = [application openURL:URL];
NSLog(@"Open %@: %d",scheme,success);
}
}
else{
bool can = [[UIApplication sharedApplication] canOpenURL:URL];
if(can){
[[UIApplication sharedApplication] openURL:URL];
}
}
Read in more detail here:
https://useyourloaf.com/blog/openurl-deprecated-in-ios10/
Method openURL:options:completionHandler compatibility in objective c
The new UIApplication method openURL:options:completionHandler:, which
is executed asynchronously and calls the specified completion handler
on the main queue (this method replaces openURL:)
This is under Additional Framework Changes > UIKit at: https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewIniOS/Articles/iOS10.html
you need use it like this:-
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
Related Topics
How to Apply a Vignette Cifilter to a Live Camera Feed in iOS
Is There an iPhone Se Simulator for Xcode 11, iOS 13
-Canopenurl: Failed for Url: "Fbauth2:/" (Osstatus Error -10814.)"
Firebase Cloud Messaging - Send Message to All Users
Passing Parameters to a Method Called by Nstimer in Swift
Can Not Save File Inside Tmp Directory
Smart-Search for Parse Usernames in Swift Not Working
Does This App Use the Advertising Identifier (IDFA)? - Admob 6.8.0
Core Data Multi Thread Application
How to Disable Floating Headers in Uitableview with Uitableviewstyleplain
Uipangesturerecognizer - Only Vertical or Horizontal
Cocoapods: Failed to Connect to Github to Update the Cocoapods/Specs Specs Repo
How to Check If a File Exists in Documents Folder
Add "Edit in Excel" or "Edit Photo" Extension
In Firebase, How to Query the Most Recent 10 Child Nodes