UIActivityViewController not showing Built-in activities - ios

I'm using a UIActivityViewController with just some of the Apple built-in services. As a test, I specify no excludedActivityTypes (the docs say this is nil by default) and no completion handler (I just want the services to do their thing).
I'm building using Xcode/SDK Version 5.1.1 (5B1008)
// this is the handler that catches the Action button tap
// self.noteArea.text is the UITextView.text string to use by the services.
- (IBAction)actionTapped:(UIBarButtonItem *)sender
{
NSString *s = [NSString stringWithString:self.noteArea.text];
NSArray *a = [NSArray arrayWithObject:s];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:a applicationActivities:nil];
[self.navigationController presentViewController:activityController animated:YES completion:NULL];
}
On both the simulator and a real iPhone the activity popup shows only Mail and Copy -- nothing else. Why just those two? Mail and Copy work fine, so everything that does show seems to work properly. How do I get the other functions to display?

Related

Gmail Extension crashes when sending images using UIActivityViewController

I use UIActivityViewController to share multiple images but when I choose a Gmail in the list, it opens it, then I see my attached files and then Gmail extension crashes. Next time it even doesn't open when I choose it.
But everything works fine with Mail app or other apps in the list in UIActivityViewController.
NSArray *scans = self.document.scans;
NSMutableArray *imagesData = [NSMutableArray arrayWithCapacity:[scans count]];
for (DScan *scan in scans) {
UIImage *image = [scan fullImageWithError:nil];
[imagesData addObject:UIImageJPEGRepresentation(image, 0.6)];
}
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:imagesData applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
Please help my understand what is wrong in the code.
Thank you in advance!

Can't share to linkedin using UIActivityViewController

I can't share anything via linkedin using UIActivityViewController. While I tap share via linkedin, it opens the sharing pop up and dismisses immediately after opened it. All other sharing are working fine. Could you please tell me a solution? Thanks.
Note: my project is in ios9 and xcode version is 7
and my error log shows : plugin com.linkedin.LinkedIn.ShareExtension interrupted
The iOS 8 extensions cannot be presented in a custom share screen. You absolutely have to use UIActivityViewController in order for the share/action extensions to appear.
Have you written the code like this
DataItemProvider *dataToShare = [[DataItemProvider alloc] initWithPlaceholderItem:FileTypeToShare];
LinkedInActivityType *linkedinActivity = [[LinkedInActivityType alloc] init];
NSArray *activityTypes = #[linkedinActivity];
NSArray *activityItems = #[dataToShare];
UIActivityViewController *activityController = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:activityTypes];
[activityController setCompletionHandler:^(NSString *activityType, BOOL completed) {
//Put in your completion handle code here.
}];
[self presentViewController:activityController animated:YES completion:nil];

Can't get a Share Button to work in my iOS App?

