How can i launch the twitter settings on the Device from my app with objective-c?
I am working on an app that shares a link on twitter, i am using the SLComposeViewController and it works, but when the Twitter app is not installed and no Twitter account is configured on settings it does nothing.
I want to show an alert inviting the user to log in on twitter to be able to share the link, when the user taps on a button the app should launch the Twitter settings on the device.
I have been reading that using the url scheme like this is not allowed since iOS 5.1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];
I read it is only allowed to launch your app settings with this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
But i have found in some apps that it actually opens the Twitter settings like this one:
screenshot of meme generator app that opens twitter settings
Do you know how to do this?
Here is the code i use for the SLComposeViewController:
- (IBAction)twitterAction:(id)sender {
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center=self.view.center;
[activityView startAnimating];
[self.view addSubview:activityView];
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *composerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composerSheet setInitialText:@"text to post"];
[composerSheet addURL:[NSURL URLWithString:@"http://urltoshare.com"]];
[composerSheet addImage:[UIImage imageNamed:@"postimage.JPG"]];
[composerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[activityView stopAnimating];
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(@"Post Canceled");
// some code ...
break;
case SLComposeViewControllerResultDone:
[self changeSharedStatus];
NSLog(@"Post Sucessful");
// some code ...
break;
default:
break;
}
}];
[self presentViewController:composerSheet animated:YES completion:nil];
}else {
/* code to show the alert that invites the user to open settings */
}
}