If I use the following code
NSArray * activityItems = #[tempFileURL];
UIActivityViewController * activityViewController =
[[UIActivityViewController alloc] initWithActivityItems: activityItems
applicationActivities: nil];
[self.parentViewController presentViewController: activityViewController
animated: YES
completion: nil];
Then choose 'Save to Files', I am presented with the following dialog:
I would like to present this dialog without needing to first go though UIActivityViewController (and the 'save to files' option) first. I haven't been able to find an alternative way to do this. Any suggestions?
Specifically, my question boils down to this:
How can I have a user specify where a file should be saved without going though UIActivityViewController?
I had same issue. And I found a solution.
You can use UIDocumentPickerViewController for that purpose.
// in Your ViewController
let viewController = UIDocumentPickerViewController(urls: [tempFileURL], in: .exportToService)
present(viewController, animated: true)
You can get a screen like the following one.
You can see Apple documentation here.
Related
When I initialize the UIActivityViewController and disable all actions, I still see a More button under the actions bar. Is there a way to remove it?
This is how I initialize it:
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeAddToReadingList,UIActivityTypeCopyToPasteboard,UIActivityTypeSaveToCameraRoll,UIActivityTypePrint,UIActivityTypeAssignToContact,UIActivityTypeCopyToPasteboard]
No, this is the button where the user choose to enable app extensions, and you are not allowed to hide extension the user chose to display
I have a Share Sheet that shares an image and I want to get rid of the "Add to Contacts" option. How would I go about doing this?
Have a look at the excludedActivityTypes property of the UIActivityViewController. Pass in UIActivityTypeAssignToContact.
UIActivityViewController avc = ... // create the activity view
avc.excludedActivityTypes = #[ UIActivityTypeAssignToContact ];
// now present the activity view controller
What I need to do is present this half modal view with buttons before presenting the UIImagePicker Controller, as in the picture below:
I believe all the apps in the world dealing with UIImagePicker Controller have this 'pre-view' but I'm struggling with this for 2 days now and haven't yet find a way to accomplish this.
I've already googled a lot in this, but still don't know if this is a subview added to the main view, a modal view controller or some property of the UIImagePicker itself, as long as almost all the apps that i've searched have the exact same way of presenting it.
Any help would be very appreciated.
You need to use the UIActionSheet component.
Here is a sample :
UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(#"ADVICES_ADD_PICTURE", nil)
delegate:self
cancelButtonTitle:NSLocalizedString(#"CANCEL", nil)
destructiveButtonTitle:nil
otherButtonTitles:NSLocalizedString(#"WITHOUT_PICTURE", nil),NSLocalizedString(#"TAKE_PICTURE", nil), NSLocalizedString(#"CHOOSE_PICTURE", nil), nil];
[sheet showInView:self.view];
I am currently doing some updates for an iOS application. For the update I am going to take advantage of iOS6 capabilities. I am using a UIActivityViewController to get this done as well as some custom UIActivity activities. The main issue I am having is that there is no "Cancel" or "Close" button. The only way you can exit out of the activity view is if you either post something to a social network, or act like you are going to and then cancel.
NSArray* dataToShare = [[NSArray alloc] initWithObjects:#"blah", nil];
// Custom activities are allocated here
NSArray* customActivities = [[NSArray alloc] initWithObjects:activities, nil];
NSArray* excludedActivities = [[NSArray alloc] initWithObjects:exclusions, nil];
activityController = [[UIActivityViewController alloc] initWithActivityItems:formatArray applicationActivities:customActivities];
activityController.excludedActivityTypes = excludedActivities;
activityController.modalPresentationStyle = UIModalPresentationFormSheet;
[[UIApplication sharedApplication].keyWindow addSubview:self.view];
[[UIApplication sharedApplication].keyWindow bringSubviewToFront:activityController.view];
[self presentViewController:activityController animated:YES completion:^{ closureCode
}];
This does everything that I need inside of the activity controller in terms of networking content, I just don't have a close button. I don't know if it is the same issue but when the view disappears if I try to bring one up my "Share" menu again it tells me
<UIActivityViewController: 0x1e0db7d0> on <ShareDelegate: 0x1e048490> which is already presenting <UIActivityViewController: 0x21b1d4f0>
Thoughts? Thanks in advance!
*I am using:
iPad 2
Objective-C/C++
XCode 4.5
iOS6
From the docs for UIActivityViewController (emphasis is mine):
When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.
On the iPad, the popover will be cancelled by the user tapping outside of the popover.
On the iPhone/iPod touch, the modal view controller will be shown with a cancel button.
In short, don't use a form sheet on the iPad.
Is there something similar to NSPopover for iOS apps? It appears in the Object library for Mac but not for iPhone nor iPad, although I have downloaded apps using this (or at least some very similar) feature.
So my question: Is there a legit way to implement this?
UIPopoverController is what you're looking for.
There is UIPopOverController, but its use is restricted to iPads:
Popover controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.
(source)
For iPhone/iPod touch, you could use an external framework, like WEPopOver.
There is they are called UIPopovers,
Heres a tutorial: http://www.youtube.com/watch?v=1iykxemuxbk
For the sake of those Googling this, UIPopoverController is now available for both iPhone and iPad. You can make popovers that look the same on both (as of iOS 9, I believe).
Step 1: Include UIAdaptivePresentationControllerDelegate and UIPopoverPresentationControllerDelegate on your class definition
Step 2: Override the presentation somewhere in your class like this:
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
Step 3: When you present a view controller, you tell it to use popover style. Something like this:
//I pull my popover from a separate storyboard, but any modal view will do
let storyboard = UIStoryboard(name: "Popovers", bundle: nil)
let modal = storyboard.instantiateViewController(withIdentifier: "AnyPickerModal") as! AnyPickerVC
modal.modalPresentationStyle = UIModalPresentationStyle.popover
let pc = modal.popoverPresentationController
pc?.permittedArrowDirections = .any
pc?.sourceView = <your button or view you tap to show the popover>
pc?.sourceRect = <your button or view>.bounds
//How big the popover should be
modal.preferredContentSize = CGSize(width: 300, height: 180)
pc?.delegate = self
self.present(modal, animated: true, completion: nil)
Your presented modal will show up as a popover on both iPhone and iPad. Attached is a screenshot from my iPhone app.
Happy coding!