How to delete Siri Shortcut Intents from your iOS App? - swift

Using iOS13.6.1, Swift5.2.4, XCode11.6,
Following Apple's documentation, I try to delete a particular Siri Shortcut from my app.
The following code shows how I created the Siri Shortcut in the first place.
The Code further below shows my trial to delete the same Siri Shortcut again from my app.
Unfortunately, the Siri Shortcut is not deleted from my App.
Any idea how I can delete it for good ?
extension EditMediaViewController {
#available(iOS 12.0, *)
func createSiriButton(documentID: String, invitationCode: String) -> INUIAddVoiceShortcutButton {
let siriShortcutButton = INUIAddVoiceShortcutButton(style: .whiteOutline)
let activity = NSUserActivity(activityType: "MyIdentifierStringCodeABCDEF")
activity.title = "Test"
activity.suggestedInvocationPhrase = "Test"
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
activity.persistentIdentifier = NSUserActivityPersistentIdentifier("MyIdentifierStringCodeABCDEF")
activity.becomeCurrent()
siriShortcutButton.shortcut = INShortcut(userActivity: activity)
return siriShortcutButton
}
}
extension EditMediaViewController: INUIAddVoiceShortcutButtonDelegate {
#available(iOS 12.0, *)
func present(_ addVoiceShortcutViewController: INUIAddVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton) {
addVoiceShortcutViewController.delegate = self
addVoiceShortcutViewController.modalPresentationStyle = .formSheet
present(addVoiceShortcutViewController, animated: true, completion: nil)
}
#available(iOS 12.0, *)
func present(_ editVoiceShortcutViewController: INUIEditVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton) {
editVoiceShortcutViewController.delegate = self
editVoiceShortcutViewController.modalPresentationStyle = .formSheet
present(editVoiceShortcutViewController, animated: true, completion: nil)
}
}
extension EditMediaViewController: INUIAddVoiceShortcutViewControllerDelegate {
#available(iOS 12.0, *)
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
#available(iOS 12.0, *)
func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
controller.dismiss(animated: true, completion: nil)
}
}
extension EditMediaViewController: INUIEditVoiceShortcutViewControllerDelegate {
#available(iOS 12.0, *)
func editVoiceShortcutViewController(_ controller: INUIEditVoiceShortcutViewController, didUpdate voiceShortcut: INVoiceShortcut?, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
#available(iOS 12.0, *)
func editVoiceShortcutViewController(_ controller: INUIEditVoiceShortcutViewController, didDeleteVoiceShortcutWithIdentifier deletedVoiceShortcutIdentifier: UUID) {
controller.dismiss(animated: true, completion: nil)
}
#available(iOS 12.0, *)
func editVoiceShortcutViewControllerDidCancel(_ controller: INUIEditVoiceShortcutViewController) {
controller.dismiss(animated: true, completion: nil)
}
}
Here my trial to delete the same Siri Shortcut (but it does not work - why?):
let activity = NSUserActivity(activityType: "MyIdentifierStringCodeABCDEF")
let activityPersistentIdentifier = NSUserActivityPersistentIdentifier("MyIdentifierStringCodeABCDEF")
NSUserActivity.deleteSavedUserActivities(withPersistentIdentifiers: [activityPersistentIdentifier]) {
print("one deleted")
}
INInteraction.deleteAll { (error) in
print("all deleted")
}
INInteraction.delete(with: [activityPersistentIdentifier]) { (error) in
print(error)
}

Related

Siri Intent Suggested Invocation Phrase not displaying in ShortcutViewController

I'm trying to enable a simple Siri Intent for my iOS app, with a TableView cell functioning to invoke INUIAddVoiceShortcutViewController, with the TableView as its delegate. However, the suggested invocation phrase that is supposed to display on the controller view, does not.
I'm extremely new to Swift, and so I haven't tried much else as I do not know what to try
The invoking function is:
getSiriView() {
intent.suggestedInvocationPhrase = "Get a joke"
let siriView = INUIAddVoiceShortcutViewController(shortcut: INShortcut(intent: intent)!)
siriView.delegate = self;
self.present(siriView, animated: true, completion: nil)
}
and its delegate extensions are as follows:
//
// ViewControllerSiriExtensions.swift
// Helium
//
// Created by Richard Robinson on 2019-04-26.
// Copyright © 2019 Richard Robinson. All rights reserved.
//
import Foundation
import IntentsUI
extension TableViewController: INUIAddVoiceShortcutButtonDelegate {
func present(_ addVoiceShortcutViewController: INUIAddVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton) {
addVoiceShortcutViewController.delegate = self
addVoiceShortcutViewController.modalPresentationStyle = .formSheet
present(addVoiceShortcutViewController, animated: true, completion: nil)
}
func present(_ editVoiceShortcutViewController: INUIEditVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton) {
editVoiceShortcutViewController.delegate = self
editVoiceShortcutViewController.modalPresentationStyle = .formSheet
present(editVoiceShortcutViewController, animated: true, completion: nil)
}
}
extension TableViewController: INUIAddVoiceShortcutViewControllerDelegate {
public func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
public func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
controller.dismiss(animated: true, completion: nil)
}
}
extension TableViewController: INUIEditVoiceShortcutViewControllerDelegate {
public func editVoiceShortcutViewController(_ controller: INUIEditVoiceShortcutViewController, didUpdate voiceShortcut: INVoiceShortcut?, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
public func editVoiceShortcutViewController(_ controller: INUIEditVoiceShortcutViewController, didDeleteVoiceShortcutWithIdentifier deletedVoiceShortcutIdentifier: UUID) {
controller.dismiss(animated: true, completion: nil)
}
public func editVoiceShortcutViewControllerDidCancel(_ controller: INUIEditVoiceShortcutViewController) {
controller.dismiss(animated: true, completion: nil)
}
}
extension TableViewController {
public var intent: JokeIntent {
return JokeIntent()
}
}
Currently, the controller appears and works properly, except it does not display the suggested phrase.

icloud drive doesn't appear using UIDocumentPickerViewController

In my app I want import .sqlite from iCloud to restore data, but it's not showing iCloud drive everything is managed, iCloud entitlements are already on and from developer account its enable
ICloud entitlements
In my app, I have integrated this code
#IBAction func btnImport(_ sender: Any) {
//let importMenu = UIDocumentPickerViewController(documentTypes: [String(kUTTypePDF)], in: .import)
let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePNG),String(kUTTypeImage)], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .fullScreen
self.present(importMenu, animated: true, completion: nil)
}
extension MoreViewController : UIDocumentMenuDelegate, UIDocumentPickerDelegate {
func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentPicker.delegate = self
self.present(documentPicker, animated: true, completion: nil)
}
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
print("url = \(url)")
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
dismiss(animated: true, completion: nil)
}
}
but it shows me only this
OUTPUT

