When using UIActivityViewController to share #[dataFileURL, #"text"] via messages app, the text is not included - message

I have a simple UIActivityViewController to share a data file and some text.
The text is required because, since iOS 13, it's no longer intuitive how to open a file sent in messages.
My issue is, when I choose Messages as the option to send, it attaches the file, but not the text.
Prior to iOS13, it used to send the file in one message, and the text in a follow up.
If I share to Mail, or save to Files, both the text and the data are included.
If I share an NSURL that's simply a web address, and text, then both are shared in the same message.
It's only when I try to share an NSURL that points to a data source, and text, that only the data file is sent.
Here's my code:
//Get NSURL for file
NSURL *dataUrl = [AppData data:zippedData toPlnUrl:fileName]; //zipped data
NSString *subject = #“PolyNome files”;
NSString * textToShare = #"Check out these PolyNome Presets. Learn how to import here ->”];
NSURL *website = [NSURL URLWithString:#"https://polynome.net/importing"];
NSArray *objectsToShare = #[textToShare,website,dataUrl];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
[activityVC setValue:subject forKey:#"subject"];
activityVC.modalPresentationStyle = UIModalPresentationPopover;
activityVC.popoverPresentationController.barButtonItem = self.shareButton;
[self presentViewController:activityVC animated:YES completion:nil];
So, for example, if NSArray *objectsToShare = #[textToShare,website]; then that works and both text and url are included in one message.
As soon as I add dataUrl as an element at any position in the array, then that's the only thing that gets shared in messages - all other things are omitted.
This is driving me crazy since the only reason I need to include the import instructions is because iOS 13 made it very complicated to import the file from messages (you have to tap the avatar at the top of messages, tap "info", find "attachments", tap an attachment, then tap the share button, then choose "More...", then choose the app.)
Any advice much appreciated!

Related

UIActivityViewController not showing Built-in activities

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?

Network Sharing Apps within the App

I am enable to get the answer from last couple of Weeks that
Actually I have 1 tableview contains some text, and I have Sharing bar button if iClicked that Sharing Barbutton At Index i need to Share that text to Email,FB,WhatsuP,and other that are Installed and supported to send text.
finally my requirement is when I clicked the bar button, i need to open the view that contains the list of Installed Apps in our device(Email,FB,WhatsUp,etc)That are supported to send text.
and When I clicked The Item in the List, text should send to That App.
I have no idea and I am searching for it from few couple of weeks
Please Help me
Thanks
Use UIActivityViewController
NSString *shareText = #"some text to share";
NSURL *url = [NSURL URLWithString:#"http://www.someurl.com"];
NSArray *itmes = #[shareText, items];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];
If you wish you can also exlude some of the items in the activityVC like
activityVC.excludeActivityTypes = #[UIActivityTypePostToFlickr, UIActivityTypePostToTensentWeibo];
// and as many more you like

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.

Naming file when sending PDF via AirDrop

If sending a PDF generated from an app through AirDrop in iOS 7, any ideas how to set the title of the document?
The usual search on SO and documents have not answered my question
NSString *fileName = [NSString stringWithFormat:#"userCert_%#",self.certificate.reference];
NSData *cert = self.pdfData;
UIActivityViewController *activityCtr = [[UIActivityViewController alloc] initWithActivityItems:#[cert]
applicationActivities:nil];
NSMutableArray *excludedActivities = [self iOS6Activities].mutableCopy;
[excludedActivities addObject:UIActivityTypeAddToReadingList];
[excludedActivities addObject:UIActivityTypePostToFlickr];
[excludedActivities addObject:UIActivityTypePostToTencentWeibo];
[excludedActivities addObject:UIActivityTypePostToVimeo];
[activityCtr setExcludedActivityTypes:excludedActivities];
[self presentViewController:activityCtr
animated:YES
completion:nil];
If you want to share NSData, you have to wrap it in an object that conforms to the UIActivityItemSource protocol, and implement the optional protocol method activityViewController:dataTypeIdentifierForActivityType:. This however will not solve the problem of specifying the file name as it seems in this case the system will generate one based upon the UTI and some hash.
If you write the data out to a file and share a NSURL fileURL instead of the NSData, the filename you gave the file will be used and is what is shown in the alert on the receiving device. Even in this case, it might be worth wrapping the URL in a UIActivityItemSource conforming object as it will enable you to provide things such as a preview image using the optional protocol method activityViewController:thumbnailImageForActivityType:suggestedSize:.

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