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)
}
Related
I can make a phone call with this code:
if let url = URL(string: "telprompt://\(number)"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
Now I want to make a phone call with hidden phone number, so I would add #31# but then url is not, and the canOpenURL function is not even called.
if let url = URL(string: "telprompt://#31#\(number)"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
tel:// scheme responds the same, and I don't want to go in the system settings and change it there, as it would hide my number on every call I make.
Any idea?
Xcode 11.5 - macOS Catalina - Swift 5
Have you tried url-encoding the # ?
"telprompt://%2331%23\(number)"
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)
}
}
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 created a button to make a call from app:
#IBAction func callButton(sender: AnyObject) {
if (PhoneNumber != ""){
UIApplication.sharedApplication().openURL(NSURL(string: "telprompt://\(PhoneNumber)")!)
}
}
and it works perfectly fine. Strange thing happens when I want to open a web page. I use nearly exactly same code
#IBAction func openWeb(sender: AnyObject) {
UIApplication.sharedApplication().openURL(NSURL(string: "www.google.com")!)
}
But this time button doesn't react and nothing happens. Wherever I was looking for some information about opening web pages in safari from the app, the code was written exactly this way. Do you have any idea where the problem is?
Thanks in advance!
missing url scheme
UIApplication.shared.open(URL(string: "http://www.google.com")!, options: [:], completionHandler: nil)
Swift 4, safely unwrapped optional, check if canOpenURL
if let url = URL(string: "https://www.google.com"),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:])
}
Swift 3 Version
UIApplication.shared.openURL(NSURL(string: "http://google.com")! as URL)
Updated Swift 3.0 version as of iOS 10
let googleURL = NSURL(string: "www.google.com")! as URL
UIApplication.shared.open(googleURL, options: [:], completionHandler: nil)
Swift 4.2.1, iOS 10 and higher
UIApplication.shared.open(URL(string: "https://google.com")!, options: [:], completionHandler: nil)