I'm trying to pop the built in Safari share WeChat in my iOS app. But can't find a way to make WeChat app show up in the UIActivityViewController!
I noticed that the WeChat app icon shows up when sharing images from the Photo Gallery, and Safari link sharing. The native Notes app doesn't have WeChat option.
Not sure how that's working, any help is appreciated! Thanks!
This is done using "Share" extensions. See Apple docs for more information: https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/ShareSheet.html#//apple_ref/doc/uid/TP40014214-CH12-SW1
Regarding why some apps appear in certain sharing contexts but not in others, this is because a Share extension has to declare to iOS which kind of data it supports for sharing. Presumably, WeChat developers did not enable their Share extension for "pure" text content, like in the Notes app. See here for how to set which kind of data a Share extension accepts: https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW8
Unfortunately you won't be able to add the WeChat Share extension on behalf of them if they didn't allow it, but you might be able to use some WeChat API to develop your own app extension with text content enabled.
Hope it helped.
WeChat's icon won't appear in UIActivityViewController if you try to share anything other than URL. WeChat only accepts URL posts. This code snippet should work for you:
NSArray *items = #[[NSURL URLWithString:#"http://google.com"]];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
Related
Our team is building an iOS app from which a user can share media content through social apps present on his iPhone. While testing how other apps behave, I observed that not all apps show all the available sharing options.
Specifically, I don't see the following apps in the sharing options:
Kik, WeChat, Reddit, Youtube, GroupMe, Band.
I have all these apps on my device. So expected all these apps to be shown for sharing. Should the base app explicitly handle all the sharing options?
No. Only following ActivityTypes are supported by iOS. Of course you can exclude some of these activities if you want to.
UIActivityTypePostToFacebook
UIActivityTypePostToTwitter
UIActivityTypePostToWeibo
UIActivityTypeMessage
UIActivityTypeMail
UIActivityTypePrint
UIActivityTypeCopyToPasteboard
UIActivityTypeAssignToContact
UIActivityTypeSaveToCameraRoll
UIActivityTypeAddToReadingList
UIActivityTypePostToFlickr
UIActivityTypePostToVimeo
UIActivityTypePostToTencentWeibo
UIActivityTypeAirDrop
For the app to appear in the share sheet:
The app needs to implement a sharing extension (not all do)
The sharing extension must support the type of data that is being shared (text, url, image, video...).
The user must have selected that sharing extension (by tapping on the "More" button at the end of the list)
In my app I'm using the following code that allows to share an image with a text:
- (IBAction)sharePressed:(id)sender {
UIImage *postingImage = [UIImage imageWithContentsOfFile:self.filepath];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"Lorem ipsum", postingImage] applicationActivities:nil;
[self presentViewController:activityViewController animated:YES completion:nil];
}
And when posting I can see image, but can't see text. Also text doesn't appear in FB.
I'm afraid to tell you, you cannot post text to Facebook programatically. It's a new Facebook prohibition that forbids "pre-filled" Facebook sharing. That is why newer versions of iOS do not show your text, even tough it's correctly provided (and works on Twitter and in other sharing options).
For more info please refer to https://developers.facebook.com/docs/apps/review/prefill)
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.
In my app I'm using the following code that allows to share an image with a text:
- (IBAction)sharePressed:(id)sender {
UIImage *postingImage = [UIImage imageWithContentsOfFile:self.filepath];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"Lorem ipsum", postingImage] applicationActivities:nil;
[self presentViewController:activityViewController animated:YES completion:nil];
}
Posting the image to Facebook works fine and it appears on my FB wall, however in my console I get the following message:
plugin com.apple.share.Facebook.post invalidated
I've tested it on a couple of devices, as far as I could see it only happens on my iPhone 6 with iOS 8.1 installed.
Anyone knows what that message means and how to prevent it from showing?
Here is the correct answer ios plugin com.apple.share.Facebook.post do not show provided text. It's a bummer.
I'm afraid to tell you, you cannot post text to Facebook programatically. It's a new Facebook prohibition that forbids "pre-filled" Facebook sharing. That is why newer versions of iOS do not show your text, even tough it's correctly provided (and works on Twitter and in other sharing options).
For more info please refer to https://developers.facebook.com/docs/apps/review/prefill
This is a terrible error message by Apple. Go to settings and check your facebook/twitter accounts. You will notice they have no password set (perhaps this happens after updating to 8.1). Just update the account info and the message will be gone and your post/tweet will work.
In my case, this is related to the fact that the Facebook app replaces the iOS system level Facebook share extension with a custom one. Case is triggered as follows:
Load an app and share to Facebook (Note: Facebook app is currently
installed)
Exit app
Delete the Facebook app from device
Open app again (still active in memory) and share to Facebook ...
fail! The app is looking for a share extension that was
uninstalled along with the Facebook app
Kill and restart the app, share to Facebook. Voila! The app has loaded the default iOS Facebook share extension and it works again.
Head scratcher as to why Apple let Facebook take this approach as opposed to either forcing them to replace the default Facebook share extension or just not allowing them to inject their own, only if their app is installed.
It also happen when u try to set an URL using addURL: method for SLServiceTypeTwitter in your SLComposeViewController. Deleting it fix the issue.
Facebook has updated their policy. It doesn't work with this anymore. you need to integrate Facebook sdk to do so. here is the relevant references for those who want to share image or post from your app to Facebook
https://developers.facebook.com/docs/sharing/opengraph/ios#sharedialog
I faced the same issue. I was using activity controller and SLComposeViewController, and in both cases got the same error, even if i don't set any text/url etc for fb programatically. So according to me, in my case, it was not the issue of new facebook policy as mentioned in comment above.
To avoid any inconvenience in future, i fixed it by using facebook share SDK (not using SLComposeViewController or activityViewController now). FBSdk is integrated in my iOS project and the code, i used for sharing purpose is as:
#IBAction func shareOnFaceBook(sender: AnyObject) {
var content = FBSDKShareLinkContent()
content.contentURL = urlToShare() //method returning the url
content.contentDescription = textToShare() //method returning text(string) to share
var dialog = FBSDKShareDialog()
dialog.mode = FBSDKShareDialogMode.Automatic
dialog.shareContent = content
dialog.delegate = self
dialog.fromViewController = self
dialog.show()
}
It'll open fb application (if installed), Otherwise will open Safari (fb web application).Hope that it'll help you
Best,
For Share sheet for my iOS app. As I referred in this link How to display the default iOS 6 share action sheet with available share options?.
And I end up with below working code :
NSString *string = #"Some text to share";
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[string]
applicationActivities:nil];
[self presentViewController:activityViewController
animated:YES
completion:^{
NSLog(#"complerted.");
}];
But I can see only Email & Message button !!?
How can I get other social media buttons in Share sheet like Facebook , twitter as seen below. Even though user account not available/created in device? (As we can see iOS default Photos app, where the share sheet has social buttons even though for example facebook not installed in the device!) Should I enable or extend extension?
Please help,
Thanks & Regards,
//Update
- I added iOS-8 social framework and imported #import <Social/Social.h>.
This UIactivityController show the app which can share your string or image. If you have not added any Facebook or twitter account than that will not show that app in this action sheet.
Try by adding Facebook and twitter account in your devices setting. you will able to see that app too.
You have a More button in your share sheet. Tap on it & it will shows all the available Extension & turn on it for Facebook & Twitter.
I am trying to use the UIActivityViewController Flickr sharing in iOS 7 but the Flickr icon does not appear in the sharing sheet. I feel like I am missing something basic.
I am testing on an iPhone 5S.
I am logged into a Flickr account on the device.
The same share sheet displays and shares properly with Facebook, Twitter, Email , MMS, and AirDrop.
The photos app on the device displays the Flickr icon in the photos app sharing sheet and can share successfully to the phone Flickr account.
I am sure that I am not listing Flickr in the excluded activities for the UIActivityViewController.
I have tried with both standard UIActivityViewController and the RDActivityViewController subclasses.
Is there something additional required for Flickr sharing? or could someone confirm that they have seen this work in their own app.
Thanks
Flickr share with UIActivityViewController will only work if you are sharing a image.
So in your array with activity items there should be at least one image.
Make sure that the image is of type UIImage:
NSArray *shareItems = #[someImage, #"Text of the messages"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil];
Exmple of how it looks: https://www.dropbox.com/s/jpjmnuqbktqgb8s/FlickTest.png