I'd like to redirect the user to the general settings page, not the application settings page (with permissions, etc.). Is that possible and if so, how?
Try this!!
let url = NSURL(string: UIApplicationOpenSettingsURLString)
if UIApplication.shared.canOpenURL(url as! URL) {
UIApplication.shared.openURL(url as! URL)
}
To navigate to specific page, check this link:
How do i open phone settings when a button is clicked ios
Try below code
UIApplication.shared.open(URL(string:"App-Prefs:root=General")!, options: [:], completionHandler: nil)
Related
I run the shortcuts with the x-callback url given below code:
let url = URL(string: "shortcuts://x-callback-url/run-shortcut?name=Airplane&x-success=shortcutsdemo://")
UIApplication.shared.open(url!, options: [:], completionHandler: nil)
When I open the URL in UIApplication.shared.open, it runs the shortcut and after its done, return back to our iOS app.
My question is if my shortcut is not added in shortcuts app, how I manage?
Is there any way to first find our shortcut is added or not in shortcuts app and then we run the shortcut.
Like :
if (Shortcut.isInstalled) {
let url = URL(string: "shortcuts://x-callback-url/run-shortcut?name=Airplane&x-success=shortcutsdemo://")
UIApplication.shared.open(url!, options: [:], completionHandler: nil)
} else {
print("Not installed")
}
Summary :
If the shortcut is added in our shortcuts app, Then it's run the shortcuts using our iOS app. Otherwise its not run. and give an error for that shortcut.
I think you will need to use func canOpenURL(_ url: URL) -> Bool
let url = URL(string: "shortcuts://x-callback-url/run-shortcut?name=Airplane&x-success=shortcutsdemo://")
if UIApplication.shared.canOpenURL(ur!l) {
print("Short uts is installed")
} else {
print("Shortcuts not installed")
}
I am not 100% sure, but I think it redirects you automatically to appstore if you don't have it, check that out.
https://developer.apple.com/documentation/storekit/skstorereviewcontroller/2851536-requestreview
Apple document suggest to automatically open a page on which users can write a review in the
App Store, append the query parameter action=write-review to your
product URL.
I want to redirect the user to write a comment page of the app on the app store.
I am new to iOS please guide me to achieve this functionality.
Thank you.
here i what i am using
let appID = "Your App ID on App Store"
let urlStr = "itms-apps://itunes.apple.com/app/id\(appID)?action=write-review"
if let url = URL(string: urlStr), UIApplication.shared.canOpenURL(url) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
Inside an iOS app of mine I want to set a button which is going to allow me to view a movie in the iTunes app.
Is that possible?
If yes, how can I do it?
Swift 3, iOS 10 and above.
if let url = URL(string: "itms://itunes.apple.com/"),
UIApplication.shared.canOpenURL(url){
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
I have a custom URL set up for a Swift application. I would like to use this URL on another app's button action to deep link. I tried UIApplication.shared.open(NSURL(string: "redirectToApp://Testapp/startPage")! as URL, options: [:], completionHandler: nil) but, it isn't working. Any suggestions?
Update:
redirectToApp://Testapp/startPage opens the app from a Safari.
Thanks!
Make sure you write code with error checking / handling so you can figure out what's not working.
Try it like this:
if let url = URL(string: "redirectToApp://Testapp/startPage")
{
if UIApplication.shared.canOpenURL(url)
{
UIApplication.shared.open(url, options: [:], completionHandler: {
(success) in
if (success)
{
print("OPENED \(url): \(success)")
}
else
{
print("FAILED to open \(url)")
}
})
}
else
{
print("CANNOT open \(url)")
}
}
Firstly, you shouldn't use NSURL in Swift3, you should use the native Swift version, URL. On iOS9+ you also have to add LSApplicationQueriesSchemes entries to your Info.plist file in order to be able to open apps using deep links.
For example if you want to open the Uber app, you have to do:
UIApplication.shared.open(URL(string: "uber://)!). from code and add these lines to your Info.plist file:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>uber</string>
</array>
I'm creating an iOS application with a password reset feature that sends an email to the user. After sending the email I want to display a UIAlertController to the user asking them if they would like to open the mail application.
I've seen various posts on here along the lines of:
let url = NSURL(string: "mailto:")
UIApplication.sharedApplication().openURL(url!)
This works but unfortunately it starts a new message which is not what I want. I only want to launch the application so the user can see their inbox.
Not tested myself but maybe this answer will help you:
Apparently Mail supports a second url scheme message:// which (I suppose) allows you to open a specific message if it was fetched by your application. If you do not provide a full message url, it will just open Mail:
let mailURL = URL(string: "message://")!
if UIApplication.shared.canOpenURL(mailURL) {
UIApplication.shared.openURL(mailURL)
}
Taken from: Launch Apple Mail App from within my own App?
The Swift 3.0.1 way of just opening the Mail app goes as follows:
private func openMailClient() {
let mailURL = URL(string: "message://")!
if UIApplication.shared.canOpenURL(mailURL) {
UIApplication.shared.openURL(mailURL)
}
}
As "dehlen" correctly stated, using the message:// scheme will only open the mail app, if no further information is provided.
Obviously a few years later...I had to add a completion handler for Xcode 10.2.1 swift 5.
This works perfectly-
let emailURL = NSURL(string: "message://")!
if UIApplication.shared.canOpenURL(emailURL as URL)
{
UIApplication.shared.open(emailURL as URL, options: [:],completionHandler: nil)
}
Since UIApplication.shared.openURL() method has been deprecated and we can use URL() directly in place of NSURL(), the updated version of this question's answer is:
let mailURL = URL(string: "message://")!
if UIApplication.shared.canOpenURL(mailURL) {
UIApplication.shared.open(mailURL, options: [:], completionHandler: nil)
}
This will work with Xcode 11.5:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.row {
case 5:
openEmailApp(email: "email#gmail.com")
default:
break
}
}
func openEmailApp(email: String) {
if let url = URL(string: "mailto: \(email)") {
UIApplication.shared.open(url)