For some reason when I use ActivityViewController from my app I don't get the option to share using Airdrop. If i use it from Chrome, I do get the option:
This is the code that I'm using:
NSMutableArray * items = [NSMutableArray new];
[items addObject:#"text for share"];
[items addObject:[UIImage imageNamed:#"image"]];
NSArray *activityItems = [NSArray arrayWithArray:items];
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:^{
.....
}];
But I only get this:
How do I add the Airdrop option?
In order to be able to send something over AirDrop the item will need to be a URL. I couldn't find the official documentation, but in this Apple AirDrop Example it states:
URLs can be used as a simple way to transfer information between devices. Apps can easily parse a received URL to determine what action to take. After an app registers a URL scheme (including custom schemes), the system will know to launch that app when a URL of that type is received.
Related
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.
I'm sharing an image and its description text using UIActivityType. I need to share the URL of the image if I choose SMS sharing option. How can I do that? Currently I'm sharing the image and data to Facebook and Twitter. How to send the URL in case that SMS option is selected?
You can share the image using SMS option in the same way that you are doing it with Facebook and Twitter.
The activityType for SMS is UIActivityTypeMessage. It is the built-in activityType.
So the only thing you need to do is provide image and image description as activityItems while creating your UIActivityController.
The code snippet is given below:
NSString *imageDescription = #"Image Description Goes Here";
UIImage *image = [UIImage imageNamed:#"Image_Name"];
NSArray *items = [NSArray arrayWithObjects: imageDescription,image,nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
I have used UIActivityViewController for sharing my message in Facebook, Twitter, Viber etc....It seems the message is send twice in Viber but for others are ok. Can u please help me?? I have used the code given below...
-(void)shareContent {
NSString * message;
NSArray * itemsArray = [NSArray new] ;
if ([shareFlag isEqualToString:#"Friend"]) {
message = #"Hi, I am using Amar Sticker, an amazing app to download & share cool Bangla Stickers. Click here and get it for FREE: http://goo.gl/qK7HRw";
NSURL *appLink = [NSURL URLWithString:#"http://goo.gl/qK7HRw"];
itemsArray = #[message, appLink];
shareFlag = #"";
}
UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:nil];
[avc setExcludedActivityTypes:#[UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard,UIActivityTypeSaveToCameraRoll]];
[avc setCompletionHandler:^(NSString *activityType, BOOL completed) {
}];
[self presentViewController:avc animated:YES completion:nil];
}
After many searching and doing in several way I see that it only happens when I share an array, it can not handle the shared object of the array properly, maybe its a bug of viber. When I post only one string or url it can send properly. I have tested using 2,3,4 items arrry and only one single string/url etc.
I'm trying to share an image and text.
But when i'm trying to share using whatsapp i dont see the image and it doesnt get sent (i do see it when i'm trying to share to facebook or mail...).
Whats going on?
- (void)shareImage:(UIImage *)image
{
NSString *sharedMsg=[NSString stringWithFormat:#"Hello world"];
UIImage* sharedImg=image;
NSArray* sharedObjects=[NSArray arrayWithObjects:sharedMsg, sharedImg, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
initWithActivityItems:sharedObjects applicationActivities:nil];
activityViewController.popoverPresentationController.sourceView = self.view;
[self presentViewController:activityViewController animated:YES completion:nil];
}
#ozd,
if image Share then
see link : Share image/text through WhatsApp in an iOS app
& if Share Text
JBWhatsAppActivity Library: https://github.com/jberlana/JBWhatsAppActivity
using Below Code You can share Text , Link..etc, may be helpful to you.
WhatsAppMessage *whatsappMsg = [[WhatsAppMessage alloc] initWithMessage:#"Hey , I would like you to experience this fabulous app which helps you to create , store and share your MOMENTS. You can add your voice message to every photo and moments too !!!\n\nDownload the app from https://play.google.com/store?hl=en" forABID:#""];
NSArray *applicationActivities = #[[[JBWhatsAppActivity alloc] init]];
NSArray *excludedActivities = #[UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypeMessage];
NSArray *activityItems = #[#"Hey , I would like you to experience this fabulous app which helps you to create , store and share your MOMENTS. You can add your voice message to every photo and moments too !!!\n\nDownload the app from https://play.google.com/store?hl=en", whatsappMsg];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityViewController.excludedActivityTypes = excludedActivities;
[self presentViewController:activityViewController animated:YES completion:^{}];
Below given code, I'm sharing 1 text and 2 photos using UIActivityViewController. Then I choose Facebook for my sharing destination and it's shared on 2 separated posts on the feed for each photo but what I want is to share it in one single post with 1 text and 2 photos. How can I achieve this? I have done lot of search on here and found no proper answer. It seems to me that Facebook may have no clear way to do this, so it's like such an issue may lie on their side.
activityItems = #[self.textDetail.text, self.imageFileView1.image, self.imageFileView2.image];
UIActivityViewController *activityController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
The issue was solved by either new iOS ver or Facebook's new way of handling activity items. Anyway it works as I expect now.
Try this:
NSString *message = #"msg To post";
NSMutableArray *postsImages=[[NSMutableArray alloc] init];
[postsImages addObject:message];
for (UIImage *img in collectionImageArray) {
[postsImages addObject:img];
}
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:postsImages
applicationActivities:nil];
[activityVC setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
if([activityType isEqualToString:UIActivityTypePostToTwitter]){
//twitter selected
}
}];
[self presentViewController:activityVC animated:YES completion:nil];