Is there a way to open the Apple Reminders app programmatically?
I have tried in Swift 5+ and iOS 13, you need to use the following url scheme.(Earlier x-apple-reminder:// was working but now it isn't)
x-apple-reminderkit://
if let url = URL(string: "x-apple-reminderkit://"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:]) { (isDone) in
}
}
It will open the iOS Reminder App from your application.
Hope it may be helpful to other.
Try This
let url = URL(string: "x-apple-reminder://")
UIApplication.shared.open(url!, options: [:]) { (finish) in
}
Reference for all apple apps scheme :
https://ios.gadgethacks.com/news/always-updated-list-ios-app-url-scheme-names-0184033/
and if you use x-apple-reminderkit://today, you can open the Today "view" in Reminders.
Still trying to figure out how to open a specific list or the Flagged view, though.
Related
In order to open instagram app with certain post I'm using following code:
func instaOpen(_ postId: String, _ postUrl: String){
let appURL = URL(string: "instagram://media?id=\(postId)")!
if UIApplication.shared.canOpenURL(appURL) {
UIApplication.shared.open(appURL, options: [:], completionHandler: nil)
} else {
// if Instagram app is not installed, open URL inside Safari
let webURL = URL(string: postUrl)!
let svc = SFSafariViewController(url: webURL)
present(svc, animated: true, completion: nil)
}
}
When instaOpen function called – instagram app opens, but login prompt forcefully pops over. Not matter what you do - close it or proceed with login, the queried post simply won't open(see gif).
This started happening recently, after I've updated my app and pushed deployment target to iOS12.
I do have instagram listed in my LSApplicationQueriesSchemes as well as I'm 100% positive that correct mediaID is being passed to instaOpen func (the code worked previously).
Let me know if there's any suggestions on how to fix this and actually open instagram post in instagram app.
Updated - Facebook developer fixed the issue.
Its instagram bug you can follow its progress from https://developers.facebook.com/support/bugs/290173615155052/?disable_redirect=0
Probably a bug, as that feature works on Android.
i manage to "fix" the problem on a pwa app using the Instagram web app.
let appURL = URL(string: "https://www.instagram.com/p/\(postId)")!
//https://www.instagram.com/p/insert here media id
I moved step by step for getting rich push notifications. Here they are :
Created Notification service extension with plist :
NotificationService didRecieve :
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: #escaping (UNNotificationContent) -> Void) {
func failEarly() {
contentHandler(request.content)
}
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
// Get the custom data from the notification payload
if let data = request.content.userInfo as? [String: AnyObject] {
// Grab the attachment
// let notificationData = data["data"] as? [String: String]
if let urlString = data["attachment-url"], let fileUrl = URL(string: urlString as! String) {
// Download the attachment
URLSession.shared.downloadTask(with: fileUrl) { (location, response, error) in
if let location = location {
// Move temporary file to remove .tmp extension
let tmpDirectory = NSTemporaryDirectory()
let tmpFile = "file://".appending(tmpDirectory).appending(fileUrl.lastPathComponent)
let tmpUrl = URL(string: tmpFile)!
try! FileManager.default.moveItem(at: location, to: tmpUrl)
// Add the attachment to the notification content
if let attachment = try? UNNotificationAttachment(identifier: "video", url: tmpUrl, options:nil) {
self.bestAttemptContent?.attachments = [attachment]
}else if let attachment = try? UNNotificationAttachment(identifier: "image", url: tmpUrl, options:nil) {
self.bestAttemptContent?.attachments = [attachment]
}else if let attachment = try? UNNotificationAttachment(identifier: "audio", url: tmpUrl, options:nil) {
self.bestAttemptContent?.attachments = [attachment]
}else if let attachment = try? UNNotificationAttachment(identifier: "image.gif", url: tmpUrl, options: nil) {
self.bestAttemptContent?.attachments = [attachment]
}
}
// Serve the notification content
self.contentHandler!(self.bestAttemptContent!)
}.resume()
}
}
}
Configured AppId and provision profile for extension.
Rich notification is coming correctly :
But here are the issues I am facing :
didRecieve is not getting called. For that I attached the serviceExtension process to the app target and ran the app.
Note : Extension is getting called as soon as notification arrives but didRecieve is not called :
On opening the push notification (which has video attachment), nothing happens. Ideally it should get played.
If I have to open the video and play it, do I have to explicitly do something or extension will take care of that ?
Payload :
aps = {
alert = "This is what your message will look like! Type in your message in the text area and get a preview right here";
badge = 1;
"mutable-content" = 1;
sound = default;
};
"attachment-url" = "https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4";
deeplinkurl = "";
"message_id" = 1609;
}
I did try going through following posts but that didn't help :
iOS10 UNNotificationServiceExtension not called
NotificationServiceExtension not called
UNNotificationServiceExtension not working on iPhone 5 (iOS 10)
Good news! Your service extension is indeed being called - the image on your notification is evidence of that. What is probably happening here is that you are unable to debug the extension using the workflow you are used to with applications.
Debugging notification extensions is not like debugging an app. Extensions are plug-ins to an iOS process outside your application. Just setting a breakpoint is not a reliable way to debug them. Instead:
Debugging A Notification Service Extension
Launch the app from Xcode or the device
In Xcode, select Attach To Process or PID By Name... from the Debug menu
Enter the name of your notification extension
Trigger a notification (by sending a push, etc.).
When the notification is delivered the service extension should launch in to the debugger. Service extensions are only relevant to remote (push) notifications, so you will need a device to troubleshoot them.
Debugging A Notification Content Extension
There are at least two ways. The steps shown above for a service extension also work for a content extension. The second method is more familiar but less reliable.
Select the extension scheme in Xcode using the toolbar
In the Product menu, select Edit Scheme...
Set the Executable to the parent application.
Set a breakpoint inside the content extension.
Now build and run your extension. It will launch the parent application.
Trigger a notification that will cause the content extension to load.
It's worth noting that adding logging using the logging framework can be very useful for debugging and troubleshooting as well.
Why The Video May Not Be Playing
iOS limits the size of content that can be presented in notifications. This is described in the documentation for UNNotificationAttachment. For video it is generally 50Mb. Make sure your video is as small as you can make it in terms of bytes, and of course provide a video that is sized appropriately for the device it will be played on. Do not try to play a 1080p video in a notification that is 400 points wide!
In practice it is almost always better to use HLS instead of downloading video, and present it in a content extension.
Another thing in your code that may be problematic is the identifiers you are assigning to your attachments. Identifiers should be unique. Typically this would be a reverse-domain notation string like your bundle ID followed by a UUID string. You could also use the original URL of the content followed by a UUID string. If you provide an empty string iOS will create a unique identifier for you.
With the user notifications framework having non-unique identifiers (for notifications, attachments, etc.) tends to cause difficult to track down issues inside the framework. For example, this can cause an attached watchOS device to crash.
If you want to implement "auto play" for your video - it is not clear from your question wether that is what you are describing - you will need to implement your own player functionality in a content extension.
If you are going to do that, again, HLS is the preferred way to display video in a notification. It usually uses less RAM, offers a better user experience and tends to be more stable.
did anyone successfully deep linked from his app to a directions to a place in moovit ? why can't i ?! it just opens the app and does nothing ....
if anyone successfully deep linked to a direction to anywhere please help.
if UIApplication.shared.canOpenURL(URL(string: "moovit://")!) {
// Moovit installed - launch app (with parameters)
let MoovitURL: String = "moovit://directions?dest_lat=40.758896&dest_lon=-73.985130&dest_name=TimesSquare&orig_lat=40.735845&orig_lon=-73.990512&orig_name=UnionSquare&auto_run=true&partner_id=<testApp2345>"
let escapedString = MoovitURL.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
UIApplication.shared.openURL(URL(string: escapedString!)!)
}else {
// Moovit not installed - send to store
UIApplication.shared.openURL(URL(string: "https://itunes.apple.com/us/app/id498477945")!)
}
}
even Moovit's own example isn't working for me....Whats wrong?
The problem is with the .urlHostAllowed parameter.
Using the .urlQueryAllowed parameter instead will only convert the parameters after '?'.
Fixed your code:
if UIApplication.shared.canOpenURL(URL(string: "moovit://")!) {
// Moovit installed - launch app (with parameters)
let MoovitURL: String = "moovit://directions?dest_lat=40.758896&dest_lon=-73.985130&dest_name=TimesSquare&orig_lat=40.735845&orig_lon=-73.990512&orig_name=UnionSquare&auto_run=true&partner_id=<testApp2345>"
let escapedString = MoovitURL.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
UIApplication.shared.open(URL(string: escapedString!)!, options: [:], completionHandler: nil)
}else {
// Moovit not installed - send to store
UIApplication.shared.open(URL(string: "https://itunes.apple.com/us/app/id498477945")!, options: [:], completionHandler: nil)
}
Try opening this url in Safari and see if it works (It does for me).
Looks like the problem is with the code, maybe try without addingPercentEncoding or use the new openURL API
I don't know how to check if app is installed or not on phone! Or when App is installed, open the app, otherwise open the Appstore link to download the app. I'm using swift 3. I want to do it using app name or bundle identifier.
Thank You!
func openApp(appName:String) {
let appName = "instagram"
let appScheme = "\(appName)://app"
let appUrl = URL(string: appScheme)
if UIApplication.shared.canOpenURL(appUrl! as URL) {
UIApplication.shared.open(appUrl!)
} else {
print("App not installed")
}
}
After looking into so many answers, i am writing a common code which will help for new users. If you have two mobile apps as App1 and App2, if you want to check in App2 that App1 is already installed in his device or not, here is code below.
In App1 add this property in info.plist file
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.companyName.App1</string>
<key>CFBundleURLSchemes</key>
<array>
<string>App1</string>
</array>
</dict>
</array>
In App2 add this property in info.plist file
<key>LSApplicationQueriesSchemes</key>
<array>
<string>App1</string>
</array>
In App2 write the method to check if app is installed or not on phone! Or when App is installed, open the app, otherwise open the Appstore link to download the app as below.
func checkAndOpenApp(){
let app = UIApplication.shared
let appScheme = "App1://app"
if app.canOpenURL(URL(string: appScheme)!) {
print("App is install and can be opened")
let url = URL(string:appScheme)!
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
} else {
print("App in not installed. Go to AppStore")
if let url = URL(string: "https://apps.apple.com/us/app/App1/id1445847940?ls=1"),
UIApplication.shared.canOpenURL(url)
{
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
}
}
I hope it will help some one.
Between the other answers and their comments, I'm getting the impression that the asker wants to be able to see if any given app is installed.
Beginning with iOS 9.0, that is not possible.
Apps for iOS 9 and later must have a list of requested URL schemes in the Info.plist before being allowed to use canOpenURL:. This is to protect user privacy, as advertisers were abusing this functionality in an arguably invasive fashion. (See this excellent post for more details on those changes.)
Of course, that list is static and cannot be changed after build time or submission to the App Store. If Apple doesn't like the ones you chose, they have every right to reject it.
I'm afraid that what you're asking isn't possible within reason for iOS 9.0 and later.
Edit: I also want to make clear that an app's URL scheme may not necessarily match nicely with its name. (This is more of an issue of a badly named constant than a functional issue.) There used to be a giant list of known URI schemes with documentation for each, but poignantly and fittingly enough, it seems that the wiki hosting it has shut down.
Swift 4.1. One developer can have more than one app on AppStore. So, I need to check if user has installed other apps or not by the same developer. I had Bundle ID's of other apps. Although you can use Appname instead of Bundle Id. So I followed the following steps.
In your current app add LSApplicationQueriesSchemes key of type Array in your info.plist file. Make entry of bundle id or Appname of app there which you want to open from your app.
Other app should have their bundle id or Appname entry in that app URL Scheme.
In your current app check if that app in installed in iPhone or not and can open accordingly.
let app = UIApplication.shared
let bundleID = "some.Bundle.Id://"
if app.canOpenURL(URL(string: bundleID)!) {
print("App is install and can be opened")
let url = URL(string:bundleID)!
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
} else {
print("App in not installed. Go to AppStore")
}
You can also test it from Safari browser. Just type the following in search bar
URL_scheme:// or Bundle_Id://
If app is installed the it will show alert with Appname to open it in app.
This worked for me (Swift 3.0)
Below two inputs should be provided:
<APP URL SCEHME>: The URL Scheme of the app which you want to open
<YOUR APP URL>: The App Itunes URL
func openApp() {
let appURL = NSURL(string: "<APP URL SCHEME>")
if UIApplication.shared.canOpenURL(appURL as! URL) {
print("Opening App...")
}else {
UIApplication.shared.openURL(NSURL(string: "<YOUR APP URL>")! as URL)
}
}
first go to info.plist, add LSApplicationQueriesSchemes add an item and place instagram on that item. Now this code will run perfectly.
let appName = "instagram"
let appScheme = "\(appName)://"
let appUrl = URL(string: appScheme)
if UIApplication.shared.canOpenURL(appUrl! as URL)
{
UIApplication.shared.open(appUrl!)
} else {
print("App not installed")
}
I know there are lot of topics about this problem but is there a solution? I have not found official documentation for that.
My problem is I need to redirect my code on storage settings like this : (work in iOS 9)
let settingsUrl = NSURL(string: "prefs:root=CASTLE&path=STORAGE_AND_BACKUP")
if let url = settingsUrl {
UIApplication.shared.openURL(url as URL)
}
But since ios10 this method don't work, so Is there an alternative? I saw SnapChat, Google Maps redirect their apps to different part on settings (not the main screen of settings) so I think there is a solution.
I already implement the url scheme in info.plist but it's still not work
I tried this method but same issue too
let settingsUrl = NSURL(string: "prefs:root=CASTLE&path=STORAGE_AND_BACKUP")
if let url = settingsUrl {
if #available(iOS 10.0, *) {
UIApplication.shared.open(URL.init(string:"Prefs:root=General&path=STORAGE_ICLOUD_USAGE/DEVICE_STORAGE")!, options: [UIApplicationOpenURLOptionUniversalLinksOnly:true], completionHandler:{(success: Bool?) -> Void in})
} else {
UIApplication.shared.openURL(url as URL)
}
}
Thank in advance.
Since iOS 10, it's not possible to open the Settings app from a third party app. The only settings that are allowed to be opened are Keyboard setting but only by a custom keyboard extension and your own application settings.
More details: here
Note: Even for iOS 9, using the URL string that is mentioned in the question can lead to app rejection as it violates iOS App Review Guidelines.