Email option is not available while sharing video using UIActivityViewController - ios

Hi I am trying to share video using UIActivityViewController but it is not showing Email option. It is showing Facebook and Message option. But in native Photos app it is showing Email share option on same video. So please could anyone tell me why it is not showing Email option in my App. Here is my code:
NSURL* url=[NSURL URLWithString:#"asset url here"];
[self shareItems:[NSMutableArray arrayWithObjects:url,nil]];
- (IBAction)shareItems:(NSMutableArray*)shareItems {
UIActivityViewController *shareController =
[[UIActivityViewController alloc]
// actual items are prepared by UIActivityItemSource protocol methods below
initWithActivityItems: shareItems
applicationActivities :nil];
[self presentViewController: shareController animated: YES completion: nil];
}
The same code is working fine (Shows Email option) if Asset Url is of an image. Problem is in case of Video. I have tried on iPhone5 with iOS7.

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];

Facebook is not shown in UIActivityViewController but twitter does

My iOS is 8.1.2 and I am using the UIActivityViewController for social sharing.
I click on a button and allow the UIActivityViewController to present
- (IBAction)UIActivityTypeButtonClick:(id)sender {
NSString* text=#"I am sharing this text";
NSArray* sharedArray=#[text];
UIActivityViewController * activityVC=[[UIActivityViewController alloc]initWithActivityItems:sharedArray applicationActivities:nil];
activityVC.excludedActivityTypes=#[];
[self presentViewController:activityVC animated:YES completion:nil];
}
I am getting this
I am getting Message, Twitter, Mail, WhatsApp and a More button.
On clicking More I get this.
Where is FACEBOOK. I have the facebook app in my iPhone and it is setup with my ID too in settings. But facebook never shows up here. Twitter does. Is this a bug or what? Please suggest
Thanks
I first saw this when Facebook updated their app on April 24th. Plain text sharing to Facebook isn't working as long as the Facebook app is installed. After you delete it, it's available again.
If you try to share a URL or an image together with the plain text, you will see Facebook as an option but the text field will be blank. The image or URL will attach without a problem.
I posted a sample project that reproduces this problem on github:
https://github.com/djr/UIActivityViewController-Facebook
This is not an answer, but it's pretty clear that the problem is caused by the Facebook app.
EDIT:
It's not ideal, but I created a workaround. Don't forget that you will need to attach an image or a URL for this to work.
Detect if the user has the Facebook app installed. If they do, then give them some type of informational message.
BOOL facebookIsInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]];
BOOL isUserLoggedInWithFacebook = [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook];
if(isUserLoggedInWithFacebook && facebookIsInstalled)
{
// Explain that they have to copy and paste in order to share on Facebook
}
Create a subclass of UIActivityItemProvider and override
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
NSString *stringToShare = #"string to share";
if([activityType isEqualToString:UIActivityTypePostToFacebook] ||
[activityType isEqualToString:#"com.facebook.Facebook.ShareExtension"] ||
[activityType.lowercaseString rangeOfString:#"facebook"].length)
// Because who knows when they are going to change the activityType string?
{
// Automatically copy the text for them
[[UIPasteboard generalPasteboard] setString:stringToShare];
}
return stringToShare;
}
Tell the user that they have to paste into the Facebook text field in order to share.
Blame it on Facebook.
I confirm what djr reported - if you have the FB app text is no longer shared. I deleted the FB app and now sharing both text and image works.
Facebook would like you to use their SDK. They have blocked the ability to set initial text. (Not sure how.) Check out my answer in a similar post:
UIActivityViewController for Facebook not Showing Default Text
The desired solution (from Facebook) is to use their SDK.
NSString* text=#"I am sharing this text";
NSURL *myWebsite = [NSURL URLWithString:#"http://www.website.com/"];
// UIImage * myImage =[UIImage imageNamed:#"myImage.png"];
NSArray* sharedArray=#[text,myWebsite];
UIActivityViewController * activityVC=[[UIActivityViewController alloc]initWithActivityItems:sharedArray applicationActivities:nil];
NSArray *excludedActivities = #[];
activityVC.excludedActivityTypes=excludedActivities;
[self presentViewController:activityVC animated:YES completion:nil];
To show facebook sharing button you must add a image to the array of activity items... this may be a bug on apple side but i've not seen any open radar about this issue.
Also note on iOS 8.3 text can't be added to facebook for some reason. when adding text you only be presented to a blank textfield.
UIImage *image = [UIImage imageNamed:#"__some_image__file"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[image]
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];

How can my app jump to iOS default mailbox?

I wanna set a button inside my app that, if clicked, app can jump to the default mailbox of iOS. I want to do this so users can check & send their mails.
Does this function need a private API or is this forbidden by Apple?
Thanks in advance for your kind help.
This does what you want:
let app = UIApplication.shared
if let url = NSURL(string: "message:"), app.canOpenURL(url) {
app.openURL(url)
}
The canOpenURL part checks if the user has got at least one email address setup in Mail that they can send/receive from.
Maybe you can use the url scheme like this:
NSString *email = #"mailto:?subject=YourSubject&body=MsgBody";
email = [email stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:email]];
To Send an email from within your app, one of the first 2 answers will work: MFMailComposeViewController or using the url scheme mailto://.
As for checking the users email, there is currently no public way to launch the default iOS mail application. There are however a few 3rd party libraries available to allow you to set up your own mail client, for example MailCore, remail or Chilkat. I'm sure there are others but you get the idea.
How about using MFMailComposeViewController? You can set its subject, recipients, message body, the attachment, and then you can present it modally within your app. It will be better too since the user does not need to leave your app.
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:subjectString];
[mailViewController setMessageBody:messageString isHTML:YES];
[self presentViewController:mailViewController animated:YES completion:nil];
}
Just remember to set the view controller calling the function above as the delegate of MFMailComposeViewControllerDelegate so that you can dismiss the view controller afterwards.
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissViewControllerAnimated:YES completion:nil];
}
Apple documentation on this class:
http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html

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