Setting DarkTheme has no effect Braintree iOS v4 SDK

The documentation clearly says it can be done, easy breezy:
https://developers.braintreepayments.com/guides/drop-in/customization/ios/v4#themes
I can indeed customize the primaryTextColor to red.
Here is a screenshot, that demonstrates that red works but not darkTheme:
And is here is my code in my UIViewController:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
showDropIn(clientTokenOrTokenizationKey: clientToken)
}
func showDropIn(clientTokenOrTokenizationKey: String) {
BTUIKAppearance.darkTheme()
BTUIKAppearance.sharedInstance().primaryTextColor = UIColor.red
let request = BTDropInRequest()
request.vaultManager = true
let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
{ (controller, result, error) in
if (error != nil) {
print("ERROR")
} else if (result?.isCancelled == true) {
print("CANCELLED")
} else if let result = result {
// Use the BTDropInResult properties to update your UI
// result.paymentOptionType
// result.paymentMethod
// result.paymentIcon
// result.paymentDescription
}
controller.dismiss(animated: true, completion: nil)
}
self.present(dropIn!, animated: true, completion: nil)
}
So Braintree's documentation on Theme's is a bit poorly choose wording IMO.
The instruction is what is misleading to me: "To use the Dark theme instead, call this method before initializing Drop-in". Yet you have to initialize or instantiate the drop-in before setting darkTheme.
The instruction might better read: "To use the Dark theme instead, call this method before presenting the Drop-in"
Here is my working code:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
showDropIn(clientTokenOrTokenizationKey: clientToken)
}
func showDropIn(clientTokenOrTokenizationKey: String) {
let request = BTDropInRequest()
request.vaultManager = true
dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
{ (controller, result, error) in
if (error != nil) {
print("ERROR")
} else if (result?.isCancelled == true) {
print("CANCELLED")
} else if let result = result {
// Use the BTDropInResult properties to update your UI
// result.paymentOptionType
// result.paymentMethod
// result.paymentIcon
// result.paymentDescription
}
controller.dismiss(animated: true, completion: nil)
}
BTUIKAppearance.darkTheme()
BTUIKAppearance.sharedInstance()?.primaryTextColor = UIColor.lightGray
self.present(dropIn!, animated: true, completion: nil)
}

