UIActivityViewController not showing Message option When Sharing Image Object - ios

I am using UIActivityViewController to share my generated image, it worked fine for certain apps like Whatsapp or sharing via Email, but i also wanted to share it using Messages app. I've tried several ways to do it but i can't display Messages app on it.
Here's my code :
UIImage *receiptStage3 = [CreateReceiptImage putLogo:nil putLabel:TRANSACTION_RECEIPT inImage:receiptStage2];
NSData *imageData = UIImageJPEGRepresentation(receiptStage3,0.5);
// create url
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyyMMddHHmmss"];
NSString *fileName = [NSString stringWithFormat:#"%#%#%#", #"FormatHere-", [dateFormatter stringFromDate:[NSDate date]],#".jpg"];
NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:fileName]];
NSData *data = imageData;
// write data
[data writeToURL:url atomically:NO];
NSArray *activityItems = #[url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePostToTencentWeibo, UIActivityTypePostToVimeo, UIActivityTypePostToWeibo, UIActivityTypePostToFlickr, UIActivityTypePostToTwitter, UIActivityTypePostToFacebook, UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeOpenInIBooks, UIActivityTypeAirDrop,UIActivityTypeSaveToCameraRoll,UIActivityTypeAddToReadingList];
[activityVC setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
//Delete file
NSError *errorBlock;
if([[NSFileManager defaultManager] removeItemAtURL:url error:&errorBlock] == NO) {
NSLog(#"error deleting file %#",#"error");
return;
}
}];
[self presentViewController:activityVC animated:YES completion:nil];
As i said before i've tried several ways like putting NSUrl #[url] and UIImage *receiptStage3 directly to initWithActivityItems. I've also tried to remove excludedActivityTypes but the Message option wont show. Am i missing something ? or are there another ways to do this ? Thanks before

Your code is completely fine, works to me.
First of all you Messages app may be missing if you have iMessage disabled in your settings. Go to Settings->Messages and make sure it's on:
Also you may not see it in the default items, check out hidden ones:

Related

How to share Deeplinking url via Email

I tried to share Url, for instance,deeplink:// via default iphone Email.But unfortunately,the link doesn't turn as hyperlink mode so that it can be clickable and directed to the specified location.So please kindly help me for the below code.
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"deeplink://"]];
NSArray * activityItems = #[url];
NSArray * applicationActivities = nil;
NSArray * excludeActivities = #[UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeMessage];
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityController.excludedActivityTypes = excludeActivities;
[self presentViewController:activityController animated:YES completion:nil];
Custom URI schemes are not a valid solution for this. As you discovered, they are not recognized as links in many situations, but there are other more serious issues too. Read this answer for more information

How to share text and image(both) on whatsapp using UIActivityController : Objective C?

