Canopenurl Not Working in iOS 10

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

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: 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 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



Related Topics



Leave a reply



Submit