Document picker in Swift

I'm trying to open document picker view controller on a click of a button, but there are no option shown in it. Only more option is shown as u can see in the screen shot. I want to show options of iCloud, google drive, dropbox etc. I just want to get any document, image or pdf file from the cloud storages and want to show it in my application. I have tried this code,
#available(iOS 8.0, *)
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
let cico = url as URL
print("The Url is : \(cico)")
//optional, case PDF -> render
//displayPDFweb.loadRequest(NSURLRequest(url: cico) as URLRequest)
}
#available(iOS 8.0, *)
public func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print("we cancelled")
dismiss(animated: true, completion: nil)
}
#IBAction func docsBtnTapped(_ sender: Any) {
let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePDF)], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .formSheet
self.present(importMenu, animated: true, completion: nil)
}
It is only this in picker controller,
But i want to show option in this controller and when click it should take us to that cloud storage. I have also enable the iCloud option from capabilites of my application.

Can't close mail view controller when clicking Cancel, Save Draft or Delete Draft

I'm implementing a mail controller in my app but I can't figure out why it won't close when clicking save draft or delete draft. The window gets stuck on the email screen and I can't click "Cancel" a second time either.
#IBAction func emailButtonTapped(_ sender: UIButton) {
guard MFMailComposeViewController.canSendMail() else {
if !MFMailComposeViewController.canSendMail() {
print("Can not send email")
return
}
return
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
dismiss(animated: true, completion: nil)
}
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
mailComposer.setToRecipients(["example#example.com"])
mailComposer.setSubject("Look at this")
mailComposer.setMessageBody("Hello, this is an email from the app I made.", isHTML: false)
present(mailComposer, animated: true, completion: nil)
}
I successfully fixed the issue, and it was a pretty stupid one!
Some code was outside the emailButtonTapped func:
#IBAction func emailButtonTapped(_ sender: UIButton) {
//guard MFMailComposeViewController.canSendMail() else {
if !MFMailComposeViewController.canSendMail() {
print("Can not send email")
return
}
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
mailComposer.setToRecipients(["example#example.com"])
mailComposer.setSubject("Look at this")
mailComposer.setMessageBody("Hello, this is an email from the app I made.", isHTML: false)
present(mailComposer, animated: true, completion: nil)
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
dismiss(animated: true, completion: nil)
}
Swift 4
// MARK: - SEND EMAIL BUTTON
#IBAction func SendEmailButt(_ sender: AnyObject) {
// This string containes standard HTML tags, you can edit them as you wish
let messageStr = "Hello,"
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
mailComposer.setSubject("Title")
mailComposer.setMessageBody(messageStr, isHTML: true)
if MFMailComposeViewController.canSendMail() { present(mailComposer, animated: true, completion: nil)
} else {
print("Your device cannot send emails. Please configure an email address into Settings -> Mail, Contacts, Calendars.")
}
}
// Email delegate
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
var resultMess = ""
switch result.rawValue {
case MFMailComposeResult.cancelled.rawValue:
resultMess = "Mail cancelled"
case MFMailComposeResult.saved.rawValue:
resultMess = "Mail saved"
case MFMailComposeResult.sent.rawValue:
resultMess = "Thanks for contacting us!\nWe'll get back to you asap."
case MFMailComposeResult.failed.rawValue:
resultMess = "Something went wrong with sending Mail, try again later."
default:break
}
// Show email result alert
print(resultMess)
dismiss(animated: true, completion: nil)
}
Can you try this once instead:
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Dismiss the mail compose view controller.
controller.dismissViewControllerAnimated(true, completion: nil)
}
Check the following Code.
#IBAction func sendEmailButtonTapped(sender: AnyObject) {
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.presentViewController(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients([])
mailComposerVC.setSubject("Sending In-App Email")
mailComposerVC.setMessageBody("Sending Email through your app in Swift", isHTML: false)
return mailComposerVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send Email. Please check Email configuration and try again.", delegate: self, cancelButtonTitle: "OK")
sendMailErrorAlert.show()
}
// MFMailComposeViewControllerDelegate Method
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
controller.dismissViewControllerAnimated(true, completion: nil)
}