icloud drive doesn't appear using UIDocumentPickerViewController - swift

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

Related

How to delete Siri Shortcut Intents from your iOS App?

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)
}

how to autocapture an image from camera by using UIImagePickerController in swift

I am trying to capture a picture automatically from camera without clicking the camera capture-button and i am using the UIImagePickerController for camera usage.what should I have to add for autocapture?
class ViewController:UIViewController,UINavigationControllerDelegate,UIImagePickerControllerDelegate
{
var imagePicker = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
self.openCamera()
}
func openCamera() {
if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerController.SourceType.camera)) {
imagePicker.sourceType = UIImagePickerController.SourceType.camera
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
} else {
let alert = UIAlertController(title: "Warning", message: "You don't have camera", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]){
self.imagePicker.dismiss(animated: true, completion: nil)
guard let selectedImage = info[.originalImage] as? UIImage
else{
print("Image not found!")
return
}
}
Here I am clicking the capture button. But I want to take automatically a picture after autofocusing.
It is possible using UIImagePickerController as I R&D on this functionality.
If you want to autocapture an image from camera then you can use this below mentioned code.
1. First you need to Add AVFoundation framework in your project.
Select project -> Add AVFoundation framework in Frameworks, Libraries, and Embedded Content Section
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIGestureRecognizerDelegate {
let objCaptureSession = AVCaptureSession()
var objPreviewLayer : AVCaptureVideoPreviewLayer?
var objCaptureDevice : AVCaptureDevice?
var objImagePicker = UIImagePickerController()
var objTimer: Timer?
var flagRepeatRecording: Bool = false
var objOutputVolumeObserve: NSKeyValueObservation?
let objAudioSession = AVAudioSession.sharedInstance()
override func viewDidAppear(_ animated: Bool) {
if !flagRepeatRecording {
if UIImagePickerController.isSourceTypeAvailable(.camera) {
objImagePicker = UIImagePickerController()
objImagePicker.delegate = self
objImagePicker.sourceType = .camera
objImagePicker.allowsEditing = false
objImagePicker.showsCameraControls = false
//imagePicker.mediaTypes = [kUTTypeMovie as String] // If you want to start auto recording video by camera
} else {
debugPrint("Simulator has no camera")
}
self.present(self.objImagePicker, animated: true, completion: {
self.objImagePicker.takePicture() // If you want you auto start video capturing then replace this code with take picture() method startVideoCapture()
NotificationCenter.default.addObserver(self, selector: #selector(self.cameraIsReady), name: .AVCaptureSessionDidStartRunning, object: nil)
flagRepeatRecording = true
}
}
#objc func cameraIsReady(notification: NSNotification) {
DispatchQueue.main.async {
self.objImagePicker.takePicture()
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
// let tempImage = info[UIImagePickerController.InfoKey.mediaURL] as! NSURL?
// let pathString = tempImage?.relativePath
self.dismiss(animated: true, completion: {})
// UISaveVideoAtPathToSavedPhotosAlbum(pathString!, self, nil, nil)
self.objTimer?.invalidate()
self.objTimer = nil
}
}

Can someone please tell me why my apps crashes when I press the cam button

I had a class that i chose to remove and after that my add keeps crashing.
Below is what is in the button
#IBAction func cameraButton_TouchUpInside(_ sender: Any) {
let imagePickerController = ImagePickerController()
imagePickerController.delegate = self
imagePickerController.imageLimit = 1
present(imagePickerController, animated: true, completion: nil)
}
func wrapperDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {
}
func doneButtonDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {
guard let image = images.first else {
dismiss(animated: true, completion: nil)
return
}
if let image = info["UIImagePickerControllerOriginalImage"] as? UIImage{
selectedImage = image
photo.image = image
dismiss(animated: true, completion: nil)
// dismiss(animated: true, completion: {
// self.performSegue(withIdentifier: "Camera", sender: nil)
// })
}
if I uncomment the what is above my app crashes when i try to choose from the library
more
// override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// if segue.identifier == "filter_segue" {
// let filterVC = segue.destination as! FilterViewController
// filterVC.selectedImage = self.selectedImage
// filterVC.delegate = self
// }
// }
//extension CameraViewController: FilterViewControllerDelegate {
// func updatePhoto(image: UIImage) {
// self.photo.image = image
// self.selectedImage = image
// }
//}
crashes could be simply because of these:
not having required permission added to the info.plist ( in this case you will get message in the log that permission is missing in .plist file.
object are not connected to the correct IBOutlet ( in this case the circle beside the IBOutlet in files would be empty which means its not connected to any object.)
for your case permission is missing in your info.plist. you should add NSCameraUsageDescription and the value is a string which will be shown on permission dialog when asks user the permission to open camera . it will be like this:

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.

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.