UIActivityViewController Style in iOS10 - ios

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.

Related

Popover crashing on iPad (SpriteKit game)

Recently I discovered that it’s necessary to use Popover to display the ActivityViewController on iPad. I found this website as a main reference:
http://pinkstone.co.uk/how-to-share-things-with-a-uiactivityviewcontroller/
It’s perfectly explained, but I can’t make it work from my SpriteKit game. I double-checked with other examples and all seems to be in its place... but this crash on iPad anyways, without any meaningful message (on iPhone it works). I have no idea on what’s wrong. If somebody experienced the same, any clue will be very welcome!
UIActivityViewController *activityController = [[UIActivityViewController alloc]initWithActivityItems:#[twitterText] applicationActivities:nil];
UIViewController* viewController = self.view.window.rootViewController;
activityController.modalPresentationStyle = UIModalPresentationPopover;
[viewController presentViewController:activityController animated:YES completion:nil];
UIPopoverPresentationController *popController = [activityController popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionDown;
popController.sourceRect = CGRectMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame),200,200);
The solution was adding
popController.sourceView = self.view;
before the sourceRect. Thanks and kudos to Warren Burton.

UIActivityViewController view frame is cut in ios 9.0

I encounter this bug when using UIActivityViewController in order to create a simple UI for sharing assets in my app. This works well on ios 10 and above, but in ios 9 this annoy issue appears. I've already researched for solutions but didn't find any help. Could you guys please take a look?
My code is just simple as below:
NSString *url=#"http://itunes.apple.com/us/app/APPNAME/idXXXXXXXXX";
NSString * title =[NSString stringWithFormat:#"Download ECG app %# and get free reward points!",url];
NSArray* dataToShare = #[title];
UIActivityViewController* activityViewController =[[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypeAirDrop];
[self presentViewController:activityViewController animated:YES completion:^{}];
In ios 9, it looks like THIS
Please try to update animated:NO when you present the Activity View, if the view displayed correctly with animated:NO then self.view.translatesAutoresizingMaskIntoConstraints = NO; should be the cause of this problem.

iOS app Sharing through whatsApp

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.

iOS native way to share files to any possible apps

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

UIActivityController Cancel button doesn't work on iPad

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;

Resources