UIImage * imageShare = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:trackImagePath]]];
NSURL *urlLink = [NSURL URLWithString:linkstr];
SharingActivityProvider * share = [[SharingActivityProvider alloc]initWithPlaceholderItem:#"Ghaneely Share!"];
share.sharelink = urlLink;
share.sharelinkText = shareString;
NSArray *objectsToShare = #[imageShare,share];
activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypePostToWeibo,UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,UIActivityTypeAssignToContact,UIActivityTypeAirDrop];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:TRUE completion:nil];
I want to share text and image (both) on WhatsApp just like Android by using UIActivityController. It used to work before when I used share without SharingActivityProvider. But I need to post different text on facebook, twitter,etc ,hence I am using ActivityProvider(which I think should not be the problem). Now with the code above it is sharing only image.
What could be the issue?
From this way you can share text and video to whatsapp :-
NSString *URLString=#"http://video.app.com/video.php?";
NSURL *VideoURL=[NSURL URLWithString:#“URLString ”];
NSMutableArray *activityItems= [NSMutableArray arrayWithObjects:VideoURL,#"Hey, check out this video I've shared with you, it's awesome!", result1, nil];
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
self.activityViewController.excludedActivityTypes = #[UIActivityTypePostToWeibo,UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,UIActivityTypeAirDrop];
[self presentViewController:self.activityViewController animated:YES completion:nil];
try this may be it will help you.

Sharing video with airdrop

I am having some trouble in sharing videos with airdrop. So, i am using the AssetLibrary like this :
else if (conformsToVideo) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Asset Loaded" message:#"Video One Loaded"
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
self.mediaAsset = [AVAsset assetWithURL:[info objectForKey:UIImagePickerControllerMediaURL]];
UIActivityViewController * controller = [[UIActivityViewController alloc] initWithActivityItems:#[self.mediaAsset] applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
}
Maybe this is just not the way to do it, I don't know and I didn't find any tutorial about it so if you have one, I will gladly take it.
Now my problem is that when i select a video everything works fine until the UIActivityViewController pops out , i don't have any error but I can't use airdrop (nor any other service BTW) the only thing I can do is press the Cancel button of the UIAVController.
I am using iOS 8.3.
Thanks for your help
Ok, eventually I found an answer, maybe not the best but I put it there in case it helps someone cause I didn't find much on sharing video with airdrop :
NSURL * path = [info objectForKey:UIImagePickerControllerReferenceURL];
BOOL conformsToVideo = (UTTypeConformsTo((__bridge_retained CFStringRef) mediaType, kUTTypeAudiovisualContent));
if (conformsToVideo) {
[self.library assetForURL:path
resultBlock:^(ALAsset *asset) {
ALAssetRepresentation* assetRepresentation = [asset defaultRepresentation];
NSString* outputDirectory = [NSString stringWithFormat:#"%#", NSTemporaryDirectory()];
NSString* pathToCopy = [outputDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"%#", assetRepresentation.filename]];
NSUInteger size = (NSUInteger)assetRepresentation.size;
NSMutableData* data = [NSMutableData dataWithLength:size];
NSUInteger bytesRead = [assetRepresentation getBytes:data.mutableBytes fromOffset:0 length:size error:nil];
NSURL * url = nil;
if ([data writeToFile:pathToCopy atomically:YES])
{
NSLog(#"Ok");
url = [NSURL fileURLWithPath:pathToCopy];
UIActivityViewController * controller = [[UIActivityViewController alloc] initWithActivityItems:#[url] applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
}
} failureBlock:^(NSError *error) {
NSLog(#"Failure to use the ALAsset");
}
];
}
I found the solution using this question : Share a video from asset library with AirDrop fails
I am merely adding the previous steps to the code given there, hope it can be useful.

Not able to share URL on Facebook and Twitter using UIActivityViewController in iOS 7.1

I am using UIActivityViewController for share button.It's showing text and url when I am selecting mail option from list but it's showing only text not url when I am selecting Facebook or Twitter.I searched a lot but not getting solution for my issue.I got one more solution to add "http" in url but is this possible without adding http in url. My code is -
NSArray *activityItems;
NSString *str;
NSString *noteStr;
str = [NSString stringWithFormat:#"com.boxscoregames.squares://square?%#",squareID];
noteStr = #"You have been invited to join the Square game, please follow the link below on your iPhone.";
NSURL *url = [NSURL URLWithString:str];
// str =[NSString stringWithFormat:#"<html>%#</html>" ,str,str];
activityItems = #[noteStr,url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
I believe the link is indeed not being shown. But, when you post it, the link will be added to your Facebook/twitter post.
You could of course just also add the link to the text.
NSString *link = [NSString stringWithFormat:#"com.boxscoregames.squares://square?%#",squareID];
NSString *noteStr = [NSString stringWithFormat:#"You have been invited to join the Square game, please follow the link below on your iPhone. %#", link];
NSURL *url = [NSURL URLWithString:link];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:#[noteStr, url] applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];

UIActivityViewController Automatically 'Clicking' Link iOS 7

I have a basic UIActivityViewController sharing some text and a URL. The sharing options are Email, SMS, Twitter, and Facebook. Everything works fine in iOS 6 but in iOS 7 when I choose Twitter or Facebook, without touching anything my device automatically closes my app, opens Safari and goes to the URL I am trying to share. What could be causing this?
Code (CustomActivityItemProvider is a subclass to customize text based on sharer):
if ([UIActivityViewController class]) { // if class exists = ios6+
// Create array for sharing
CustomActivityItemProvider *textToShare = [[CustomActivityItemProvider alloc]
initWithStandardText:#"Text to share.\n"];
NSURL *urlToShare = iTunesShort ? iTunesShort : [NSURL URLWithString:iTunesLink];
NSArray *activityItems = #[textToShare, urlToShare];
// Show sharing view
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
So I still don't know why only shortened URLs were causing this problem, but a solution that took care of it was to include the urlToShare in the textToShare.
// Create array for sharing
NSString *urlToShare = iTunesShort ? iTunesShort : iTunesLink;
NSString *textWithUrl = [NSString stringWithFormat:#"Text to share.\n%#", urlToShare];
CustomActivityItemProvider *textToShare = [[CustomActivityItemProvider alloc]
initWithStandardText:textWithUrl];
NSArray *activityItems = #[textToShare];

Resources