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
How to Switch to Speaker Output When Bluetooth Headsets Are Connected
Replace iOS App Emoji with Twitter Open Source Twemoji
How to Use Avcapturephotooutput to Capture Photo Swift + Xcode
How to Have Firebase Automatically Delete Values Older Than 30 Minutes
Rails: Redirect_To 'Myapp://' to Call iOS App from Mobile Safari
Create a Tabbar Controller with a Master-Detail Template
Crashlytics Does Not Show Crashes
Nsindexpath? Does Not Have a Member Name 'Row' Error in Swift
Map Url Parameters to Objects Using Restkit
Why Is -Force_Load No Longer Required for My Three20 Dependencies in Xcode 4.2
Nsurlcache Does Not Clear Stored Responses in iOS8
Binding Viewmodel and Textfields with Swiftui
iOS Document/File Type Associations - Wildcard Uti
Odd Property Declaration Syntax Containing Angular Brackets <>