Openurl: Deprecated in iOS 10

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)

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.

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

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 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)
}

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/

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];


Related Topics



Leave a reply



Submit