UIActivityViewController Share Video to WeChat fails - ios

I want to share video in my application to wechat via "UIActivityViewController"
But I got "transfer fail" message on WeChat's transfer dialog very often (alsmost 90%)
But I try to save same video to my iPhone Photos,
then share to wechat, But I never fail on it.
Is there anything I have to do before share?
My code:
NSMutableArray *shareFile = [[NSMutableArray alloc] init];
NSURL *shared = [NSURL fileURLWithPath:file.localFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:file.localFilePath]) {
[shareFile addObject: shared];
}
UIActivityViewController *_shareVC = [[UIActivityViewController alloc] initWithActivityItems:[shareFile copy] applicationActivities:nil];
[_shareVC setCompletionWithItemsHandler:nil];

In iOS9.3,10.2,10.3 equipment on the same problem, share the video to WeChat friends, suggesting that "发布不成功", 100%, but in iOS8.4 can share success, use of UIActivityViewController.

Related

Is there a way to share text on facebook messenger without SDK?

Is there a way to share text on facebook messenger without SDK?
I found the following method.
-(void)shareAction:(NSString *)str param:(NSString *)strTitle
{
NSString *title = strTitle;
NSURL *url = [[NSURL alloc]initWithString:str];
NSArray *postItems = #[title, url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:postItems
applicationActivities:nil];
activityVC.excludedActivityTypes = #[];
[self presentViewController:activityVC animated:YES completion:nil];
}
However, not just how to select Facebook Messenger among the various apps,
I want to send it directly to Facebook Messenger.
Is there a way without the SDK?
You can use UIActivityViewController to share the app using Facebook Messenger. Please check following sample URL which will display the App list which have implemented share extension.
http://pinkstone.co.uk/how-to-share-things-with-a-uiactivityviewcontroller/

How to share PDF file with Evernote in iOS