I can't get a Share button to work in my current app, I successfully had one in my previous app but I can't get it to work in my new app. I think this may be due to my first app having only a single ViewController whereas this app has multiple. I am trying to do this in a different view controller, not the default main one. Not sure what I'm doing wrong.
// MoreMenuViewController.h
#import <UIKit/UIKit.h>
#interface MoreMenuViewController : UIViewController
- (IBAction)tellFriend:(id)sender;
// MoreMenuViewController.m
#import "MoreMenuViewController.h"
#implementation MoreMenuViewController
- (IBAction)tellFriend:(id)sender
{
NSString *shareText = [NSString stringWithFormat:#"Check out Stories With Friends, a new word game for iPhone!"]; // Share message
NSArray *itemsToShare = #[shareText];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[];
[MoreMenuViewController:activityVC animated:YES completion:nil];
}
For the last line of code I get an error: No known class method for selector 'animated:completion:.'
Help would be much apperciated, thanks!
You need to call this method from self instead of MoreMenuViewController:
[self presentViewController:activityVC
animated:YES
completion:nil];
You also don't need to call this setter if you don't need to excluded types:
activityVC.excludedActivityTypes = #[];
UPDATE:
Despite now being able to click the button the app crashes: -[MoreMenuViewController tellAFriend:]
It's because the name of your method is tellFriend: and NOT tellAFriend: you must had renamed your method from the code without refactoring so the linked IBAction has no clue of the change. What you need to do is remove this link made from your Storyboard to your implementation file.
Click on your button then click on the cross where the action is linked to tellAFriend:
Try [self presentViewController:activityVC animated:YES completion:nil];
instead

How to send text (or URL) AND image with AirDrop at the same time

I am trying to share a text (or an URL) and an image with AirDrop and it seems it sends only the image. It works fine with other sharing activities (Facebook, Twitter, Mail, Message etc.). Is it possible to share two items with AirDrop?
Here is how I use the UIActivityViewController:
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[self.activityItem, self.attachedImage] applicationActivities:nil];
self.attachedImage is an UIImage and self.activityItem is a subclass of UIActivityItemProvider which returns different text for different activity types in delegate method
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
Does anyone have an idea? Thanks!
EDIT:
I also tried without subclassing UIActivityItemProvider and passed directly some text. Didn't work.
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"some text", self.attachedImage] applicationActivities:nil];
As a note, it works if I want to share multiple texts OR multiple images (UIImage):
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"text 1", #"text 2"] applicationActivities:nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[attachedImage1, attachedImage2] applicationActivities:nil];
Try this code
NSString *text= #"text to share";
CustomActivityItemProvider *textToShare = [[CustomActivityItemProvider alloc]
initWithStandardText:text];
NSArray *activityItems = #[textToShare,self.attachedImage];
Use activityItems array in activity view controller.
Posted the same question on Apple Dev Forums: https://devforums.apple.com/message/937697#937697
Got this answer:
Currently not possible. AirDrop only lets you send sets of single
items. If you are trying to send it to an instance of your own app on
the other side, you could instead create a fileformat (a
bundle/package would probably be suitable here) and embed all the
different types with the file. Then on the receiving side you can
extract the different types out of the file.

Certain UIActivityViewController services missing from my app

I have implemented UIActivityViewController within my app and can successfully share both strings and images. However, I notice that when you share an image within the iOS Photos app, there are some services that do not appear in my app. Namely Print, Use as Wallpaper, and Assign To Contact, and Photo Stream. My app is able to use Mail, Message, Facebook, Twitter, and Copy just fine.
I am thinking that either:
1.) These extra services have been implemented as custom services within the Photos app using UIActivityItemProvider, UIActivityItemSource, etc..
2.) The data that I am providing is not in the correct format to be used with these services.
I have read through the documentation a few times, but don't seem to see anything about it.
Edit: Showing code as requested:
#define SM_SHARE_IMAGE_AND_STRING 1
-(void)actionToolbarViewControllerUserTappedShareButton:(SMActionToolbarViewController*)sender{
// Reposition anchor view for UIPopoverController to point at
[self repositionAnchorViewToButtonFrame:self.actionToolbarViewController.shareButtonFrame];
// Asynch download of image
[SMUtility downloadAsset:self.selectedAsset completion:^(UIImage *image) {
// Create image source
SMActivitySource *activityImageSource = [[SMActivitySource alloc]initWithImage:image];
#if defined(SM_SHARE_IMAGE_AND_STRING)
// Create string source
NSString *assetsString = [SMUtility assetsString:[NSArray arrayWithObject:self.selectedAsset]];
SMActivitySource *activityStringSource = [[SMActivitySource alloc]initWithString:assetsString];
// Present UIActiviyViewController within an UIPopoverController
NSArray *items = [#[activityImageSource, activityStringSource]mutableCopy];
#else
NSArray *items = [#[activityImageSource]mutableCopy];
#endif
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];
[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed){
[SMMixPanel eventSharePhotoMethod:#"Share"];
}];
self.buttonPopoverController = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[self.buttonPopoverController presentPopoverFromRect:self.anchorView.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}];
}
The Print, and Assign To Contact activities are standard activities shown by the UIActivityViewController as long as you provide the proper data.
You must provide a UIImage for the Assign To Contact activity. See the docs for UIActivityTypeAssignToContact. See the docs for UIActivityTypePrint for details on what it accepts.
The "Use As Wallpaper" seems to be a custom activity shown only in the Photos app.

Resources