UIActivityViewController Hide More from Actions - ios

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

Related

inputAccessoryView animating down when alertController (actionSheet) presented

I have an inputAccessoryView for a chat app that always remains visible and docked at the bottom of the screen for text input similar to most messaging apps.
When I present an alertController with actionSheet style, the inputAccessoryView animates down off screen as the alert is presented and then back up again when the alert is dismissed. This in turn scrolls my tableView and is undesirable.
This is happening because the chat viewController is giving up firstResponder when the alert is presented.
Is there anyway to present an alertController and not give up firstResponder, or anyway to keep an inputAccessoryView docked at the bottom of the screen when it's view resignsFirstResponder?
The InputAccessoryView sits outside of your ViewController's hierarchy - it's contained in the UITextEffectsWindow whose rootViewController is a UIInputWindowController. Similarly the keyboard is contained in UIRemoteKeyboardWindow and its own UIInputWindowController.
So, if we present the alert from the topmost window or higher (UITextEffectsWindow or UIRemoteKeyboardWindow), it won't resign first responder.
The simplest solution I've found is:
let topViewController = UIApplication.shared.windows.last!.rootViewController!
topViewController.present(alert, animated: true, completion: nil)
Ideally you would safely handle those optionals. A potentially better solution (I've seen some console errors from the previous solution) would be to create a new UIWindow with a higher WindowLevel, make it the key window and visible, and present the alert from there.
Thanks to #Corey W. (give votes to him) we have a solution for this issue. Safer way in Swift 5:
// Instantiate AlertController
let actionSheet = UIAlertController(title: title,
message: "Comment options",
preferredStyle: .actionSheet)
// Add actions
actionSheet.addAction(UIAlertAction(title: "Edit",
style: .default,
handler: { (_: UIAlertAction) in
self.showEditingView(withCommentId: commentId, withCommentText: commentText)
}))
// Present AlertController
if let lastApplicationWindow = UIApplication.shared.windows.last,
let rootViewController = lastApplicationWindow.rootViewController {
rootViewController.present(actionSheet, animated: true, completion: nil)
}
For those looking the Objective-C equivalent of Corey's answer:
UIViewController *objViewController = [UIApplication sharedApplication].windows.lastObject.rootViewController;
[objViewController presentViewController:view animated:YES completion:nil];

Prompt use to save to iCloud WITHOUT using UIActivityViewController

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.

Facebook UIActivityViewController is Missing the Cancel and Post Buttons

When my app opens the Facebook UIActivityViewController, there is no navigation bar at the top of the Facebook screen and there is no Cancel or Post button - the only way to exit the screen is to kill the app. Other apps that I look at have an additional navigation bar at the top of the Facebook screen, which holds the Cancel and Post buttons.
Here is the code I am using:
NSURL *url = [NSURL URLWithString:#"http://www.mywebsite.com"];
NSArray *activityItems = #[url];
// Put together the UIActivityViewController
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:activityItems
applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAirDrop,
UIActivityTypePostToVimeo,
UIActivityTypePostToFlickr,
UIActivityTypeAddToReadingList];
// Present the UIActivityViewController
[self presentViewController:activityVC
animated:YES
completion:nil];
The Twitter, Email, and SMS screens all appear as expected. Facebook is the only one that is having problems.
Some other notes: I notice that when I open the Facebook Share on this app, the status bar turn black with white text. On another test app that I created, the status bar looks grayed-out with black text. Not sure why / what this points to, but might be a clue.
This problem seems to be app-wide, as I have 3 spots where sharing can be invoked, and it is happening in all 3 instances.
Attaching an image. There should be a Navigation bar above the "To: Public" toolbar.
Any ideas would be appreciated.
You can hide the navigation bar as per your requirement.
So, add the below code, if you want to show the navigation when UIActivityViewController is present and then hide it when UIActivityViewController is dismissed:-
//this will be called when the UIActivityViewController will be dismissed, so we are hiding the navigation
[activityVC setCompletionHandler:^(NSString *activityType, BOOL completed) {
[[UINavigationBar appearance] setHidden:YES];
}];
//this will be called when the UIActivityViewController will be shown, so we are enabling the navigation mean unhiding it.
[self presentViewController:activityVC animated:YES completion:^{
[[UINavigationBar appearance] setHidden:NO]
//you can also add code to customize status bar
}];
I have created new app and copy pasted your code on button action. It is workiing perfectly. You can check image of it over here: https://drive.google.com/file/d/0B0FNcjA1N299NWdmZGZQWC1KbzA/view?usp=sharing
As per my knowledge, If you have done something with [UINavigationBar appearance] in your app, then and then only it makes the problem. Please check that.

How to dismiss a popover only with a button in swift

My iPad app has several data gathering popovers, and I want to be able to disable the dismissal of the popover by touching outside of it, I then will use a button to quit the popover at the users discretion.
The app looks great, the popovers work fine, and I have a button inside them that quits nicely. Only I can't find a way of disabling dismissal in Swift, lots of posts on obj-c but nothing in Swift.
Does this mean that the functionality is no longer available?
I would greatly appreciate any help to my frustration.
Simply set the view controller's modalInPopover to true and the popover's passthroughViews to nil. But you must do the latter using delayed performance or it won't work. A small delay is all that's needed. Example:
let vc = UIViewController()
vc.modalPresentationStyle = .Popover
self.presentViewController(vc, animated: true, completion: nil)
if let pop = vc.popoverPresentationController {
vc.modalInPopover = true
delay(0.1) {
pop.passthroughViews = nil
}
}
For the delay function, see dispatch_after - GCD in swift?.

Remove the "Assign to contact" option in the iOS Share Sheet

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

Resources