I want to share PDF file with Evernote in iOS application.
Note: I have found the code of Evernote login from Evernote official website but didn't get any reference of sharing PDF from anywhere.
I have found solution of my above question :
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"pdf-sample" ofType:#"pdf"];
NSData *pdfFileData = [NSData dataWithContentsOfFile:filePath];
ENResource * resource = [[ENResource alloc] initWithData:pdfFileData mimeType:#"application/pdf" filename:#"pdf-sample.pdf"];
ENNote * note = [[ENNote alloc] init];
note.title = #"Costsfirst PDF file";
[note addResource:resource];
[[ENSession sharedSession] uploadNote:note notebook:nil completion:^(ENNoteRef *noteRef, NSError *uploadNoteError) {
NSString * message = nil;
if (noteRef) {
message = #"Pdf uploaded!";
} else {
message = #"Failed to upload.";
}
}];
Above code is working perfectly for me.
If I do understand your question then, to share PDF with Evernote from your iOS app, can be achieved via UIActivityViewController.
try this:
NSData *pdfFileData = [NSData dataWithContentsOfFile:pdfFilePath];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"Test", pdfFileData] applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
--- OR ---
NSString *str = [[NSBundle mainBundle] pathForResource:#"YourPdfFileName" ofType:#"pdf"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"Test", [NSURL fileURLWithPath:str]] applicationActivities:nil];
With the code above, You could scroll over on UIActivityViewController’s share section, and use other custom share extensions like Evernote.
You didn’t have to do a thing. As a user, just click the more button to show the ones you want in the share sheet. As a developer, you don’t have to do anything to your UIActivityViewController to show custom Share and Action Extensions.
Hope this may help you.
Regarding Evernote cloud sdk for iOS:
https://github.com/evernote/evernote-cloud-sdk-ios/blob/master/Getting_Started.md
This document covers getting set up with the Evernote Cloud SDK for iOS, some quick examples, and some discussion of the primary classes.

Show all options in UIActivityViewController

I have some trouble with create native share dialog.
My goal is share link of my product by native view controller, but I can't do it. I'm trying test code:
NSURL *google = [NSURL URLWithString:#"http://google.com"];
NSArray *activityItems = #[google];
UIActivity *activity = [UIActivity new];
UIActivityViewController *activityViewControntroller = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:#[activity]];
activityViewControntroller.excludedActivityTypes = #[];
[self presentViewController:activityViewControntroller animated:true completion:nil];
And I get no FB and twitter icons. In the other hand, I can see it in safari both icons and when I'm touching it I see "You need configure your account before post".
So, I want the same behavior: icons for all most-popular social networks such as VK, FB, twitter; messengers like whatsapp, viber and telegram. If some of them is not installed I want dialog "You have to log in before" and redirect to safari (e.g. for FB) to log in or open appstore (e.g. for telegram or viber) to install; otherwise I want post message with my link.
I see it like this: exclude all types from activity vc, than forcibly add all icons I need and check each of them on click manually. But in apple docs I've read that "you have to use native behavior for native items instead of create custom". So, will it be correct? Or there are other ways to solve this?
Try this
-(void)clickShare:(UIButton *)sender{
NSArray * activityItems = #[[NSString stringWithFormat:#"Some initial text."], [NSURL URLWithString:#"http://www.google.com"]];
NSArray * applicationActivities = nil;
NSArray * excludeActivities = #[];
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityController.excludedActivityTypes = excludeActivities;
[self presentViewController:activityController animated:YES completion:nil];
}
this code working in my project.

iOS Share GIF (animated image) not Working

It's been almost 2 days that i'm looking to find a solution to my problem but i wasn't successful , i want to share GIF (animated image) on Facebook, Twitter, Email, WhatsApp , using "UIActivityViewController".
This is my code :
NSURL *imagePath = [NSURL URLWithString:#"http://sth.gif"];
NSData *animatedGif = [NSData dataWithContentsOfURL:imagePath];
NSArray *sharingItems = [NSArray arrayWithObjects: animatedGif,stringToShare, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
When i share in Email its animated and its working perfect , but in Twitter , Facebook , whatsApp Gifs are not animated and its like an image ...
I already read all Stack-overflow questions about the same problem Like this or this or this but its not working for me.
So far base on days research found out that :
TWITTER : For share a GIF on twitter had to use twitter API and create a multipart request to achieve the goal and its working very well.
FACEBOOK : I did share some GIF on Facebook using FACEBOOKSHAREKIT , but i don't know why sometimes Gifs are animated, sometimes not.
INSTAGRAM : To share gif on Instagram had to convert GIFS to MP4 (or any other video formats accepted by Instagram) then save it into camera roll then share it , It is little twisted but its working very well.
WHATSAPP : It not supporting GIF at all. READ THE UPDATE
To do all of this i couldn't use "UIActivityViewController" , so decided to create a custom share page. if anybody know something to add here , to help me and others please tell me (especially about Facebook).
Thanks in advance
UPDATE
WHATSAPP : Thanks to #AmmarShahid, as he mentioned in comments, Whatsapp now supports gif.
Encountered the similar problem and Googled a lot but still not a perfect solution, the best I came up is here:
Use UIActivityItemProvider and extend - (id)item {} for different UIActivityType:
Twitter: The default UIActivityViewController Twitter share doesn't support it yet which it will "scale down" it as a still JPG. However somehow it works for GIF less than 100kb (tested in iOS 9) and I don't know why. Therefore, I have to use SLRequest to upload the GIF as taught in here. When the SLRequest is done and return, dismiss the UIActivityViewController. The downside of that is no preview share sheet and users cannot type their own message anymore.
Facebook: It's actually much easier! Just upload the GIF to Giphy, then provide the Giphy URL to UIActivityViewController instead of the file contents, Facebook will recognize it and show the animated GIF
- (id)item
{
if ([self.activityType isEqualToString:UIActivityTypePostToFacebook]) {
// Upload to Giphy
...
return [NSURL URLWithString:giphyURL];
}
if ([self.activityType isEqualToString:UIActivityTypePostToTwitter]) {
// Use SLRequest to share instead
...
// Dismiss the UIActivityViewController (I am using Unity)
[UnityGetGLViewController() dismissViewControllerAnimated:NO completion: NULL];
return nil;
}
}
full code is in my GitHub, I am actually a iOS newb so some experts please correct me and the code if possible
// Share GIF File: WhatsApp
NSURL *imageUrl =[self.ImageArray objectAtIndex:currentPhotoIndex];
NSString *path=imageUrl.absoluteString;
NSArray *strings = [path componentsSeparatedByString:#"/"];
NSString *mygif=[strings objectAtIndex:strings.count-1];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *dataPath = [documentsPath stringByAppendingPathComponent:#"/MrHRamani"];
NSString *filePath = [dataPath stringByAppendingPathComponent:mygif];
NSURL *urll=[NSURL fileURLWithPath:filePath];
NSLog(#"imag %#",imageUrl);
self.documentationInteractionController.delegate = self;
self.documentationInteractionController.UTI = #"net.whatsapp.image";
self.documentationInteractionController = [self setupControllerWithURL:urll usingDelegate:self];
[self.documentationInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

UIActivityController behaviour different on device and simulator

I add an activityViewController to my app like below, passing in an image
UIActivityViewController *avc = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:img,nil] applicationActivities:[NSArray arrayWithObjects:nil]];
[self presentModalViewController:avc animated:YES];
[avc release];
On the simulator (twitter, facebook and weibo accounts all not configured):
options mail, twitter, facebook, weibo, assign to contact, save to camera roll, print, and copy appear by default.
but on device:
in my app: twitter, facebook and weibo only show if the accounts are configured.
in safari: twitter, facebook and weibo options are available irregardless of whether the accounts are configured.
I am expecting the same behaviour in my app as safari. am I missing a particular step?
Okay I have figured the problem.
The options shown in the UIActivityViewController totally depends on the type of items that are to be shared. For example, if there is a video, it will not show Facebook or twitter option. But if it's an image and title, it definitely will show the relevant options.
The following will show up apps like mail, twitter, Facebook, assignToContact, save to camera roll, print, copy, etc
// Create the content
NSString *message = #"The Upcoming App Scribble Talk";
UIImage *imageToShare = [UIImage imageNamed:#"createbtn.png"];
NSArray *objectsToShare = [NSArray arrayWithObjects:message, image, nil];
However, the following shall bring up only camera roll, mail or copy.
NSString *message = #"The Upcoming App Scribble Talk";
NSString *videoToShare = #"myFirsScribble.mov";
NSURL *videoPath = [NSURL fileURLWithPath:videoToShare];
NSArray *objectsToShare = [NSArray arrayWithObjects:message, videoPath, nil];
I think you want to show some certain service only in your UIActivityViewController. You may one property called excludedActivityTypes to be defined as below to avoid some default activity.
UIActivityViewController *yourvc = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:img,nil] applicationActivities:[NSArray arrayWithObjects:nil]];
yourvc.excludedActivityTypes = #[UIActivityTypePostToWeibo,UIActivityTypePrint,UIActivityTypeMail,UIActivityTypeCopyToPasteboard];//Try this code in simulator.. you can only see FB & Twitter.
[self presentModalViewController:yourvc animated:YES];
[avc release];
likewise you can excluded from default UIActivityViewController..

Resources