SLComposeViewController setInitialText not showing up in View - ios

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

Related

Why does iMessages change the URL I pass to it via the UIActivityViewController?

my code is very simple, but there's a bug somewhere and I can't seem to figure this out.
Step 1:
// create an array that contains this url
NSArray *items = #[[NSURL URLWithString:#"https://danzafuerte33.as.me/YogaPrivate"]];
UIActivityViewController *shareController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[self.window.rootViewController presentViewController:shareController animated:true completion:nil];
Step 2:
The activity view controller modal will show up, and one of the choices will be iMessages.
Step 3:
Tap on iMessages -- notice that the correct url is shared -- so far so good
Step 4:
Tap cancel on the iMessages modal window, the UIActivityViewController should still be visible
Step 5:
Tap on iMessages again, the url is changed to https://app.acuityscheduling.com/schedule.php?owner=12808744 which is not the right url!
Why on earth is this happening the second time iMessages opens this link, is this an iMessages bug?
When the url is passed to iMessages, it retrieves the web site in order to render a preview.
At the top of the page returned is:
<link rel="canonical" href="https://app.acuityscheduling.com/schedule.php?owner=12808744">
This says that the canonical link for this page is https://app.acuityscheduling.com/schedule.php?owner=12808744, and so the activity item is updated with this, preferred, url for the page.

UIActivityViewController, activities not being completed, sharing options not loading

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.

UIActivityViewController with ugly header

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.

Using Apple icons with iOS 6

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, ...

DismissModalViewControllerAnimated?

I've been looking for hours to solve my problem. Right now my program is set as a page control with a UIScrollView. So I looked at a tutorial on adding an in-app email (http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/).
Everything works out well until I want to cancel an email, or send the mail, the log says it did the method fine, however when i do the
[self DismissModalViewControllerAnimated:YES];
it will dismiss to the mainwindow.xib, however, I want it to dismiss back to the secondcontrollerview where the email function and button resides obviously.
What am i missing? Hope someone could help ^-^,
simply .. if you are present your mailController from seconedControllerView your app will return back to it when you dismiss the mailController.

Resources