I've a problem with the UIActivityController on iOS 8 iPad: the activity view works correctly I can select a share service (i.e. Twitter) but when the "publish" view appear I can only click on the Post button,the Cancel button doesn't work. I've the same problem on real devices and on the simulator.
If you have an idea about how to fix this problem,...
Thanks
Here's my code:
- (IBAction)activityController:(id)sender {
// items to share
NSURL *url = [NSURL URLWithString:_articleUrl];
NSArray *items=#[url];
// create the controller
UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
UIPopoverPresentationController *popPC = controller.popoverPresentationController;
popPC.barButtonItem = _buttn;
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
Related
I am using this code in my app to share a URL to other apps using share extension.
NSArray *activityItems = #[adURL];
UIActivityViewController *activityViewControntroller = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewControntroller.excludedActivityTypes = #[];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
activityViewControntroller.popoverPresentationController.sourceView = self.view;
activityViewControntroller.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/4, 0, 0);
}
[self presentViewController:activityViewControntroller animated:true completion:nil];
When WhatsApp is selected I get a view like this:
Is there any way I can change the color of the right 'Send' button in the navigation bar?
You can set this property on the modal before opening, something like the following
modal.navigationController.navigationBar.barTintColor = ...
This will change the navigationBar color, you can select your app color there,, this will make send button prominent automatically.
I am new to ios and I have a problem on displaying UIActivityViewController. I have done the code and it works fine on ios8&9 iPad, but when I tested on ios10 iPad 5th and the UIActivityViewController frame was restricted by its parent view controller.
Problem need to be fixed:
The desired layout:
UIActivityViewController *vc = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
vc.excludedActivityTypes = #[UIActivityTypeMessage];
vc.popoverPresentationController.barButtonItem = self.shareButton;
vc.popoverPresentationController.permittedArrowDirections =
UIPopoverArrowDirectionAny;
vc.popoverPresentationController.delegate = self;
vc.modalPresentationStyle = UIModalPresentationPopover;
Can anyone give me some hints on that? Thanks in advance.
I'm currently implementing an iOS app using objective-C, which has a function that users may share a file with other friend or other app (like upload the file to Dropbox, Google Drive, attach the file to Mail, share the file to Facebook Messenger, Whatsapp, via Bluetooth, etc).
Is there a native way to implement this share function that can detect all apps which allows sharing a file, while I don't need to do it one by one?
You want to use UIActivityViewController. Below is an example from NSHipster, which is probably the most comprehensive article I've seen on the subject. And Apple has some good documentation here.
NSString *string = ...;
NSURL *URL = ...;
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[string, URL]
applicationActivities:nil];
[navigationController presentViewController:activityViewController
animated:YES
completion:^{
// ...
}];
This provide full answer for iPhone and iPad devices
ViewController *contentViewController = [[ViewController alloc] init];
// Present the view controller using the popover style.
contentViewController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:contentViewController
animated:YES
completion:nil];
// Get the popover presentation controller and configure it.
UIPopoverPresentationController *presentationController =[contentViewController popoverPresentationController];
presentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
presentationController.sourceView = self.view;
presentationController.sourceRect = self.view.frame;
UIPopoverPresentationController should have a non-nil sourceView or barButtonItem set before the presentation occurs on iOS 9
I'm trying to use UIActivityController in my app. Unfortunately the size of the modal is far too large.
On the left, the modal I want, on the right, the modal I have :
And here is the code I use to display the modal when I click on the Share button :
NSString *textToShare = #"Hello !";
NSURL *myWebsite = [NSURL URLWithString:#"http://stackoverflow.com/"];
NSArray *objectsToShare = #[textToShare, myWebsite];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
// Email subject
[activityVC setValue:#"Hello !" forKey:#"subject"];
[self presentViewController:activityVC animated:YES completion:nil];
What am I doing wrong ?
Thanks in advance.
You're doing nothing wrong, you're just using a differently sized device! Try running in the simulator using iPhone 6 or iPhone 6S and I bet you'll see exactly what you want on the left. Looks like you're just running it on a smaller device than what you want.
I have this wired problem with UIActivityViewController on iPad when dismissing it.
What I have is a MainViewController from which I present a view controller like so (modal view):
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
[self presentViewController:self.readerViewController animated:YES completion:nil];
In the ReaderViewController's toolbar I have a UIButton to show UIActivityViewController for PDF sharing.
This is how I present the UIActivityViewController:
_activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[document.fileURL] applicationActivities:nil];
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:_activityViewController];
[popup presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
When UIActivityViewController is presented it works as expected. It will dismiss if I press anywhere on the screen, also as expected. The problem is if I double tap somewhere on the screen, both the UIActivityViewController and ReaderViewController will be dismissed at the same time.
Now, I want only UIActivityViewController to be dismissed not ReaderViewController.
Any solution for this ?
/Cheers
There is a way, declare UIPopoverController *popup as a global variable or property.