With the release of iOS 6 I'd like to revisit the original question here: Access to Apple's built in Icons?
For example, when you hit the 'action' button to share a photo, now instead of an action sheet with buttons titled 'Message', 'Mail', etc., now there is a collection view of the icons for mail, messaging, facebook, twitter, etc.
For a 'share' action in my app I'd like to be able to present the same - because it looks better and would provide a consistent user experience. Is the use of these icons still not allowed, even if they are referring to (and would take the user to) the apps they originally belong to?
For just showing the share UI with icons, you probably want UIActivityViewController.
NSString* someText = self.textView.text;
NSArray* dataToShare = #[someText]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:^{}];
It looks like:
Documentation here.
The problem with using UIActivity for sending mail is that you cannot set the subject field's text, recipients, etc. like you can with MFMailComposeViewController
I've been trying to do a workaround to set the subject field, but have not found a solution yet.
UIActivity class provides built-in activity types for mail, messaging, ...
Related
I am wondering how Dolly (iOS app) does this. If I select the Twitter icon in the first screenshot, the view in the second screen appears immediately.
That second screenshot is what is presented after you typically click the Twitter service from the scrollable list presented in a UIActivityViewController (below), e.g. Facebook, Mail, Messages, Twitter, etc. But, I never had to click Twitter from the below menu.
Again, the share sheet was presented immediately. I did not have to select Twitter from the built in set of options. So, I am wondering what, if anything I can do to duplicate this behavior. Possibly a few lines that I am missing below?
func handleTwitterShareButtonTapped(){
let activityVC = UIActivityViewController.init(activityItems: [ShareActivityItemStringSource(), ShareActivityItemURLSource()], applicationActivities: [])
//preselect twitter from services somehow???
navigationController?.present(activityVC, animated: true, completion: nil)
}
Or, perhaps there is some swizzling magic that I need to do. If this does involve swizzle magic, any resources that might get me going would be extremely helpful.
Thanks!!!
I'm trying to use the SLComposeViewController to share a link in my iOS App.
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"Here's the link I promised:"];
[controller addURL:[NSURL URLWithString:#"http://www.url.com"]];
[self presentViewController:controller animated:YES completion:nil];
When the controller presents, there is no text in the entry box. You can add text and send it fine (the URL shows up correctly in the Post as well).
I just installed FacebookSDK 4.01 and it's a iOS 7/8 App.
Any ideas on why the initial text isn't showing up. I even tried to do it without the URL and just do text, but nothing.
Additional Note: If I do remove the addURL, then the App freezes when I touch "Post" and the post never gets sent.
Thanks for any help!!!
I found a nice way to work around this which still gives the user control.
For Facebook only, just before presenting the SLComposerViewController I show a self dismissing alert (with a 6 second dismissal if OK wasn't tapped). This alert will contain "Write to your friends about how you did playing !\n\nYou can just PASTE for a preset message.".
Right after showing the alert, I then use the following to post a preset message to the UIPasteboard:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = msg;
So then the SLComposeViewController is presented and an alert view right over it. Once the user dismisses the alert view (or 6 seconds passes and it self dismisses), that the user has the option to just PASTE, right in the message text, your preset message. Or not, that's the beauty of it.
Hope this helps some others get around what FB decided to suddenly enforce. I didn't even realize it was against policy to use the setInitialText method for FB.
Cheers.
This behaviour is intended. See also this bug report: https://developers.facebook.com/bugs/962985360399542/. As #WizKid mentions, it's against policy to pre-fill text. Up until recently, you could still do so (violating the policy) but now this is actually enforced.
There is nothing you can do for this on your side; it's a policy enforcement by Facebook.
Also, related Rdar: http://openradar.appspot.com/20709403
Apparently iOS8 by default adds a "iCloud Photo Sharing" activity to activity views in iOS8 and I haven't found any useful documentation regarding it, especially how to explicitly remove it (going into the "More" option allows the user to toggle showing/hiding it, but for our app we want to completely disallow this option).
Has anyone figured anything out about how to disable this? Any input would be appreciated. Thanks!
If you init your UIActivityViewController with full of images, iCloud sharing set to activity types by default. You can add a string in your activityItems array. This move will cause that iCloud sharing to be removed from activityTypes.
NSArray *Items = [NSArray arrayWithObjects: image1, image2, #"", nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:Items applicationActivities:nil];
Normally you'd set the excludedActivityTypes property on your UIActivityViewController instance -- e.g., to exclude posting to Facebook, you'd put UIActivityTypePostToFacebook in that array.
But it doesn't look like the Built-in Activity Types list (either in the documentation or in UIActiviy.h) includes a constant for iCloud Photos. That's probably worth filing a bug about.
I have an app that has a share button. This share button loads a UIActivityViewController for sharing to Facebook, Twitter, email, text message, etc.
It used to work fine, and I think it still works fine on the simulator, but on devices, the view controller appears with all the right options, and if you click on one, either nothing happens, or if it's Mail, the mail modal view loads and then dismisses itself. Then I get my log "Activity was not performed.", which is when the completion block returns false for completed but the activityType was not null. So it is recognizing the selection, but it isn't loading the activity into the view for some reason
I have checked the stuff I'm trying to share, even replaced it with dummy stuff (as shown below), still no luck. I am using a normal device, I have my Twitter, Mail, and Facebook accounts set up, texting works too. The only thing that works is copy (i.e. when you copy the share contents to the clipboard). In other apps on the same device, the UIActivityViewController and the loading of selected activities works just fine. Same issue observed on other devices running the app as well.
Really don't understand what the issue is here. Very perplexing! Any help or suggestions of things to try would be much appreciated. I don't see any way to debug this issue.
Here's the code: (note I tried removing the image as well, no luck)
- (void)shareTapped {
NSString *shareText = #"Testing";//[self shareText];
NSURL *url = [NSURL URLWithString:#"http://www.google.ca"]; //[self shareURL];
NSArray *activityItems = [NSArray arrayWithObjects:shareText,url, self.shareImage, nil];
UIActivityViewController *shareDrawer = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
shareDrawer.excludedActivityTypes = #[UIActivityTypePostToWeibo,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypePrint];
shareDrawer.completionHandler = ^(NSString *activityType, BOOL completed) {
if (completed) {
NSLog(#"Selected activity was performed.");
} else {
if (activityType == NULL) {
NSLog(#"User dismissed the view controller without making a selection.");
} else {
NSLog(#"Activity was not performed.");
}
}
NSString *result = completed ? #"success" : #"fail";
if (activityType == NULL) {
result = #"dismissed";
}
};
[self presentViewController:shareDrawer animated:YES completion:nil];
}
OK, by process of elimination I finally narrowed down the culprit:
I have a custom UISegmentedControl with a custom font for the text and I manually adjusted the content offset to make it appear properly. Although I have removed these lines and the segmented control actually looks fine.
Here's the code (I've confirmed that it's all three lines that cause the problem)
[[UISegmentedControl appearance] setContentPositionAdjustment:UIOffsetMake(4, 0) forSegmentType:UISegmentedControlSegmentLeft barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setContentPositionAdjustment:UIOffsetMake(0, 0) forSegmentType:UISegmentedControlSegmentCenter barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setContentPositionAdjustment:UIOffsetMake(-4, 0) forSegmentType:UISegmentedControlSegmentRight barMetrics:UIBarMetricsDefault];
Now, seeing as the views that popup after you select a share option DO NOT HAVE SEGMENTED CONTROLS in them, I have no clue why this would cause this problem. But it definitely works now that I removed it.
Thanks for those of you who attempted to help. Of course, there's no way you could have possibly guessed this was the issue. Chances are pretty low that anyone would ever encounter this problem in the first place, since adjusting the content position is probably fairly rare.
To debug this issue I followed the following steps:
I tested if the issue had something to do with the properties on the UIActivityViewController that I was setting, or the activity items I was sharing. It did not.
I tested if UIActivityViewController worked properly when called from a different view controller inside my app. It did not.
I made a blank view controller with a button that causes a generic UIActivityViewController to show on press of a bar button. I made that my root view. That worked, thus showing that it was an isolated issue.
Instead of making that view controller the root of my app, I pushed it from my normal main view. It no longer worked, thus determining that the problem probably had something to do with my main view.
I commented out all the code in viewDidLoad, viewDidAppear, and viewWillAppear, except for adding a button to the nav bar which would load my sharing test. That worked. Then I uncommented viweDidAppear and viewWillAppear, still worked. So I uncommented chunks of viewDidLoad until I figured out exactly what the problem was.
What I learned: For weird problems like this (i.e. ones that seem like an iOS bug or something, but you can't find anyone posting about it), you should spend more time debugging before trying to post to stack overflow.
(I should really know this by now, but every new problem to debug feels like an exception to this rule)
Please comment below if you know why adjusting the content position of UISegmentedControl would mess up the sharing from UIActivityViewController even though those views don't contain segmented controls
Thanks
Had same issue too, here's what I done to overcome it.
I'd recommend adding the Social.framework to your Link Binary and using
SLComposeViewController *socialShare = [SLComposeViewController composeViewControllerForServiceType:shareType];
Where the shareType can be SLServiceTypeFacebook or SLServiceTypeTwitter.
I created a UIAlertview pop-up to show the share options for the user
UIAlertView *social = [[UIAlertView alloc]initWithTitle:#"Share" message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Twitter", #"Facebook", #"Email", nil];
and depending on which one they picked (using the UIAlertview Delegate methods) then the content can be shared accordingly, and it's a great alternative to UIActivityViewController.
Hope this suggestion helps, cheers, Jim.
I use a UIActivityViewController with valid activities in the activityItems (NSArray).
UIActivityViewController* activityController=[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
I have a problem with the appearance of the UIActivityViewController both in the simulator and on the iPhone itself. If I click 'Mail' then a mail form pops up that displays its title 'New message' directly over the statusbar (can't show you a picture 'cause I lack 'reputation'?) ending up with text written over info in the status bar.
The same happens with the message-activity. I think that the things I do are pretty basic and don't even offer the opportunity to mess things up. So what can be the reason that this happens? Or better: how can I prevent this from happening?
(Screenshot of the problem.)
Simple solution what worked for me is to embed view in Navigation Controller.
If you are using Storyboard you can try this.